qmctorch.utils package

Module contents

Utils module API.

qmctorch.utils.plot_energy(local_energy, e0=None, show_variance=False)[source]

Plot the evolution of the energy

Parameters:
  • local_energy (np.ndarray) – local energies along the trajectory
  • e0 (float, optional) – Target value for the energy. Defaults to None.
  • show_variance (bool, optional) – show the variance if True. Defaults to False.
qmctorch.utils.plot_data(observable, obsname)[source]

Plot the evolution a given data

Parameters:
  • obs_dict (SimpleNamespace) – namespace of observable
  • obsname (str) – name (key) of the desired observable
qmctorch.utils.plot_block(eloc)[source]

Plot the blocking thingy

Parameters:eloc (np.array) – values of the local energy
qmctorch.utils.plot_walkers_traj(eloc, walkers='mean')[source]

Plot the trajectory of all the individual walkers

Parameters:
  • obs (SimpleNamespace) – Namespace of the observables
  • walkers (int, str, optional) – all, mean or index of a given walker Defaults to ‘all’
qmctorch.utils.plot_correlation_time(eloc)[source]

Plot the blocking thingy

Parameters:eloc (np.array) – values of the local energy
qmctorch.utils.set_torch_double_precision()[source]

Set the default precision to double for all torch tensors.

qmctorch.utils.set_torch_single_precision()[source]

Set the default precision to single for all torch tensors.

class qmctorch.utils.DataSet(data)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

Creates a torch data set

Parameters:{torch.tensor} -- data (data) –
class qmctorch.utils.Loss(wf, method='energy', clip=False)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

Defines the loss to use during the optimization

Parameters:

{WaveFunction} -- wave function object used (wf) –

Keyword Arguments:
 
  • {str} -- method to use (default (method) – {‘energy’}) (energy, variance, weighted-energy, weighted-variance)
  • {bool} -- clip the values that are +/- % sigma away from (clip) – the mean (default: {False})
forward(pos, no_grad=False, deactivate_weight=False)[source]

Computes the loss

Parameters:{torch.tensor} -- positions of the walkers in that batch (pos) –
Keyword Arguments:
 {bool} -- computes the gradient of the loss (no_grad) – (default: {False})
Returns:torch.tensor, torch.tensor – value of the loss, local energies
static get_grad_mode(no_grad)[source]

Returns enable_grad or no_grad

Parameters:{bool} -- [description] (no_grad) –
get_clipping_mask(local_energies)[source]

computes the clipping mask

Parameters:{torch.tensor} -- values of the local energies (local_energies) –
get_sampling_weights(pos, deactivate_weight)[source]

Get the weight needed when resampling is not done at every step

class qmctorch.utils.OrthoReg(alpha=0.1)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

Add a penalty loss to keep the MO orthogonalized

Keyword Arguments:
 {float} -- strength of the penaly (default (alpha) – {0.1})
forward(W)[source]

Return the loss : |W x W^T - I|.

qmctorch.utils.dump_to_hdf5(obj, fname, root_name=None)[source]

Dump the content of an object in a hdf5 file.

Parameters:
  • {object} -- object to dump (obj) –
  • {str} -- name of the hdf5 (fname) –
Keyword Arguments:
 

{str} -- root group in the hdf5 file (default (root_name) – {None})

qmctorch.utils.load_from_hdf5(obj, fname, obj_name)[source]

Load the content of an hdf5 file in an object.

Parameters:
  • {object} -- object where to load the data (obj) –
  • {str} -- name pf the hdf5 file (fname) –
  • {str} -- name of the root group in the hdf5 (obj_name) –
qmctorch.utils.bytes2str(bstr)[source]

Convert a bytes into string.

qmctorch.utils.register_extra_attributes(obj, attr_names)[source]

Register extra attribute to be able to dump them

Parameters:
  • {object} -- the object where we want to add attr (obj) –
  • {list} -- a list of attr names (attr_names) –
qmctorch.utils.fast_power(x, k, mask0=None, mask2=None)[source]

Computes x**k when k have elements 0, 1, 2

Parameters:
  • x (torch.tensor) – input
  • k (torch.tensor) – exponents
  • mask0 (torch.tensor) – precomputed mask of the elements of that are 0 (Defaults to None and computed here)
  • mask2 (torch.tensor) – precomputed mask of the elements of that are 2 (Defaults to None and computed here)
Returns:

values of x**k

Return type:

torch.tensor

class qmctorch.utils.InterpolateMolecularOrbitals(wf)[source]

Bases: object

Interpolation of the AO using a log grid centered on each atom.

get_mo_max_index(orb)[source]

Get the index of the highest MO to inlcude in the interpoaltion

Parameters:orb (str) – occupied or all
Raises:ValueError – if orb not valid
interpolate_mo_irreg_grid(pos, n, orb)[source]

Interpolate the mo occupied in the configs.

Parameters:
  • pos (torch.tensor) – sampling points (Nbatch, 3*Nelec)
  • n (int, optional) – Interpolation order. Defaults to 6.
Returns:

mo values Nbatch, Nelec, Nmo

Return type:

torch.tensor

interpolate_mo_reg_grid(pos, res, blength, orb)[source]

Interpolate the mo occupied in the configs.

Parameters:pos (torch.tensor) – sampling points (Nbatch, 3*Nelec)
Returns:mo values Nbatch, Nelec, Nmo
Return type:torch.tensor
class qmctorch.utils.InterpolateAtomicOrbitals(wf)[source]

Bases: object

Interpolation of the AO using a log grid centered on each atom.

get_interpolator(n=6, length=2)[source]

evaluate the interpolation function.

Parameters:
  • n (int, optional) – number of points on each log axis. Defaults to 6.
  • length (int, optional) – half length of the grid. Defaults to 2.
qmctorch.utils.btrace(M)[source]

Computes the trace of batched matrices

Parameters:M (torch.tensor) – matrices of size (Na, Nb, … Nx, N, N)
Returns:trace of matrices (Na, Nb, … Nx)
Return type:torch.tensor

Example

>>> m = torch.rand(100,5,5)
>>> tr = btrace(m)
qmctorch.utils.bdet2(M)[source]

Computes the determinant of batched 2x2 matrices

Parameters:M (torch.tensor) – input matrices
Returns:determinants of the matrices
Return type:torch.tensor
qmctorch.utils.bproj(M, P)[source]

Project batched marices using P^T M P

Parameters:
  • M (torch.tensor) – batched matrices size (…, N, M)
  • P (torch.tensor) – Porjectors size (…, N, M)
Returns:

Projected matrices

Return type:

torch.tensor

qmctorch.utils.diagonal_hessian(out, inp, return_grads=False)[source]

return the diagonal hessian of out wrt to inp

Parameters:
  • out ([type]) – [description]
  • inp ([type]) – [description]
Returns:

[description]

Return type:

[type]

qmctorch.utils.gradients(out, inp)[source]

Return the gradients of out wrt inp

Parameters:
  • out ([type]) – [description]
  • inp ([type]) – [description]