qmctorch.utils package

Submodules

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(*args: Any, **kwargs: Any)[source]

Bases: Dataset

Creates a torch data set

Parameters:

data (data {torch.tensor} --) –

class qmctorch.utils.Loss(*args: Any, **kwargs: Any)[source]

Bases: Module

Defines the loss to use during the optimization

Parameters:

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

Keyword Arguments:
  • (default (method {str} -- method to use) – {‘energy’}) (energy, variance, weighted-energy, weighted-variance)

  • from (clip {bool} -- clip the values that are +/- % sigma away) – the mean (default: {False})

forward(pos, no_grad=False, deactivate_weight=False)[source]

Computes the loss

Parameters:

batch (pos {torch.tensor} -- positions of the walkers in that) –

Keyword Arguments:

loss (no_grad {bool} -- computes the gradient of the) – (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:

[description] (no_grad {bool} --) –

get_clipping_mask(local_energies)[source]

computes the clipping mask

Parameters:

energies (local_energies {torch.tensor} -- values of the local) –

get_sampling_weights(pos, deactivate_weight)[source]

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

class qmctorch.utils.OrthoReg(*args: Any, **kwargs: Any)[source]

Bases: Module

Add a penalty loss to keep the MO orthogonalized

Keyword Arguments:

(default (alpha {float} -- strength of the penaly) – {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:
  • dump (obj {object} -- object to) –

  • hdf5 (fname {str} -- name of the) –

Keyword Arguments:

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

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

Load the content of an hdf5 file in an object.

Parameters:
  • data (obj {object} -- object where to load the) –

  • file (fname {str} -- name pf the hdf5) –

  • hdf5 (obj_name {str} -- name of the root group in the) –

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:
  • attr (obj {object} -- the object where we want to add) –

  • names (attr_names {list} -- a list of attr) –

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]