Skip to content

Commit

Permalink
renamed solvers
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoRenaud committed Apr 2, 2021
1 parent a623bca commit e65381d
Show file tree
Hide file tree
Showing 27 changed files with 81 additions and 75 deletions.
2 changes: 1 addition & 1 deletion bin/qmctorch
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import os
import argparse


dist_solvers = ['SolverOrbitalHorovod']
dist_solvers = ['SolverSlaterJastrowHorovod']


def check_file(fname):
Expand Down
2 changes: 1 addition & 1 deletion docs/qmctorch.solver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Solver
Solver
----------------------------------------

.. automodule:: qmctorch.solver.solver_orbital
.. automodule:: qmctorch.solver.solver_slater_jastrow
:members:
:undoc-members:

Expand Down
24 changes: 12 additions & 12 deletions docs/solver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ Solvers
=========================

Solvers are responsibe to orchestrate the calculations by combining the different elements, Molecule, QMCNet wave function, samplers and optimizers/schedulers
The main solver is caled `SolverOrbital` and is defined as
The main solver is caled `SolverSlaterJastrow` and is defined as

>>> from qmctorch.solver import SolverOrbital
>>> solver = SolverOrbital(wf=wf, sampler=sampler,
>>> from qmctorch.solver import SolverSlaterJastrow
>>> solver = SolverSlaterJastrow(wf=wf, sampler=sampler,
>>> optimizer=opt, scheduler=scheduler, output='output.hdf5'

As soon as the solver its content is defined the HDF5 file specficied byt `out`. This file will contain all the parameter
Expand All @@ -14,7 +14,7 @@ of the solver and can be explored using the dedicated `h5x` browser. This solver
Single point calculation
----------------------------

A single point calculation sample the current wave function and computes the energy & variance of the system.
A single point calculation sample the current wave function and computes the energy & variance of the system.
It can simply be done by:

>>> obs = solver.single_point()
Expand All @@ -27,14 +27,14 @@ It can simply be done by:
* `obs.variance` : variance of the local energy values
* `obs.error` : error on the energy

The result of the calculation will also be stored in the hdf5 output file. The energy distribution can be vizualised
The result of the calculation will also be stored in the hdf5 output file. The energy distribution can be vizualised
with the matplotlib histogram function.

Sampling trajectory
----------------------------

It is possible to compute the local energy during the propagation of the wlakers to assess the convergence of the sampling
To this end the sampler must be configured to output the walker position after each `N` steps.
To this end the sampler must be configured to output the walker position after each `N` steps.
For example to start recording the walkers positions after 1000 MC steps and then record their position each 100 MC steps one can use :

>>> from qmctorch.utils import plot_walkers_traj
Expand All @@ -44,7 +44,7 @@ For example to start recording the walkers positions after 1000 MC steps and the
>>> obs = solver.sampling_traj(pos)
>>> plot_walkers_traj(obs.local_energy)

There as well the results are returned in the `obs` SimpleNamespace and are stored in the hdf5 file.
There as well the results are returned in the `obs` SimpleNamespace and are stored in the hdf5 file.
The trajectory can be visualized with the `plot_wakers_traj` routine of QMCTorch

Wave function optimization
Expand All @@ -55,24 +55,24 @@ configured properly.

>>> solver.configure(task='wf_opt', freeze=['ao', 'mo'])

To main task are available wave function optimization (`wf_opt`) and geometry optimization (`geo_opt`).
To main task are available wave function optimization (`wf_opt`) and geometry optimization (`geo_opt`).
If a wave function optimization is selected the atom coordinate will be frozen while all the other parameters of the QMCNet will be optimized.
If a geometry optimization is selected only the atom coordinates will be optimized. One cal also freeze (i.e. not optimize) certain parameter groups.
If a geometry optimization is selected only the atom coordinates will be optimized. One cal also freeze (i.e. not optimize) certain parameter groups.
In the example above the parameters of the atomic orbitals and molecular orbitals will be frozen,

One can specified the observale that needs to be recorded during the optimization.
One can specified the observale that needs to be recorded during the optimization.

>>> solver.track_observable(['local_energy'])

By default the local energy and all the variational parameters will be recorded.

As the system is optimized, one can resample the wave function by changing the positions of the walkers.
As the system is optimized, one can resample the wave function by changing the positions of the walkers.
Several strategies are available to resample the wave function. The preferred one is to update the walkers by performing a small number of MC steps after each optimization step.
This can be specified with :

>>> solver.configure_resampling(mode='update', resample_every=1, nstep_update=25)

Finally we can now optimize the wave function using the `.run()` method of the solver.
Finally we can now optimize the wave function using the `.run()` method of the solver.
This methods takes a few arguments, the number of optimization step, the batchsize, and some parameters to compute the gradients.

>>> data = solver.run(5, batchsize=None,
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorial_geo_opt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ As previously the firs task is to import all the modules needed
>>> from torch import optim
>>> from torch.optim import Adam
>>> from qmctorch.wavefunction import SlaterJastrow
>>> from qmctorch.solver import SolverOrbital
>>> from qmctorch.solver import SolverSlaterJastrow
>>> from qmctorch.samplerimport Metropolis
>>> from qmctorch.wavefunction import Molecule
>>> from qmctorch.utils import plot_energy
Expand Down Expand Up @@ -47,7 +47,7 @@ As an opimizer we use ADAM and define a simple linear scheduler.
We can now assemble the solver

>>> # solver
>>> solver = SolverOrbital(wf=wf,
>>> solver = SolverSlaterJastrow(wf=wf,
>>> sampler=sampler,
>>> optimizer=opt,
>>> scheduler=scheduler)
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorial_gpus.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ and use is as the normal solver and only a few modifications are required to use


>>> import horovod.torch as hvd
>>> from deepqmc.solver.solver_orbital_horovod import SolverOrbitalHorovod
>>> from deepqmc.solver.solver_slater_jastrow_horovod import SolverSlaterJastrowHorovod
>>>
>>> hvd.init()
>>> if torch.cuda.is_available():
Expand All @@ -48,7 +48,7 @@ and use is as the normal solver and only a few modifications are required to use
>>>
>>> ...
>>>
>>> solver = SolverOrbitalHorovod(wf=wf, sampler=sampler,
>>> solver = SolverSlaterJastrowHorovod(wf=wf, sampler=sampler,
>>> optimizer=opt, scheduler=scheduler,
>>> rank=hvd.rank())
>>> ....
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial_sampling_traj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ During the MC sampling each walker performs 500 steps of 0.25 atomic units. We h
We can now assemble the solver.

>>> # solver
>>> solver = SolverOrbital(wf=wf, sampler=sampler)
>>> solver = SolverSlaterJastrow(wf=wf, sampler=sampler)

We can first perform a single point calculation.
In this calculation the solver will sample the wave function and compute the energy of the system.
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorial_wf_opt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ We first need to import all the relevant modules :

>>> from torch import optim
>>> from qmctorch.wavefunction import SlaterJastrow, Molecule
>>> from qmctorch.solver import SolverOrbital
>>> from qmctorch.solver import SolverSlaterJastrow
>>> from qmctorch.sampler import Metropolis
>>> from qmctorch.utils import set_torch_double_precision
>>> from qmctorch.utils import (plot_energy, plot_data)
Expand Down Expand Up @@ -62,7 +62,7 @@ We also define a linear scheduler that will decrease the learning rate after 100
We can now assemble the solver :

>>> # QMC solver
>>> solver = SolverOrbital(wf=wf, sampler=sampler, optimizer=opt, scheduler=None)
>>> solver = SolverSlaterJastrow(wf=wf, sampler=sampler, optimizer=opt, scheduler=None)

The solver needs to be configured. We set the task to wave function optimization and freeze here the
variational parameters of the atomic orbitals and molecular orbitals. Hence only the jastrow factor and the CI coefficients
Expand Down
6 changes: 3 additions & 3 deletions example/gpu/h2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from qmctorch.scf import Molecule
from qmctorch.wavefunction import SlaterJastrow
from qmctorch.solver import SolverOrbital
from qmctorch.solver import SolverSlaterJastrow
from qmctorch.sampler import Metropolis
from qmctorch.utils import set_torch_double_precision
from qmctorch.utils import (plot_energy, plot_data)
Expand Down Expand Up @@ -48,8 +48,8 @@
scheduler = optim.lr_scheduler.StepLR(opt, step_size=100, gamma=0.90)

# QMC solver
solver = SolverOrbital(wf=wf, sampler=sampler,
optimizer=opt, scheduler=None)
solver = SolverSlaterJastrow(wf=wf, sampler=sampler,
optimizer=opt, scheduler=None)

# perform a single point calculation
obs = solver.single_point()
Expand Down
8 changes: 4 additions & 4 deletions example/horovod/h2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from qmctorch.scf import Molecule
from qmctorch.wavefunction import SlaterJastrow
from qmctorch.solver import SolverOrbitalHorovod
from qmctorch.solver import SolverSlaterJastrowHorovod
from qmctorch.sampler import Metropolis
from qmctorch.utils import set_torch_double_precision
from qmctorch.utils import (plot_energy, plot_data)
Expand Down Expand Up @@ -51,9 +51,9 @@
scheduler = optim.lr_scheduler.StepLR(opt, step_size=100, gamma=0.90)

# QMC solver
solver = SolverOrbitalHorovod(wf=wf, sampler=sampler,
optimizer=opt, scheduler=scheduler,
rank=hvd.rank())
solver = SolverSlaterJastrowHorovod(wf=wf, sampler=sampler,
optimizer=opt, scheduler=scheduler,
rank=hvd.rank())

# configure the solver
solver.configure(track=['local_energy'], freeze=['ao', 'mo'],
Expand Down
6 changes: 3 additions & 3 deletions example/optimization/h2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from qmctorch.scf import Molecule
from qmctorch.wavefunction import SlaterJastrow
from qmctorch.solver import SolverOrbital
from qmctorch.solver import SolverSlaterJastrow
from qmctorch.sampler import Metropolis
from qmctorch.utils import set_torch_double_precision
from qmctorch.utils import (plot_energy, plot_data)
Expand Down Expand Up @@ -47,8 +47,8 @@
scheduler = optim.lr_scheduler.StepLR(opt, step_size=100, gamma=0.90)

# QMC solver
solver = SolverOrbital(wf=wf, sampler=sampler,
optimizer=opt, scheduler=None)
solver = SolverSlaterJastrow(wf=wf, sampler=sampler,
optimizer=opt, scheduler=None)

# perform a single point calculation
obs = solver.single_point()
Expand Down
4 changes: 2 additions & 2 deletions example/single_point/h2o_sampling.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from qmctorch.scf import Molecule
from qmctorch.wavefunction import SlaterJastrow
from qmctorch.sampler import Metropolis
from qmctorch.solver import SolverOrbital
from qmctorch.solver import SolverSlaterJastrow
from qmctorch.utils import plot_walkers_traj

# define the molecule
Expand All @@ -20,7 +20,7 @@
move={'type': 'one-elec', 'proba': 'normal'})

# solver
solver = SolverOrbital(wf=wf, sampler=sampler)
solver = SolverSlaterJastrow(wf=wf, sampler=sampler)

# single point
obs = solver.single_point()
Expand Down
2 changes: 1 addition & 1 deletion notebooks/qmctorch.ipynb

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions qmctorch/solver/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
__all__ = ['SolverBase', 'SolverOrbital', 'SolverOrbitalHorovod']
__all__ = ['SolverBase', 'SolverSlaterJastrow',
'SolverSlaterJastrowHorovod']

from .solver_base import SolverBase
from .solver_orbital import SolverOrbital
from .solver_orbital_horovod import SolverOrbitalHorovod
from .solver_slater_jastrow import SolverSlaterJastrow
from .solver_slater_jastrow_horovod import SolverSlaterJastrowHorovod
5 changes: 5 additions & 0 deletions qmctorch/solver/solver_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ def __init__(self, wf=None, sampler=None,
self.cuda = False
self.device = torch.device('cpu')

# member defined in the child and or method
self.dataloader = None
self.loss = None
self.obs_dict = None

# if pos are needed for the optimizer (obsolete ?)
if self.opt is not None and 'lpos_needed' not in self.opt.__dict__.keys():
self.opt.lpos_needed = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .solver_base import SolverBase


class SolverOrbital(SolverBase):
class SolverSlaterJastrow(SolverBase):

def __init__(self, wf=None, sampler=None, optimizer=None,
scheduler=None, output=None, rank=0):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
dump_to_hdf5)

from .. import log
from .solver_orbital import SolverOrbital
from .solver_slater_jastrow import SolverSlaterJastrow

try:
import horovod.torch as hvd
Expand All @@ -21,7 +21,7 @@ def logd(rank, *args):
log.info(*args)


class SolverOrbitalHorovod(SolverOrbital):
class SolverSlaterJastrowHorovod(SolverSlaterJastrow):

def __init__(self, wf=None, sampler=None, optimizer=None,
scheduler=None, output=None, rank=0):
Expand All @@ -36,8 +36,8 @@ def __init__(self, wf=None, sampler=None, optimizer=None,
rank (int, optional): rank of he process. Defaults to 0.
"""

SolverOrbital.__init__(self, wf, sampler,
optimizer, scheduler, output, rank)
SolverSlaterJastrow.__init__(self, wf, sampler,
optimizer, scheduler, output, rank)

hvd.broadcast_optimizer_state(self.opt, root_rank=0)
self.opt = hvd.DistributedOptimizer(
Expand Down
6 changes: 3 additions & 3 deletions tests/solver/test_h2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import torch.optim as optim

from qmctorch.sampler import Hamiltonian, Metropolis
from qmctorch.solver import SolverOrbital
from qmctorch.solver import SolverSlaterJastrow
from qmctorch.utils import (plot_block, plot_blocking_energy,
plot_correlation_coefficient, plot_energy,
plot_integrated_autocorrelation_time,
Expand Down Expand Up @@ -63,8 +63,8 @@ def setUp(self):
self.opt = optim.Adam(self.wf.parameters(), lr=0.01)

# solver
self.solver = SolverOrbital(wf=self.wf, sampler=self.sampler,
optimizer=self.opt)
self.solver = SolverSlaterJastrow(wf=self.wf, sampler=self.sampler,
optimizer=self.opt)

# ground state energy
self.ground_state_energy = -1.16
Expand Down
6 changes: 3 additions & 3 deletions tests/solver/test_h2_adf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import torch.optim as optim

from qmctorch.sampler import Metropolis
from qmctorch.solver import SolverOrbital
from qmctorch.solver import SolverSlaterJastrow
from qmctorch.scf import Molecule
from qmctorch.wavefunction import SlaterJastrow

Expand Down Expand Up @@ -44,8 +44,8 @@ def setUp(self):
self.opt = optim.Adam(self.wf.parameters(), lr=0.01)

# solver
self.solver = SolverOrbital(wf=self.wf, sampler=self.sampler,
optimizer=self.opt)
self.solver = SolverSlaterJastrow(wf=self.wf, sampler=self.sampler,
optimizer=self.opt)

# ground state energy
self.ground_state_energy = -1.16
Expand Down
6 changes: 3 additions & 3 deletions tests/solver/test_h2_adf_jacobi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import torch.optim as optim

from qmctorch.sampler import Metropolis
from qmctorch.solver import SolverOrbital
from qmctorch.solver import SolverSlaterJastrow
from qmctorch.scf import Molecule
from qmctorch.wavefunction import SlaterJastrow
from ..path_utils import PATH_TEST
Expand Down Expand Up @@ -43,8 +43,8 @@ def setUp(self):
self.opt = optim.Adam(self.wf.parameters(), lr=0.01)

# solver
self.solver = SolverOrbital(wf=self.wf, sampler=self.sampler,
optimizer=self.opt)
self.solver = SolverSlaterJastrow(wf=self.wf, sampler=self.sampler,
optimizer=self.opt)

# ground state energy
self.ground_state_energy = -1.16
Expand Down
6 changes: 3 additions & 3 deletions tests/solver/test_h2_correlated.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from qmctorch.wavefunction.jastrows.elec_elec.fully_connected_jastrow import FullyConnectedJastrow

from qmctorch.sampler import Hamiltonian, Metropolis
from qmctorch.solver import SolverOrbital
from qmctorch.solver import SolverSlaterJastrow
from qmctorch.utils import (plot_block, plot_blocking_energy,
plot_correlation_coefficient, plot_energy,
plot_integrated_autocorrelation_time,
Expand Down Expand Up @@ -64,8 +64,8 @@ def setUp(self):
self.opt = optim.Adam(self.wf.parameters(), lr=0.01)

# solver
self.solver = SolverOrbital(wf=self.wf, sampler=self.sampler,
optimizer=self.opt)
self.solver = SolverSlaterJastrow(wf=self.wf, sampler=self.sampler,
optimizer=self.opt)

# ground state energy
self.ground_state_energy = -1.16
Expand Down
6 changes: 3 additions & 3 deletions tests/solver/test_h2_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import torch.optim as optim

from qmctorch.sampler import Metropolis
from qmctorch.solver import SolverOrbital
from qmctorch.solver import SolverSlaterJastrow
from qmctorch.utils import (plot_block, plot_blocking_energy,
plot_correlation_coefficient,
plot_integrated_autocorrelation_time,
Expand Down Expand Up @@ -58,8 +58,8 @@ def setUp(self):
self.opt = optim.Adam(self.wf.parameters(), lr=0.01)

# solver
self.solver = SolverOrbital(wf=self.wf, sampler=self.sampler,
optimizer=self.opt)
self.solver = SolverSlaterJastrow(wf=self.wf, sampler=self.sampler,
optimizer=self.opt)

def test_sampling_traj(self):

Expand Down
Loading

0 comments on commit e65381d

Please sign in to comment.