qmctorch.utils package

Submodules

Module contents

Utils module API.

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|.

class qmctorch.utils.DataLoader(data, batch_size, pin_memory=False)[source]

Bases: object

Simple DataLoader to replace toch data loader

Parameters:
  • data (torch.tensor) – data to load [Nbatch,Nelec*3]

  • batch_size (int) – size of the minibatch

  • pin_memory (bool, optional) – copy the data to pinned memory. Defaults to False.

qmctorch.utils.add_group_attr(filename, grp_name, attr)[source]

Add attribute to a given group

Parameters:
  • file (filename {str} -- name of the) –

  • group (grp_name {str} -- name of the) –

  • add (attr {dict} -- attrivutes to) –

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]

qmctorch.utils.blocking(x, block_size, expand=False)[source]

block the data

Parameters:
  • x (data) – size Nsample, Nexp

  • block_size (int) – size of the block

qmctorch.utils.correlation_coefficient(x, norm=True)[source]

Computes the correlation coefficient using the FFT

Parameters:
  • x (np.ndarray) – measurement of size [MC steps, N walkers]

  • norm (bool, optional) – [description]. Defaults to True.

qmctorch.utils.integrated_autocorrelation_time(correlation_coeff, size_max)[source]

Computes the integrated autocorrelation time

Parameters:
  • correlation_coeff (np.ndarray) – coeff size Nsample,Nexp

  • size_max (int) – max size