qmctorch.solver package

Module contents

class qmctorch.solver.SolverBase(wf=None, sampler=None, optimizer=None, scheduler=None, output=None, rank=0)[source]

Bases: object

Base Class for QMC solver

Parameters:
  • wf (qmctorch.WaveFunction, optional) – wave function. Defaults to None.
  • sampler (qmctorch.sampler, optional) – Sampler. Defaults to None.
  • optimizer (torch.optim, optional) – optimizer. Defaults to None.
  • scheduler (torch.optim, optional) – scheduler. Defaults to None.
  • output (str, optional) – hdf5 filename. Defaults to None.
  • rank (int, optional) – rank of he process. Defaults to 0.
configure_resampling(mode='update', resample_every=1, nstep_update=25)[source]

Configure the resampling

Parameters:
  • mode (str, optional) – method to resample : ‘full’, ‘update’, ‘never’ Defaults to ‘update’.
  • resample_every (int, optional) – Number of optimization steps between resampling Defaults to 1.
  • nstep_update (int, optional) – Number of MC steps in update mode. Defaults to 25.
track_observable(obs_name)[source]

define the observalbe we want to track

Parameters:obs_name (list) – list of str defining the observalbe. Each str must correspond to a WaveFuncion method
store_observable(pos, local_energy=None, ibatch=None, **kwargs)[source]

store observale in the dictionary

Parameters:
  • obs_dict (dict) – dictionary of the observalbe
  • pos (torch.tensor) – positions of th walkers
  • local_energy (torch.tensor, optional) – precomputed values of the local energy. Defaults to None
  • ibatch (int) – index of the current batch. Defaults to None
print_observable(cumulative_loss, verbose=False)[source]

Print the observalbe to csreen

Parameters:
  • cumulative_loss (float) – current loss value
  • verbose (bool, optional) – print all the observables. Defaults to False
resample(n, pos)[source]

Resample the wave function

Parameters:
  • n (int) – current epoch value
  • pos (torch.tensor) – positions of the walkers
Returns:

new positions of the walkers

Return type:

(torch.tensor)

single_point(with_tqdm=True, hdf5_group='single_point')[source]

Performs a single point calculatin

Parameters:
  • with_tqdm (bool, optional) – use tqdm for samplig. Defaults to True.
  • hdf5_group (str, optional) – hdf5 group where to store the data. Defaults to ‘single_point’.
Returns:

contains the local energy, positions, …

Return type:

SimpleNamespace

save_checkpoint(epoch, loss)[source]

save the model and optimizer state

Parameters:
  • epoch (int) – epoch
  • loss (float) – current value of the loss
  • filename (str) – name to save the file
load_checkpoint(filename)[source]

load a model/optmizer

Parameters:filename (str) – filename
Returns:epoch number and loss
Return type:tuple
sampling_traj(pos=None, with_tqdm=True, hdf5_group='sampling_trajectory')[source]

Compute the local energy along a sampling trajectory

Parameters:
  • pos (torch.tensor) – positions of the walkers along the trajectory
  • hdf5_group (str, optional) – name of the group where to store the data. Defaults to ‘sampling_trajecory’
Returns:

contains energy/positions/

Return type:

SimpleNamespace

print_parameters(grad=False)[source]

print parameter values

Parameters:grad (bool, optional) – also print the gradient. Defaults to False.
optimization_step(lpos)[source]

Performs one optimization step

Parameters:{torch.tensor} -- positions of the walkers (lpos) –
save_traj(fname, obs)[source]

Save trajectory of geo_opt

Parameters:fname (str) – file name
run(nepoch, batchsize=None, loss='variance')[source]
log_data()[source]

Log basic information about the sampler.

class qmctorch.solver.Solver(wf=None, sampler=None, optimizer=None, scheduler=None, output=None, rank=0)[source]

Bases: qmctorch.solver.solver_base.SolverBase

Basic QMC solver

Parameters:
  • wf (qmctorch.WaveFunction, optional) – wave function. Defaults to None.
  • sampler (qmctorch.sampler, optional) – Sampler. Defaults to None.
  • optimizer (torch.optim, optional) – optimizer. Defaults to None.
  • scheduler (torch.optim, optional) – scheduler. Defaults to None.
  • output (str, optional) – hdf5 filename. Defaults to None.
  • rank (int, optional) – rank of he process. Defaults to 0.
configure(track=None, freeze=None, loss=None, grad=None, ortho_mo=None, clip_loss=False, resampling=None)[source]

Configure the solver

Parameters:
  • track (list, optional) – list of observable to track. Defaults to [‘local_energy’].
  • freeze ([type], optional) – list of parameters to freeze. Defaults to None.
  • loss (str, optional) – merhod to compute the loss: variance or energy. Defaults to ‘energy’.
  • grad (str, optional) – method to compute the gradients: ‘auto’ or ‘manual’. Defaults to ‘auto’.
  • ortho_mo (bool, optional) – apply regularization to orthogonalize the MOs. Defaults to False.
  • clip_loss (bool, optional) – Clip the loss values at +/- X std. X defined in Loss as clip_num_std (default 5) Defaults to False.
set_params_requires_grad(wf_params=True, geo_params=False)[source]

Configure parameters for wf opt.

freeze_parameters(freeze)[source]

Freeze the optimization of specified params.

Parameters:freeze (list) – list of param to freeze
save_sampling_parameters(pos)[source]

save the sampling params.

restore_sampling_parameters()[source]

restore sampling params to their original values.

geo_opt(nepoch, geo_lr=0.01, batchsize=None, nepoch_wf_init=100, nepoch_wf_update=50, hdf5_group='geo_opt', chkpt_every=None, tqdm=False)[source]

optimize the geometry of the molecule

Parameters:
  • nepoch (int) – Number of optimziation step
  • batchsize (int, optional) – Number of sample in a mini batch. If None, all samples are used. Defaults to Never.
  • hdf5_group (str, optional) – name of the hdf5 group where to store the data. Defaults to ‘geo_opt’.
  • chkpt_every (int, optional) – save a checkpoint every every iteration. Defaults to half the number of epoch
run(nepoch, batchsize=None, hdf5_group='wf_opt', chkpt_every=None, tqdm=False)[source]

Run a wave function optimization

Parameters:
  • nepoch (int) – Number of optimziation step
  • batchsize (int, optional) – Number of sample in a mini batch. If None, all samples are used. Defaults to Never.
  • hdf5_group (str, optional) – name of the hdf5 group where to store the data. Defaults to ‘wf_opt’.
  • chkpt_every (int, optional) – save a checkpoint every every iteration. Defaults to half the number of epoch
prepare_optimization(batchsize, chkpt_every, tqdm=False)[source]

Prepare the optimization process

Parameters:
  • batchsize (int or None) – batchsize
  • chkpt_every (int or none) – save a chkpt file every
save_data(hdf5_group)[source]

Save the data to hdf5.

Parameters:hdf5_group (str) – name of group in the hdf5 file
run_epochs(nepoch)[source]

Run a certain number of epochs

Parameters:nepoch (int) – number of epoch to run
evaluate_grad_auto(lpos)[source]

Evaluate the gradient using automatic differentiation

Parameters:lpos (torch.tensor) – sampling points
Returns:loss values and local energies
Return type:tuple
evaluate_grad_manual(lpos)[source]

Evaluate the gradient using low variance expression

Parameters:
  • lpos (torch.tensor) – [description]
  • lpos – sampling points
Returns:

loss values and local energies

Return type:

tuple

log_data_opt(nepoch, task)[source]

Log data for the optimization.

class qmctorch.solver.SolverMPI(wf=None, sampler=None, optimizer=None, scheduler=None, output=None, rank=0)[source]

Bases: qmctorch.solver.solver.Solver

Distributed QMC solver

Parameters:
  • wf (qmctorch.WaveFunction, optional) – wave function. Defaults to None.
  • sampler (qmctorch.sampler, optional) – Sampler. Defaults to None.
  • optimizer (torch.optim, optional) – optimizer. Defaults to None.
  • scheduler (torch.optim, optional) – scheduler. Defaults to None.
  • output (str, optional) – hdf5 filename. Defaults to None.
  • rank (int, optional) – rank of he process. Defaults to 0.
run(nepoch, batchsize=None, loss='energy', clip_loss=False, grad='manual', hdf5_group='wf_opt', num_threads=1, chkpt_every=None)[source]

Run the optimization

Parameters:
  • nepoch (int) – Number of optimization step
  • batchsize (int, optional) – Number of sample in a mini batch. If None, all samples are used. Defaults to None.
  • loss (str, optional) – method to compute the loss: variance or energy. Defaults to ‘energy’.
  • clip_loss (bool, optional) – Clip the loss values at +/- 5std. Defaults to False.
  • grad (str, optional) – method to compute the gradients: ‘auto’ or ‘manual’. Defaults to ‘auto’.
  • hdf5_group (str, optional) – name of the hdf5 group where to store the data. Defaults to ‘wf_opt’
single_point(with_tqdm=True, hdf5_group='single_point')[source]

Performs a single point calculation

Parameters:
  • with_tqdm (bool, optional) – use tqdm for samplig. Defaults to True.
  • hdf5_group (str, optional) – hdf5 group where to store the data. Defaults to ‘single_point’.
Returns:

contains the local energy, positions, …

Return type:

SimpleNamespace

static metric_average(val, name)[source]

Average a give quantity over all processes

Parameters:
  • {torch.tensor} -- data to average (val) –
  • {str} -- name of the data (name) –
Returns:

torch.tensor – Averaged quantity