Skip to content

Commit

Permalink
Support multi-step WFOpt
Browse files Browse the repository at this point in the history
  • Loading branch information
ye-luo committed Aug 13, 2022
1 parent 9aa2a0e commit 1bdac4c
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 19 deletions.
4 changes: 3 additions & 1 deletion src/QMCDrivers/WFOpt/QMCCostFunctionBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ bool QMCCostFunctionBase::put(xmlNodePtr q)
if (obj.isOptimized())
obj.checkInVariablesExclusive(OptVariablesForPsi);
OptVariablesForPsi.resetIndex();
app_log() << "Totally " << OptVariablesForPsi.size() << " parameters being optimzied." << std::endl;
app_log() << " Selected " << OptVariablesForPsi.size() << " variational parameters." << std::endl;

//synchronize OptVariables and OptVariablesForPsi
OptVariables = OptVariablesForPsi;
Expand Down Expand Up @@ -482,6 +482,8 @@ bool QMCCostFunctionBase::put(xmlNodePtr q)
{
APP_ABORT("QMCCostFunctionBase::put No valid optimizable variables are found.");
}
else
app_log() << " Totally " << NumOptimizables << " parameters being optimized after applying constraints." << std::endl;
// app_log() << "<active-optimizables> " << std::endl;
// OptVariables.print(app_log());
// app_log() << "</active-optimizables>" << std::endl;
Expand Down
5 changes: 4 additions & 1 deletion src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ MultiSlaterDetTableMethod::MultiSlaterDetTableMethod(ParticleSet& targetPtcl,
CI_Optimizable(false),
use_pre_computing_(use_pre_computing)
{
Dets = std::move(dets);
Dets = std::move(dets);
C_otherDs.resize(Dets.size());
int NP = targetPtcl.getTotalNum();
myG.resize(NP);
Expand Down Expand Up @@ -735,7 +735,10 @@ void MultiSlaterDetTableMethod::extractOptimizableObjectRefs(UniqueOptObjRefs& o
void MultiSlaterDetTableMethod::checkInVariablesExclusive(opt_variables_type& active)
{
if (CI_Optimizable && myVars->size())
{
myVars->setIndexDefault();
active.insertFrom(*myVars);
}
}

void MultiSlaterDetTableMethod::checkInVariables(opt_variables_type& active)
Expand Down
1 change: 1 addition & 0 deletions src/QMCWaveFunctions/Jastrow/BsplineFunctor.h
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ struct BsplineFunctor : public OptimizableFunctorBase
{
if (notOpt)
return;
myVars.setIndexDefault();
active.insertFrom(myVars);
}

Expand Down
16 changes: 14 additions & 2 deletions src/QMCWaveFunctions/Jastrow/PolynomialFunctor3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -990,9 +990,21 @@ struct PolynomialFunctor3D : public OptimizableFunctorBase
reset_gamma();
}

void checkInVariables(opt_variables_type& active) override { active.insertFrom(myVars); }
void checkInVariables(opt_variables_type& active) override
{
if (notOpt)
return;

myVars.setIndexDefault();
active.insertFrom(myVars);
}

void checkOutVariables(const opt_variables_type& active) override { myVars.getIndex(active); }
void checkOutVariables(const opt_variables_type& active) override
{
if (notOpt)
return;
myVars.getIndex(active);
}

void print(std::ostream& os)
{
Expand Down
4 changes: 2 additions & 2 deletions src/QMCWaveFunctions/VariableSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ void VariableSet::getIndex(const VariableSet& selected)
}
}

void VariableSet::setDefaults(bool optimize_all)
void VariableSet::setIndexDefault()
{
for (int i = 0; i < Index.size(); ++i)
Index[i] = optimize_all ? i : -1;
Index[i] = i;
}

void VariableSet::print(std::ostream& os, int leftPadSpaces, bool printHeader) const
Expand Down
15 changes: 7 additions & 8 deletions src/QMCWaveFunctions/VariableSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ struct VariableSet
using value_type = qmcplusplus::QMCTraits::ValueType;
using real_type = qmcplusplus::QMCTraits::RealType;

using pair_type = std::pair<std::string, value_type>;
using index_pair_type = std::pair<std::string, int>;
using iterator = std::vector<pair_type>::iterator;
using const_iterator = std::vector<pair_type>::const_iterator;
using size_type = std::vector<pair_type>::size_type;
using pair_type = std::pair<std::string, value_type>;
using index_pair_type = std::pair<std::string, int>;
using iterator = std::vector<pair_type>::iterator;
using const_iterator = std::vector<pair_type>::const_iterator;
using size_type = std::vector<pair_type>::size_type;

///number of active variables
int num_active_vars;
Expand Down Expand Up @@ -327,10 +327,9 @@ struct VariableSet
*/
void getIndex(const VariableSet& selected);

/** set default Indices
* @param optimize_all if true, all the variables are active
/** set default Indices, namely all the variables are active
*/
void setDefaults(bool optimize_all);
void setIndexDefault();

void print(std::ostream& os, int leftPadSpaces = 0, bool printHeader = false) const;

Expand Down
22 changes: 17 additions & 5 deletions tests/molecules/H4_ae/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ if(NOT QMC_CUDA)
H4_OPT_SCALARS # OPT step 5
)

list(APPEND H4_OPT_SCALARS_ONLY_JAS "totenergy" "-2.066504 0.0009") # total energy
qmc_run_and_check(
short-H4-opt-OneShiftOnly-onlyjas
"${qmcpack_SOURCE_DIR}/tests/molecules/H4_ae"
H4-OneShiftOnly
optm-OneShiftOnly-onlyjas.xml
1
16
${SUCCESS_STATUS_MP}
5
H4_OPT_SCALARS_ONLY_JAS # OPT step 5
)

list(APPEND H4_OPT_SCALARS_ONLY_MSD "totenergy" "-2.138635 0.0009") # total energy
qmc_run_and_check(
short-H4-opt-OneShiftOnly-onlymsd
Expand All @@ -302,17 +315,16 @@ if(NOT QMC_CUDA)
H4_OPT_SCALARS_ONLY_MSD # OPT step 5
)

list(APPEND H4_OPT_SCALARS_ONLY_JAS "totenergy" "-2.066504 0.0009") # total energy
qmc_run_and_check(
short-H4-opt-OneShiftOnly-onlyjas
short-H4-optbatch-OneShiftOnly-multistep
"${qmcpack_SOURCE_DIR}/tests/molecules/H4_ae"
H4-OneShiftOnly
optm-OneShiftOnly-onlyjas.xml
optm-OneShiftOnly-multistep.xml
1
16
${SUCCESS_STATUS_MP}
5
H4_OPT_SCALARS_ONLY_JAS # OPT step 5
11
H4_OPT_SCALARS_ONLY_MSD # OPT step 011
)
else()
message(VERBOSE
Expand Down
71 changes: 71 additions & 0 deletions tests/molecules/H4_ae/H4.wfs_j123.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0"?>
<qmcsystem>
<wavefunction name="psi0" target="e">
<determinantset type="MolecularOrbital" name="LCAOBSet" transform="yes" source="ion0">
<basisset name="LCAOBSet">
<atomicBasisSet name="Gaussian-G2" angular="cartesian" type="Gaussian" elementType="H" normalized="no">
<grid type="log" ri="1.e-6" rf="1.e2" npts="1001"/>
<!-- Possible substitution H00 by a Slater-type orbital
<basisGroup rid="H00" n="0" l="0" type="Slater">
<radfunc exponent="1.31826" contraction="1.0"/>
</basisGroup>
-->
<basisGroup rid="H00" n="0" l="0" type="Gaussian">
<radfunc exponent="3.425250900000e+00" contraction="1.543289672950e-01"/>
<radfunc exponent="6.239137000000e-01" contraction="5.353281422820e-01"/>
<radfunc exponent="1.688554000000e-01" contraction="4.446345421850e-01"/>
</basisGroup>
</atomicBasisSet>
</basisset>
<sposet basisset="LCAOBSet" name="spo-up" size="3">
<occupation mode="ground"/>
<coefficient size="4" id="updetC">
5.04668000000000e-01 4.50114000000000e-01 3.58423000000000e-01 1.26449000000000e-01
-2.40452000000000e-01 -3.20413000000000e-01 4.66777000000000e-01 7.03549000000000e-01
8.80080000000000e-02 -5.04842000000000e-01 8.07522000000000e-01 -7.19301000000000e-01
1.03323500000000e+00 -8.77213000000000e-01 -3.90492000000000e-01 2.12318000000000e-01
</coefficient>
</sposet>
<sposet basisset="LCAOBSet" name="spo-dn" size="3">
<occupation mode="ground"/>
<coefficient size="4" id="downdetC">
5.04668000000000e-01 4.50114000000000e-01 3.58423000000000e-01 1.26449000000000e-01
-2.40452000000000e-01 -3.20413000000000e-01 4.66777000000000e-01 7.03549000000000e-01
8.80080000000000e-02 -5.04842000000000e-01 8.07522000000000e-01 -7.19301000000000e-01
1.03323500000000e+00 -8.77213000000000e-01 -3.90492000000000e-01 2.12318000000000e-01
</coefficient>
</sposet>
<multideterminant optimize="yes" spo_up="spo-up" spo_dn="spo-dn">
<detlist size="2" type="CSF" nca="0" ncb="0" nea="2" neb="2" nstates="3" cutoff="0.2">
<csf id="CSFcoeff_0" exctLvl="0" coeff="0.605818" qchem_coeff="0.955818" occ="220">
<det id="csf_0-0" coeff="1" alpha="110" beta="110"/>
</csf>
<csf id="CSFcoeff_1" exctLvl="2" coeff="-5.2056644665606530e-01" qchem_coeff="-0.276685" occ="202">
<det id="csf_1-0" coeff="1" alpha="101" beta="101"/>
</csf>
</detlist>
</multideterminant>
</determinantset>
<jastrow name="J2" type="Two-Body" function="Bspline" print="yes">
<correlation rcut="10" size="10" speciesA="u" speciesB="u">
<coefficients id="uu" type="Array"> 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 </coefficients>
</correlation>
<correlation rcut="10" size="10" speciesA="u" speciesB="d">
<coefficients id="ud" type="Array"> 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 </coefficients>
</correlation>
</jastrow>
<jastrow name="J1" type="One-Body" function="Bspline" source="ion0" print="yes">
<correlation rcut="5" size="10" cusp="1" elementType="H">
<coefficients id="eH" type="Array"> 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 </coefficients>
</correlation>
</jastrow>
<jastrow function="polynomial" name="J3" print="yes" source="ion0" type="eeI">
<correlation esize="3" especies="u" isize="3" ispecies="H" rcut="10">
<coefficients id="uuH" type="Array"> </coefficients>
</correlation>
<correlation esize="3" especies1="u" especies2="d" isize="3" ispecies="H" rcut="10">
<coefficients id="udH" type="Array"> </coefficients>
</correlation>
</jastrow>
</wavefunction>
</qmcsystem>
92 changes: 92 additions & 0 deletions tests/molecules/H4_ae/optm-OneShiftOnly-multistep.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0"?>
<simulation>
<project id="H4-OneShiftOnly" series="0">
<parameter name="driver_version">batch</parameter>
</project>
<!--random seed="605"/-->
<!-- input from gaussian converter -->
<include href="H4.ptcl.xml"/>
<include href="H4.wfs_j123.xml"/>
<hamiltonian name="h0" type="generic" target="e">
<pairpot name="ElecElec" type="coulomb" source="e" target="e"/>
<pairpot name="IonElec" type="coulomb" source="ion0"/>
<constant name="IonIon" type="coulomb" source="ion0" target="ion0"/>
</hamiltonian>

<loop max="4">
<qmc method="linear" move="pbyp" checkpoint="-1" gpu="no">
<parameter name="walkers_per_rank"> 16 </parameter>
<parameter name="blocks"> 128 </parameter>
<parameter name="warmupsteps"> 5 </parameter>
<parameter name="steps"> 128 </parameter>
<parameter name="substeps"> 5 </parameter>
<parameter name="timestep"> 0.5 </parameter>
<parameter name="useDrift"> yes </parameter>
<parameter name="samples"> 262144 </parameter>
<cost name="energy"> 1.00 </cost>
<cost name="unreweightedvariance"> 0.00 </cost>
<cost name="reweightedvariance"> 0.00 </cost>
<estimator name="LocalEnergy" hdf5="no"/>
<parameter name="MinMethod">OneShiftOnly</parameter>
<variational_subset> uu ud </variational_subset>
</qmc>
</loop>

<loop max="4">
<qmc method="linear" move="pbyp" checkpoint="-1" gpu="no">
<parameter name="walkers_per_rank"> 16 </parameter>
<parameter name="blocks"> 128 </parameter>
<parameter name="warmupsteps"> 5 </parameter>
<parameter name="steps"> 128 </parameter>
<parameter name="substeps"> 5 </parameter>
<parameter name="timestep"> 0.5 </parameter>
<parameter name="useDrift"> yes </parameter>
<parameter name="samples"> 262144 </parameter>
<cost name="energy"> 1.00 </cost>
<cost name="unreweightedvariance"> 0.00 </cost>
<cost name="reweightedvariance"> 0.00 </cost>
<estimator name="LocalEnergy" hdf5="no"/>
<parameter name="MinMethod">OneShiftOnly</parameter>
<variational_subset> uu ud eH </variational_subset>
</qmc>
</loop>

<loop max="4">
<qmc method="linear" move="pbyp" checkpoint="-1" gpu="no">
<parameter name="walkers_per_rank"> 16 </parameter>
<parameter name="blocks"> 128 </parameter>
<parameter name="warmupsteps"> 5 </parameter>
<parameter name="steps"> 128 </parameter>
<parameter name="substeps"> 5 </parameter>
<parameter name="timestep"> 0.5 </parameter>
<parameter name="useDrift"> yes </parameter>
<parameter name="samples"> 262144 </parameter>
<cost name="energy"> 1.00 </cost>
<cost name="unreweightedvariance"> 0.00 </cost>
<cost name="reweightedvariance"> 0.00 </cost>
<estimator name="LocalEnergy" hdf5="no"/>
<parameter name="MinMethod">OneShiftOnly</parameter>
<variational_subset> uu ud eH CI </variational_subset>
</qmc>
</loop>

<loop max="4">
<qmc method="linear" move="pbyp" checkpoint="-1" gpu="no">
<parameter name="walkers_per_rank"> 16 </parameter>
<parameter name="blocks"> 128 </parameter>
<parameter name="warmupsteps"> 5 </parameter>
<parameter name="steps"> 128 </parameter>
<parameter name="substeps"> 5 </parameter>
<parameter name="timestep"> 0.5 </parameter>
<parameter name="useDrift"> yes </parameter>
<parameter name="samples"> 262144 </parameter>
<cost name="energy"> 1.00 </cost>
<cost name="unreweightedvariance"> 0.00 </cost>
<cost name="reweightedvariance"> 0.00 </cost>
<estimator name="LocalEnergy" hdf5="no"/>
<parameter name="MinMethod">OneShiftOnly</parameter>
<variational_subset> uu ud eH uuH udH </variational_subset>
</qmc>
</loop>

</simulation>

0 comments on commit 1bdac4c

Please sign in to comment.