Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multi step WFopt #4169

Merged
merged 7 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions docs/methods.rst
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,31 @@ The cost function consists of three components: energy, unreweighted variance, a
<cost name="unreweightedvariance"> 0.00 </cost>
<cost name="reweightedvariance"> 0.05 </cost>

Varational parameter selection
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The predominant way of selecting varational paramemters is via ``<wavefunction>`` input.
``<coefficients>`` entries support ``optimize="yes"/"no"`` to enable/disable variational parameters in the wavefunction optimization.
The secondary way of selecting varational paramemters is via ``variational_subset`` parameter in the ``<qmc>`` driver input.
It allows controlling optimization granularity at each optimization step.
If ``variational_subset`` is not provided or empty, all the varational paramemters are selected.
If variational paramemters are set as not optimizable in the predominant way, the secondary way won't be able to set them optimizable even they are selected.

The following example shows optimizing subsets of parameters in stages in a single QMCPACK run.

::
<qmc method="linear">
...
<parameter name="variational_subset"> uu ud </parameter>
</qmc>
<qmc method="linear">
...
<parameter name="variational_subset"> uu ud eH </parameter>
</qmc>
<qmc method="linear">
...
<parameter name="variational_subset"> uu ud eH CI </parameter>
</qmc>

Optimizers
~~~~~~~~~~

Expand Down
Empty file modified docs/running_docker.rst
100755 → 100644
Empty file.
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() << "In total " << OptVariablesForPsi.size() << " parameters being optimzied." << std::endl;
app_log() << " Variational subset selects " << OptVariablesForPsi.size() << " 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() << " In total " << 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
3 changes: 3 additions & 0 deletions src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,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 @@ -1081,9 +1081,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 @@ -315,6 +315,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 @@ -328,17 +341,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"?>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ qmca -q ev *.scalar.dat
 
                            LocalEnergy               Variance           ratio 
H4-OneShiftOnly  series 0  -1.904150 +/- 0.004328   0.690708 +/- 0.008875   0.3627 
H4-OneShiftOnly  series 1  -1.993150 +/- 0.003207   0.468618 +/- 0.006004   0.2351 
H4-OneShiftOnly  series 2  -2.016938 +/- 0.001926   0.427168 +/- 0.003485   0.2118 
H4-OneShiftOnly  series 3  -2.019568 +/- 0.002191   0.430474 +/- 0.004287   0.2132 
H4-OneShiftOnly  series 4  -2.014822 +/- 0.002322   0.434599 +/- 0.009917   0.2157 
H4-OneShiftOnly  series 5  -2.060509 +/- 0.001297   0.202193 +/- 0.003284   0.0981 
H4-OneShiftOnly  series 6  -2.066163 +/- 0.001567   0.205154 +/- 0.002769   0.0993 
H4-OneShiftOnly  series 7  -2.066169 +/- 0.001489   0.207286 +/- 0.003208   0.1003 
H4-OneShiftOnly  series 8  -2.065890 +/- 0.001396   0.205738 +/- 0.002847   0.0996 
H4-OneShiftOnly  series 9  -2.105417 +/- 0.001126   0.173066 +/- 0.001457   0.0822 
H4-OneShiftOnly  series 10  -2.135769 +/- 0.000914   0.152791 +/- 0.000722   0.0715 
H4-OneShiftOnly  series 11  -2.138689 +/- 0.000870   0.152215 +/- 0.000648   0.0712 
H4-OneShiftOnly  series 12  -2.141079 +/- 0.000794   0.155026 +/- 0.002604   0.0724 
H4-OneShiftOnly  series 13  -2.155559 +/- 0.001001   0.127789 +/- 0.001123   0.0593 
H4-OneShiftOnly  series 14  -2.157919 +/- 0.001123   0.130314 +/- 0.000537   0.0604 
H4-OneShiftOnly  series 15  -2.159332 +/- 0.000800   0.130835 +/- 0.001147   0.0606 

<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>
<parameter name="variational_subset"> uu ud </parameter>
</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>
<parameter name="variational_subset"> uu ud eH </parameter>
</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>
<parameter name="variational_subset"> uu ud eH CI </parameter>
</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>
<parameter name="variational_subset"> uu ud eH uuH udH </parameter>
</qmc>
</loop>

</simulation>