Skip to content

Commit

Permalink
Merge pull request #34 from vanderhe/initRobustness
Browse files Browse the repository at this point in the history
Check for ACSF parameters and dataset information
  • Loading branch information
vanderhe authored Aug 26, 2021
2 parents 4cdffe5 + 03bfc88 commit 3b610d1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 16 deletions.
34 changes: 26 additions & 8 deletions prog/fortnet/lib_fortnet/initprogram.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
25 changes: 17 additions & 8 deletions prog/fortnet/lib_io/fnetdata.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 3b610d1

Please sign in to comment.