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

L2 DMC #1948

Merged
merged 37 commits into from
Nov 5, 2020
Merged

L2 DMC #1948

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2d7d37e
add DMC driver that really does VMC (no branching)
jtkrogel Mar 29, 2019
e010078
turn off accept/reject
jtkrogel Mar 29, 2019
6860aeb
make accept/reject optional
jtkrogel Mar 29, 2019
b435fc8
temporary add of vmc param to dmc xml
jtkrogel Apr 1, 2019
dea2452
turn off T-moves
jtkrogel Apr 1, 2019
7eccefa
keep drift rescaling for vmc propagator
jtkrogel Apr 1, 2019
66e70cc
copy vmc from dmc driver to start L2 projector implementation
jtkrogel Apr 1, 2019
9498e81
add scaffolding to support L2 projector
jtkrogel Apr 3, 2019
ead9f53
Merge branch 'eval_hess_soa' of https://github.com/jtkrogel/qmcpack i…
jtkrogel Apr 4, 2019
bf22703
initial L2 D K implementation
jtkrogel Apr 9, 2019
ecfaec7
fix sign error in L2 drift, add fake move to get correct distances in…
jtkrogel Apr 9, 2019
3958da3
cleanup commented code
jtkrogel Apr 9, 2019
907f4e0
add driver files for L2 DMC
jtkrogel Apr 11, 2019
6743df1
remove commented code
jtkrogel Apr 11, 2019
316b670
add unmodified driver
jtkrogel Apr 11, 2019
7e5bbd5
incorporate L2 adjustments into DMC projector
jtkrogel Apr 11, 2019
5eacfbc
Changing to nrule 7
Oct 7, 2020
82cf0bb
Changing to nrule 4
mcbennet Oct 27, 2020
cedd492
Hand Merge
mcbennet Oct 27, 2020
4a9c94e
More merging
mcbennet Oct 27, 2020
e77871f
Final merge before PR to Jaron
mcbennet Oct 29, 2020
e8ecfc9
Merge pull request #2 from mcbennet/mstd_l2_dmc_merge-devel
jtkrogel Oct 29, 2020
adb13f4
fix SoA L2 diffusion
jtkrogel Oct 30, 2020
e201777
add deterministic tests for vmc/dmc L2
jtkrogel Oct 30, 2020
1cb8f32
update L2 input flag
jtkrogel Oct 30, 2020
2d548fc
update test input file
jtkrogel Oct 30, 2020
24c2dde
remove scaffolding files
jtkrogel Oct 30, 2020
72ba56c
remove commented AoS remnants
jtkrogel Oct 30, 2020
5e739ab
update nexus flags
jtkrogel Oct 30, 2020
96332a0
fix stray typo in header
jtkrogel Oct 30, 2020
d390106
clean up commented code
jtkrogel Oct 30, 2020
c5e3a4b
cleanup header
jtkrogel Oct 30, 2020
f075a63
Merge branch 'develop' into mstd_l2_dmc
ye-luo Oct 30, 2020
2b4873d
handle another mixed precision upcast
jtkrogel Nov 4, 2020
dadebac
Merge branch 'mstd_l2_dmc' of https://github.com/jtkrogel/qmcpack int…
jtkrogel Nov 4, 2020
89075f1
Merge remote-tracking branch 'github/develop' into mstd_l2_dmc
ye-luo Nov 4, 2020
6ecd2fc
Fix GCC reorder warning.
ye-luo Nov 4, 2020
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
5 changes: 3 additions & 2 deletions nexus/lib/qmcpack_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -2507,8 +2507,8 @@ class dmc(QIxml):
tag = 'qmc'
attributes = ['method','move','gpu','multiple','warp','checkpoint','trace','target','completed','id','continue']
elements = ['estimator']
parameters = ['walkers','warmupsteps','blocks','steps','timestep','nonlocalmove','nonlocalmoves','pop_control','reconfiguration','targetwalkers','minimumtargetwalkers','sigmabound','energybound','feedback','recordwalkers','fastgrad','popcontrol','branchinterval','usedrift','storeconfigs','en_ref','tau','alpha','gamma','stepsbetweensamples','max_branch','killnode','swap_walkers','swap_trigger','branching_cutoff_scheme']
write_types = obj(gpu=yesno,nonlocalmoves=yesnostr,reconfiguration=yesno,fastgrad=yesno,completed=yesno,killnode=yesno,swap_walkers=yesno)
parameters = ['walkers','warmupsteps','blocks','steps','timestep','nonlocalmove','nonlocalmoves','pop_control','reconfiguration','targetwalkers','minimumtargetwalkers','sigmabound','energybound','feedback','recordwalkers','fastgrad','popcontrol','branchinterval','usedrift','storeconfigs','en_ref','tau','alpha','gamma','stepsbetweensamples','max_branch','killnode','swap_walkers','swap_trigger','branching_cutoff_scheme','l2_diffusion']
write_types = obj(gpu=yesno,nonlocalmoves=yesnostr,reconfiguration=yesno,fastgrad=yesno,completed=yesno,killnode=yesno,swap_walkers=yesno,l2_diffusion=yesno)
#end class dmc

class rmc(QIxml):
Expand Down Expand Up @@ -2699,6 +2699,7 @@ class gen(QIxml):
l_local = 'l-local',
pbcimages = 'PBCimages',
dla = 'DLA',
l2_diffusion = 'L2_diffusion',
)
# afqmc names
Names.set_afqmc_expanded_names(
Expand Down
25 changes: 25 additions & 0 deletions src/Containers/OhmmsPETE/TensorOps.h
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,31 @@ inline Tensor<T, 3> inverse(const Tensor<T, 3>& a)
// return detinv*x;
}

//////////////////////////////////////////////////////////
//
// cholesky factorization: not general, only 3D supported
//
//////////////////////////////////////////////////////////

//////////////////////////////////////////////////////
// specialized for D=3
//////////////////////////////////////////////////////
template<class T>
inline Tensor<T, 3> cholesky(const Tensor<T, 3>& a)
{
Tensor<T, 3> L;
T L00Inv;
//L = T(0); // already done by default constructor
L(0,0) = sqrt(a(0,0));
L00Inv = 1.0/L(0,0);
L(1,0) = a(1,0)*L00Inv;
L(2,0) = a(2,0)*L00Inv;
L(1,1) = sqrt(a(1,1)-L(1,0)*L(1,0));
L(2,1) = (a(2,1)-L(2,0)*L(1,0))/L(1,1);
L(2,2) = sqrt(a(2,2)-(L(2,0)*L(2,0)+L(2,1)*L(2,1)));
return L;
}

//////////////////////////////////////////////////////////////////////
//
// Specializations for Tensor dot Tensor
Expand Down
1 change: 1 addition & 0 deletions src/QMCDrivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ SET(QMCDRIVERS
DMC/DMC.cpp
DMC/DMCUpdateAll.cpp
DMC/DMCUpdatePbyPFast.cpp
DMC/DMCUpdatePbyPL2.cpp
DMC/DMCFactory.cpp
DMC/DMCFactoryNew.cpp
DMC/DMCBatched.cpp
Expand Down
15 changes: 14 additions & 1 deletion src/QMCDrivers/DMC/DMC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "DMC.h"
#include "QMCDrivers/DMC/DMCUpdatePbyP.h"
#include "QMCDrivers/DMC/DMCUpdatePbyPL2.h"
#include "QMCDrivers/DMC/SODMCUpdatePbyP.h"
#include "QMCDrivers/DMC/DMCUpdateAll.h"
#include "QMCHamiltonians/HamiltonianPool.h"
Expand Down Expand Up @@ -47,6 +48,7 @@ DMC::DMC(MCWalkerConfiguration& w,
: QMCDriver(w, psi, h, comm, "DMC"),
KillNodeCrossing(0),
BranchInterval(-1),
L2("no"),
Reconfiguration("no"),
mover_MaxAge(-1)
{
Expand All @@ -58,6 +60,7 @@ DMC::DMC(MCWalkerConfiguration& w,
m_param.add(NonLocalMove, "nonlocalmove", "string");
m_param.add(NonLocalMove, "nonlocalmoves", "string");
m_param.add(mover_MaxAge, "MaxAge", "double");
m_param.add(L2,"L2_diffusion","string");
}

void DMC::resetUpdateEngines()
Expand Down Expand Up @@ -139,7 +142,17 @@ void DMC::resetUpdateEngines()
{
if (qmc_driver_mode[QMC_UPDATE_MODE])
{
Movers[ip] = new DMCUpdatePbyPWithRejectionFast(*wClones[ip], *psiClones[ip], *hClones[ip], *Rng[ip]);
bool do_L2 = L2=="yes";
if(!do_L2)
{
app_log()<<"Using DMCUpdatePbyPWithRejectionFast\n";
Movers[ip] = new DMCUpdatePbyPWithRejectionFast(*wClones[ip], *psiClones[ip], *hClones[ip], *Rng[ip]);
}
else
{
app_log()<<"Using DMCUpdatePbyPL2\n";
Movers[ip] = new DMCUpdatePbyPL2(*wClones[ip], *psiClones[ip], *hClones[ip], *Rng[ip]);
}
Movers[ip]->put(qmcNode);
Movers[ip]->resetRun(branchEngine, estimatorClones[ip], traceClones[ip], DriftModifier);
Movers[ip]->initWalkersForPbyP(W.begin() + wPerNode[ip], W.begin() + wPerNode[ip + 1]);
Expand Down
2 changes: 2 additions & 0 deletions src/QMCDrivers/DMC/DMC.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class DMC : public QMCDriver, public CloneManager
std::string KillWalker;
///input std::string to determine swap walkers among mpi processors
std::string SwapWalkers;
///input to control diffusion with L2 operator
std::string L2;
///input std::string to determine to use reconfiguration
std::string Reconfiguration;
///input std::string to determine to use nonlocal move
Expand Down
239 changes: 239 additions & 0 deletions src/QMCDrivers/DMC/DMCUpdatePbyPL2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
//////////////////////////////////////////////////////////////////////////////////////
// This file is distributed under the University of Illinois/NCSA Open Source License.
// See LICENSE file in top directory for details.
//
// Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
//
// File developed by: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
// Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
// Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
// Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
//
// File created by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
//////////////////////////////////////////////////////////////////////////////////////


#include "QMCDrivers/DMC/DMCUpdatePbyPL2.h"
#include "Particle/MCWalkerConfiguration.h"
// #include "Particle/DistanceTable.h"
#include "Particle/HDFWalkerIO.h"
#include "ParticleBase/ParticleUtility.h"
#include "ParticleBase/RandomSeqGenerator.h"
#include "QMCDrivers/DriftOperators.h"
#if !defined(REMOVE_TRACEMANAGER)
#include "Estimators/TraceManager.h"
#else
typedef int TraceManager;
#endif
//#define TEST_INNERBRANCH
#include "QMCDrivers/DMC/DMCUpdatePbyP.h"

namespace qmcplusplus
{
using WP = WalkerProperties::Indexes;

/// Constructor.
DMCUpdatePbyPL2::DMCUpdatePbyPL2(MCWalkerConfiguration& w,
TrialWaveFunction& psi,
QMCHamiltonian& h,
RandomGenerator_t& rg)
: QMCUpdateBase(w, psi, h, rg)
{
setup_timers(myTimers, DMCTimerNames, timer_level_medium);
}

/// destructor
DMCUpdatePbyPL2::~DMCUpdatePbyPL2() {}

void DMCUpdatePbyPL2::advanceWalker(Walker_t& thisWalker, bool recompute)
{
myTimers[DMC_buffer]->start();
Walker_t::WFBuffer_t& w_buffer(thisWalker.DataSet);
W.loadWalker(thisWalker, true);
Psi.copyFromBuffer(W, w_buffer);
myTimers[DMC_buffer]->stop();
//create a 3N-Dimensional Gaussian with variance=1
makeGaussRandomWithEngine(deltaR, RandomGen);
int nAcceptTemp(0);
int nRejectTemp(0);
//copy the old energy and scale factor of drift
//EstimatorRealType eold(thisWalker.Properties(LOCALENERGY));
//EstimatorRealType enew(eold);
FullPrecRealType eold(thisWalker.Properties(WP::LOCALENERGY));
FullPrecRealType enew(eold);
RealType rr_proposed = 0.0;
RealType rr_accepted = 0.0;
RealType gf_acc = 1.0;
mPosType K;
mTensorType D;
mTensorType Dchol;
PosType Ktmp,drtmp;
TensorType Dtmp;
bool L2_proj = H.has_L2();
if(L2_proj)
{
Ktmp = 0.0;
Dtmp = 0.0;
for(int d=0;d<DIM;d++)
Dtmp(d,d) = 1.0;
}
myTimers[DMC_movePbyP]->start();
for (int ig = 0; ig < W.groups(); ++ig) //loop over species
{
RealType tauovermass = Tau * MassInvS[ig];
RealType oneover2tau = 0.5 / (tauovermass);
RealType sqrttau = std::sqrt(tauovermass);
RealType rr;
for (int iat = W.first(ig); iat < W.last(ig); ++iat)
{
//W.setActive(iat);
//get the displacement
GradType grad_iat = Psi.evalGrad(W, iat);
mPosType dr;
mPosType dr_diff = deltaR[iat];
if(!L2_proj) // normal projector
{
getScaledDrift(tauovermass, grad_iat, dr);
dr += sqrttau * dr_diff;
rr = tauovermass * dot(dr_diff, dr_diff);
rr_proposed += rr;
if (rr > m_r2max)
{
++nRejectTemp;
continue;
}
if (!W.makeMoveAndCheck(iat, dr))
continue;
}
else // projector including L2 potential
{
// do a fake move (zero distance)
// this ensures the temporary distance data is correct
// will need to remove this later, but requires reimplementation of computeL2DK
dr = 0.0;
if (!W.makeMoveAndCheck(iat, dr))
continue;

H.computeL2DK(W,iat,Dtmp,Ktmp);
D = Dtmp; // upcast for mixed precision
K = Ktmp;
getScaledDriftL2(tauovermass,grad_iat,D,K,dr);

W.rejectMove(iat);
rr = tauovermass * dot(dr_diff, dr_diff);
rr_proposed += rr;
if (rr > m_r2max)
{
++nRejectTemp;
continue;
}

// move with just drift to update distance tables
if (!W.makeMoveAndCheck(iat, dr))
continue;

// compute diffusion step
H.computeL2D(W,iat,Dtmp);
D = Dtmp; // upcast for mixed precision
Dchol = cholesky(D);
dr_diff = dot(Dchol,dr_diff);
dr += sqrttau * dr_diff;

// reverse the intermediate drift move
W.rejectMove(iat);
jtkrogel marked this conversation as resolved.
Show resolved Hide resolved
// move with drift and diffusion together
if (!W.makeMoveAndCheck(iat, dr))
continue;
}
ValueType ratio = Psi.calcRatioGrad(W, iat, grad_iat);
//node is crossed reject the move
if (branchEngine->phaseChanged(Psi.getPhaseDiff()))
{
++nRejectTemp;
++nNodeCrossing;
W.rejectMove(iat);
Psi.rejectMove(iat);
}
else
{
FullPrecRealType logGf = -0.5 * dot(deltaR[iat], deltaR[iat]);
//Use the force of the particle iat
DriftModifier->getDrift(tauovermass, grad_iat, drtmp);
dr = drtmp; // upcast for mixed precision
dr = W.R[iat] - W.activePos - dr;
FullPrecRealType logGb = -oneover2tau * dot(dr, dr);
RealType prob = std::norm(ratio) * std::exp(logGb - logGf);
if (RandomGen() < prob)
{
++nAcceptTemp;
Psi.acceptMove(W, iat, true);
W.acceptMove(iat, true);
rr_accepted += rr;
gf_acc *= prob; //accumulate the ratio
}
else
{
++nRejectTemp;
W.rejectMove(iat);
Psi.rejectMove(iat);
}
}
}
}
Psi.completeUpdates();
W.donePbyP();
myTimers[DMC_movePbyP]->stop();

if (nAcceptTemp > 0)
{
//need to overwrite the walker properties
myTimers[DMC_buffer]->start();
thisWalker.Age = 0;
RealType logpsi = Psi.updateBuffer(W, w_buffer, recompute);
W.saveWalker(thisWalker);
myTimers[DMC_buffer]->stop();
myTimers[DMC_hamiltonian]->start();
enew = H.evaluateWithToperator(W);
myTimers[DMC_hamiltonian]->stop();
thisWalker.resetProperty(logpsi, Psi.getPhase(), enew, rr_accepted, rr_proposed, 1.0);
thisWalker.Weight *= branchEngine->branchWeight(enew, eold);
myTimers[DMC_collectables]->start();
H.auxHevaluate(W, thisWalker);
H.saveProperty(thisWalker.getPropertyBase());
myTimers[DMC_collectables]->stop();
}
else
{
//all moves are rejected: does not happen normally with reasonable wavefunctions
thisWalker.Age++;
thisWalker.Properties(WP::R2ACCEPTED) = 0.0;
//weight is set to 0 for traces
// consistent w/ no evaluate/auxHevaluate
RealType wtmp = thisWalker.Weight;
thisWalker.Weight = 0.0;
H.rejectedMove(W, thisWalker);
thisWalker.Weight = wtmp;
++nAllRejected;
enew = eold; //copy back old energy
gf_acc = 1.0;
thisWalker.Weight *= branchEngine->branchWeight(enew, eold);
}
#if !defined(REMOVE_TRACEMANAGER)
Traces->buffer_sample(W.current_step);
#endif
myTimers[DMC_tmoves]->start();
const int NonLocalMoveAcceptedTemp = H.makeNonLocalMoves(W);
if (NonLocalMoveAcceptedTemp > 0)
{
RealType logpsi = Psi.updateBuffer(W, w_buffer, false);
W.saveWalker(thisWalker);
NonLocalMoveAccepted += NonLocalMoveAcceptedTemp;
}
myTimers[DMC_tmoves]->stop();
nAccept += nAcceptTemp;
nReject += nRejectTemp;

setMultiplicity(thisWalker);
}

} // namespace qmcplusplus
45 changes: 45 additions & 0 deletions src/QMCDrivers/DMC/DMCUpdatePbyPL2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//////////////////////////////////////////////////////////////////////////////////////
// This file is distributed under the University of Illinois/NCSA Open Source License.
// See LICENSE file in top directory for details.
//
// Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
//
// File developed by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
// Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
// Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
// Jeongnim Kim, jeongnim.kim@intel.com, Intel Corp.
//
// File created by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
//////////////////////////////////////////////////////////////////////////////////////


#ifndef QMCPLUSPLUS_DMC_UPDATE_PARTICLEBYPARTCLE_L2_H
#define QMCPLUSPLUS_DMC_UPDATE_PARTICLEBYPARTCLE_L2_H
#include "QMCDrivers/QMCUpdateBase.h"
#include "Utilities/TimerManager.h"

namespace qmcplusplus
{
class DMCUpdatePbyPL2 : public QMCUpdateBase
{
public:
/// Constructor.
DMCUpdatePbyPL2(MCWalkerConfiguration& w,
TrialWaveFunction& psi,
QMCHamiltonian& h,
RandomGenerator_t& rg);
///destructor
~DMCUpdatePbyPL2();

void advanceWalker(Walker_t& thisWalker, bool recompute);

private:
TimerList_t myTimers;
};

//extern TimerNameList_t<DMCTimers> DMCTimerNames;


} // namespace qmcplusplus

#endif
Loading