diff --git a/prog/fortnet/lib_fortnet/initprogram.F90 b/prog/fortnet/lib_fortnet/initprogram.F90 index 0b845b3..ff12a11 100644 --- a/prog/fortnet/lib_fortnet/initprogram.F90 +++ b/prog/fortnet/lib_fortnet/initprogram.F90 @@ -28,7 +28,8 @@ module fnet_initprogram use dftbp_globalenv, only : stdOut use dftbp_hsdparser, only : parseHSD, dumpHSD - use fnet_fnetdata, only : inquireExtFeatures, readHdfDataset, TDataset, checkDatasetCompatibility + use fnet_fnetdata, only : inquireExtFeatures, inquireTargets, inquireStructures, readHdfDataset,& + & TDataset, checkDatasetCompatibility use fnet_netstat, only : createNetstat, readSubnetArchitecture use fnet_acsf, only : TGFunction_init, TGFunctions use fnet_features, only : TFeatures, TFeaturesBlock @@ -515,18 +516,17 @@ subroutine readDataBlock(data, node, mode) !> true, if files exist logical :: tExist + !> true, if dataset holds corresponding information + logical :: tStructures, tTargets, tExtFeatures + call getChildValue(node, 'NetstatFile', strBuffer, default='fortnet.hdf5') + ! netstat file must be present in validation or prediction mode if ((mode == 'validate') .or. (mode == 'predict')) then inquire(file=trim(unquote(char(strBuffer))), exist=tExist) - if (tExist) then - data%netstatpath = trim(unquote(char(strBuffer))) - else - call detailedError(node, 'Specified netstat file is not present.') - end if - else - data%netstatpath = trim(unquote(char(strBuffer))) + if (.not. tExist) call detailedError(node, 'Specified netstat file is not present.') end if + data%netstatpath = trim(unquote(char(strBuffer))) call getChildValue(node, 'Dataset', strBuffer) inquire(file=trim(unquote(char(strBuffer))), exist=tExist) @@ -536,6 +536,21 @@ subroutine readDataBlock(data, node, mode) call detailedError(node, 'Specified dataset file is not present.') end if + ! dataset must contain targets in training or validation mode + if ((mode == 'train') .or. (mode == 'validate')) then + call inquireTargets(data%trainpath, tTargets) + if (.not. tTargets) then + call error('Selected running mode requires the dataset to hold target information.') + end if + end if + + ! dataset must always hold some feature information + call inquireStructures(data%trainpath, tStructures) + call inquireExtFeatures(data%trainpath, tExtFeatures) + if ((.not. tStructures) .and. (.not. tExtFeatures)) then + call error('Neither mappings nor features provided by the dataset.') + end if + ! validation dataset only relevant for training runs if (mode == 'train') then @@ -958,6 +973,9 @@ subroutine readFeaturesBlock(this, node, nTotExtFeatures) call getChildValue(tmp, 'xi', xi) call getChildValue(tmp, 'eta', eta) call getChildValue(tmp, 'lambda', lambda) + if ((lambda > 1.0_dp) .or. ((lambda < -1.0_dp))) then + call detailedError(tmp, 'Specified lambda parameter leaves interval [-1, 1].') + end if call TGFunction_init(this%mapping%functions%func(iChild - iAutoBlock), type, rCut,& & xi=xi, eta=eta, lambda=lambda) case default diff --git a/prog/fortnet/lib_io/fnetdata.F90 b/prog/fortnet/lib_io/fnetdata.F90 index d16cc72..4ebd56f 100644 --- a/prog/fortnet/lib_io/fnetdata.F90 +++ b/prog/fortnet/lib_io/fnetdata.F90 @@ -371,18 +371,24 @@ subroutine inquireTargets(fname, tTargets, tAtomic, nTargets) call h5fopen_f(fname, H5F_ACC_RDONLY_F, file_id, iErr) call h5ltget_attribute_int_f(file_id, 'fnetdata/dataset/training', 'ntargets', tmp, iErr) - nTargets = tmp(1) - if (nTargets > 0) then + + if (tmp(1) > 0) then tTargets = .true. else tTargets = .false. end if + if (present(nTargets)) then + nTargets = tmp(1) + end if + call h5ltget_attribute_int_f(file_id, 'fnetdata/dataset/training', 'atomic', tmp, iErr) - if (tmp(1) == 1) then - tAtomic = .true. - else - tAtomic = .false. + if (present(tAtomic)) then + if (tmp(1) == 1) then + tAtomic = .true. + else + tAtomic = .false. + end if end if ! close the dataset file @@ -423,13 +429,16 @@ subroutine inquireExtFeatures(fname, tFeatures, nFeatures) ! read nextfeatures attribute call h5ltget_attribute_int_f(file_id, 'fnetdata/dataset', 'nextfeatures', tmp, iErr) - nFeatures = tmp(1) - if (nFeatures > 0) then + if (tmp(1) > 0) then tFeatures = .true. else tFeatures = .false. end if + if (present(nFeatures)) then + nFeatures = tmp(1) + end if + ! close the dataset file call h5fclose_f(file_id, iErr)