Skip to content

Commit

Permalink
clean up example
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoRenaud committed Apr 29, 2020
1 parent a483ece commit f7afaaf
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 170 deletions.
9 changes: 9 additions & 0 deletions docs/molecule.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,12 @@ The two other keyword arguments (``calculator`` and ``basis``) refers to the QM
used to describe the electronic strucrure of the molecule. The calculator refers to a particular QM package and so far only
``pyscf`` and ``adf`` are supported. ``basis`` refers to the basis set used for the calculation.
The value of the keyword argument should be a valid name of an **all electron** basis set.

Load from HDF5
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Creating a molecule will automatically geneate a HDF5 file containing all the information
about the molecule (geometry, basis, etc ...). It is possible to load this hdf5 file in molecule

>>> mol = Molecule(load='H2_adf_dzp.hdf5')

67 changes: 22 additions & 45 deletions example/h2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
from qmctorch.wavefunction import Orbital, Molecule
from qmctorch.solver import SolverOrbital
from qmctorch.sampler import Metropolis

from qmctorch.utils import set_torch_double_precision

from qmctorch.utils import (plot_energy, plot_data, plot_walkers_traj)
from qmctorch.utils import (plot_energy, plot_data)

# bond distance : 0.74 A -> 1.38 a
# optimal H positions +0.69 and -0.69
Expand All @@ -21,10 +19,6 @@
basis='dzp',
unit='bohr')

# load the molecule from a previous hdf5
# mol = Molecule(load='H2_pyscf_dzp.hdf5')


# define the wave function
wf = Orbital(mol, kinetic='jacobi',
configs='cas(2,2)',
Expand All @@ -33,18 +27,18 @@
wf.jastrow.weight.data[0] = 1.

# sampler
sampler = Metropolis(nwalkers=50,
nstep=200, step_size=0.2,
sampler = Metropolis(nwalkers=2000,
nstep=2000, step_size=0.2,
ntherm=-1, ndecor=100,
nelec=wf.nelec, init=mol.domain('atomic'),
move={'type': 'all-elec', 'proba': 'normal'})


# optimizer
lr_dict = [{'params': wf.jastrow.parameters(), 'lr': 1E-3},
lr_dict = [{'params': wf.jastrow.parameters(), 'lr': 3E-3},
{'params': wf.ao.parameters(), 'lr': 1E-6},
{'params': wf.mo.parameters(), 'lr': 1E-3},
{'params': wf.fc.parameters(), 'lr': 1E-3}]
{'params': wf.fc.parameters(), 'lr': 2E-3}]
opt = optim.Adam(lr_dict, lr=1E-3)

# scheduler
Expand All @@ -54,38 +48,21 @@
solver = SolverOrbital(wf=wf, sampler=sampler,
optimizer=opt, scheduler=None)


# perform a single point calculation
# obs = solver.single_point()

# compute the sampling trajectory
# solver.sampler.ntherm = 1000
# solver.sampler.ndecor = 100
# pos = solver.sampler(solver.wf.pdf)
# obs = solver.sampling_traj(pos)
# plot_walkers_traj(obs.local_energy)


# # optimize the wave function
# solver.configure(task='wf_opt', freeze=['ao', 'mo'])
# solver.track_observable(['local_energy'])

# solver.configure_resampling(
# mode='update', resample_every=1, nstep_update=25)
# solver.ortho_mo = False
# data = solver.run(5, batchsize=None,
# loss='energy',
# grad='manual',
# clip_loss=False)

# plot_energy(solver.observable.local_energy, e0=-
# 1.1645, show_variance=True)
# plot_data(solver.observable, obsname='jastrow.weight')

# optimize the geometry
solver.configure(task='geo_opt')
solver.track_observable(['local_energy', 'atomic_distances'])
data = solver.run(5, batchsize=None,
loss='energy',
grad='manual',
clip_loss=False)
obs = solver.single_point()

# optimize the wave function
solver.configure(task='wf_opt', freeze=['ao', 'mo'])
solver.track_observable(['local_energy'])

solver.configure_resampling(mode='update',
resample_every=1,
nstep_update=50)
solver.ortho_mo = False
obs = solver.run(250, batchsize=None,
loss='energy',
grad='manual',
clip_loss=False)

plot_energy(obs.local_energy, e0=-1.1645, show_variance=True)
plot_data(solver.observable, obsname='jastrow.weight')
60 changes: 0 additions & 60 deletions example/h2_gpu.py

This file was deleted.

63 changes: 0 additions & 63 deletions example/h2_hvd.py

This file was deleted.

4 changes: 2 additions & 2 deletions example/h2o_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use_jastrow=True)

# sampler
sampler = Metropolis(nwalkers=100, nstep=300, step_size=0.25,
sampler = Metropolis(nwalkers=100, nstep=500, step_size=0.25,
nelec=wf.nelec, ndim=wf.ndim,
init=mol.domain('atomic'),
move={'type': 'one-elec', 'proba': 'normal'})
Expand All @@ -26,7 +26,7 @@

# reconfigure sampler
solver.sampler.ntherm = 0
solver.sampler.ndecor = 3
solver.sampler.ndecor = 5

# compute the sampling traj
pos = solver.sampler(solver.wf.pdf)
Expand Down

0 comments on commit f7afaaf

Please sign in to comment.