qmctorch.utils package

Submodules

qmctorch.utils.algebra_utils module

qmctorch.utils.algebra_utils.btrace(M: torch.Tensor) torch.Tensor[source]

Computes the trace of batched matrices

Parameters:

M – matrices of size (Na, Nb, … Nx, N, N)

Returns:

trace of matrices (Na, Nb, … Nx)

qmctorch.utils.algebra_utils.bproj(M: torch.Tensor, P: torch.Tensor) torch.Tensor[source]

Project batched matrices using P^T M P

Parameters:
Returns:

Projected matrices

Return type:

torch.Tensor

qmctorch.utils.algebra_utils.bdet2(M: torch.Tensor) torch.Tensor[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.algebra_utils.double_factorial(input: List) numpy.ndarray[source]

Computes the double factorial of an array of int

Parameters:

input (List) – input numbers

Returns:

values of the double factorial

Return type:

List

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

Bases: Function

static forward(ctx, input)[source]
static backward(ctx, grad_output)[source]
using jaobi’s formula

d det(A) / d A_{ij} = adj^T(A)_{ij}

using the adjunct formula

d det(A) / d A_{ij} = ( (det(A) A^{-1})^T )_{ij}

qmctorch.utils.constants module

qmctorch.utils.hdf5_utils module

qmctorch.utils.hdf5_utils.print_insert_error(obj, obj_name)[source]
qmctorch.utils.hdf5_utils.print_insert_type_error(obj, obj_name)[source]
qmctorch.utils.hdf5_utils.print_load_error(grp)[source]
qmctorch.utils.hdf5_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.hdf5_utils.load_object(grp, parent_obj, grp_name)[source]

Load object attribute from the hdf5 group/data

Parameters:
  • architecture (grp {hdf5 group} -- the current group in the hdf5)

  • object (parent_obj {object} -- parent)

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

qmctorch.utils.hdf5_utils.load_group(grp, parent_obj, grp_name)[source]

Load object attribute from the hdf5 group

Parameters:
  • architecture (grp {hdf5 group} -- the current group in the hdf5)

  • object (parent_obj {object} -- parent)

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

qmctorch.utils.hdf5_utils.load_data(grp, parent_obj, grp_name)[source]

Load data from the hdf5 data

Parameters:
  • architecture (grp {hdf5 group} -- the current group in the hdf5)

  • object (parent_obj {object} -- parent)

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

qmctorch.utils.hdf5_utils.cast_loaded_data(data)[source]

cast the data before loading.

qmctorch.utils.hdf5_utils.bytes2str(bstr)[source]

Convert a bytes into string.

qmctorch.utils.hdf5_utils.lookup_cast(ori_type, current_type)[source]
qmctorch.utils.hdf5_utils.isgroup(grp)[source]

Check if current hdf5 group is a group

Parameters:

dataset (grp {hdf5 group} -- hdf5 group or)

Returns:

bool – True if the group is a group

qmctorch.utils.hdf5_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.hdf5_utils.insert_object(obj, parent_grp, obj_name)[source]

Insert the content of the object in the hdf5 file

Parameters:
  • save (obj {object} -- object to)

  • dump (parent_grp {hdf5 group} -- group where to)

  • object (obj_name {str} -- name of the)

qmctorch.utils.hdf5_utils.insert_group(obj, parent_grp, obj_name)[source]

Insert the content of the object in a hdf5 group

Parameters:
  • save (obj {object} -- object to)

  • dump (parent_grp {hdf5 group} -- group where to)

  • object (obj_name {str} -- name of the)

qmctorch.utils.hdf5_utils.insert_data(obj, parent_grp, obj_name)[source]

Insert the content of the object in a hdf5 dataset

Parameters:
  • save (obj {object} -- object to)

  • dump (parent_grp {hdf5 group} -- group where to)

  • object (obj_name {str} -- name of the)

qmctorch.utils.hdf5_utils.insert_type(obj, parent_grp, obj_name)[source]

Insert the content of the type object in an attribute

Parameters:
  • save (obj {object} -- object to)

  • dump (parent_grp {hdf5 group} -- group where to)

  • object (obj_name {str} -- name of the)

qmctorch.utils.hdf5_utils.insert_default(obj, parent_grp, obj_name)[source]

Default funtion to insert a dataset

Parameters:
  • save (obj {object} -- object to)

  • dump (parent_grp {hdf5 group} -- group where to)

  • object (obj_name {str} -- name of the)

qmctorch.utils.hdf5_utils.insert_list(obj, parent_grp, obj_name)[source]

funtion to insert a list as a dataset

Parameters:
  • save (obj {object} -- object to)

  • dump (parent_grp {hdf5 group} -- group where to)

  • object (obj_name {str} -- name of the)

qmctorch.utils.hdf5_utils.insert_tuple(obj, parent_grp, obj_name)[source]

funtion to insert a tuple as a dataset

Parameters:
  • save (obj {object} -- object to)

  • dump (parent_grp {hdf5 group} -- group where to)

  • object (obj_name {str} -- name of the)

qmctorch.utils.hdf5_utils.insert_numpy(obj, parent_grp, obj_name)[source]

funtion to insert a numpy array as a dataset

Parameters:
  • save (obj {object} -- object to)

  • dump (parent_grp {hdf5 group} -- group where to)

  • object (obj_name {str} -- name of the)

qmctorch.utils.hdf5_utils.insert_torch_tensor(obj, parent_grp, obj_name)[source]

funtion to insert a torch tensor as a dataset

Parameters:
  • save (obj {object} -- object to)

  • dump (parent_grp {hdf5 group} -- group where to)

  • object (obj_name {str} -- name of the)

qmctorch.utils.hdf5_utils.insert_torch_parameter(obj, parent_grp, obj_name)[source]

funtion to insert a torch parameter as a dataset

Parameters:
  • save (obj {object} -- object to)

  • dump (parent_grp {hdf5 group} -- group where to)

  • object (obj_name {str} -- name of the)

qmctorch.utils.hdf5_utils.insert_none(obj, parent_grp, obj_name)[source]

funtion to insert a None Type as a dataset

Parameters:
  • save (obj {object} -- object to)

  • dump (parent_grp {hdf5 group} -- group where to)

  • object (obj_name {str} -- name of the)

qmctorch.utils.hdf5_utils.haschildren(obj)[source]

Check if the object has children

Parameters:

check (obj {object} -- the object to)

Returns:

bool – True if the object has children

qmctorch.utils.hdf5_utils.children(obj)[source]

Returns the children of the object as items

Parameters:

check (obj {object} -- the object to)

Returns:

dict – items

qmctorch.utils.hdf5_utils.get_children_names(obj)[source]

Returns the children names of the object as items

Parameters:

check (obj {object} -- the object to)

Returns:

dict – items

qmctorch.utils.hdf5_utils.get_child_object(obj, child_name)[source]

Return the child object

Parameters:
  • object (obj {object} -- parent)

  • name (child_name {str} -- cild)

Returns:

object – child object

qmctorch.utils.hdf5_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.hdf5_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.interpolate module

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

Bases: object

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

get_mo_max_index(orb: str) int[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

Returns:

index of the highest MO to inlcude in the interpoaltion

Return type:

int

interpolate_mo_irreg_grid(pos: torch.Tensor, n: int, orb: str) torch.Tensor[source]

Interpolate the molecular orbitals occupied in the configs.

Parameters:
  • pos (torch.Tensor) – Sampling points with shape (Nbatch, 3*Nelec).

  • n (int) – Interpolation order.

  • orb (str) – Type of orbitals to interpolate, either ‘occupied’ or ‘all’.

Returns:

Interpolated molecular orbital values with shape (Nbatch, Nelec, Nmo).

Return type:

torch.Tensor

interpolate_mo_reg_grid(pos: torch.Tensor, res: int, blength: float, orb: str) torch.Tensor[source]

Interpolate the mo occupied in the configs.

Parameters:
  • pos (torch.tensor) – sampling points (Nbatch, 3*Nelec)

  • res (int) – resolution of the regular grid

  • blength (float) – border length of the regular grid

  • orb (str) – Type of orbitals to interpolate, either ‘occupied’ or ‘all’

Returns:

mo values Nbatch, Nelec, Nmo

Return type:

torch.tensor

class qmctorch.utils.interpolate.InterpolateAtomicOrbitals(wf)[source]

Bases: object

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

get_interpolator(n: int = 6, length: float = 2) None[source]

evaluate the interpolation function.

Parameters:
  • n (int, optional) – number of points on each log axis. Defaults to 6.

  • length (float, optional) – half length of the grid. Defaults to 2.

Returns:

None

qmctorch.utils.interpolate.get_boundaries(atomic_positions: torch.Tensor | numpy.ndarray | List[numpy.ndarray], border_length: float = 2.0) Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]

Computes the boundaries of the structure

Parameters:
  • atomic_positions (Union[torch.Tensor, np.ndarray, List[np.ndarray]]) – atomic positions

  • border_length (float, optional) – length of the border. Defaults to 2.

Raises:

ValueError – if type of positions not recognized

Returns:

min, max values in the 3 cartesian directions

Return type:

Tuple[np.ndarray, np.ndarray, np.ndarray]

qmctorch.utils.interpolate.get_reg_grid(atomic_positions: torch.Tensor | numpy.ndarray | list, resolution: float = 0.1, border_length: float = 2.0) Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]

Computes a regular grid points from the atomic positions

Parameters:
  • atomic_positions (Union[torch.Tensor, np.ndarray, list]) – atomic positions

  • resolution (float, optional) – distance between two points. Defaults to 0.1.

  • border_length (float, optional) – length of the border. Defaults to 2.0.

Returns:

grid points in the x, y, and z axis

Return type:

Tuple[np.ndarray, np.ndarray, np.ndarray]

qmctorch.utils.interpolate.interpolator_reg_grid(func: Callable[[numpy.ndarray], torch.Tensor], x: numpy.ndarray, y: numpy.ndarray, z: numpy.ndarray) Callable[[numpy.ndarray], numpy.ndarray][source]

Computes the interpolation function

Parameters:
  • func (Callable[[np.ndarray], torch.Tensor]) – compute the value of the function to interpolate

  • x (np.ndarray) – grid points in the x direction

  • y (np.ndarray) – grid points in the y direction

  • z (np.ndarray) – grid points in the z direction

Returns:

interpolation function

Return type:

Callable[[np.ndarray], np.ndarray]

qmctorch.utils.interpolate.interpolate_reg_grid(interpfunc: Callable[[numpy.ndarray], numpy.ndarray], pos: torch.Tensor) torch.Tensor[source]

Interpolate the function

Parameters:
  • interpfunc (callable) – function to interpolate the data points

  • pos (torch.tensor) – positions of the walkers Nbatch x 3*Nelec

Returns:

interpolated values of the function evaluated at pos

Return type:

torch.tensor

qmctorch.utils.interpolate.is_even(x: int) bool[source]

Return True if x is even.

Parameters:

x (int) – number to test

Returns:

True if x is even

Return type:

bool

qmctorch.utils.interpolate.logspace(n: int, length: float) numpy.ndarray[source]

Returns a 1d array of logspace between -length and +length.

Parameters:
  • n (int) – number of points in the array

  • length (float) – absolute value of the max distance

Returns:

1d array of length n

Return type:

np.ndarray

qmctorch.utils.interpolate.get_log_grid(atomic_positions: List | numpy.ndarray | torch.Tensor, n: int = 6, length: float = 2.0, border_length: float = 2.0) numpy.ndarray[source]

Computes a logarithmic grid

Parameters:
  • atomic_positions (list, np.ndarray, torch.tensor) – positions of the atoms

  • n (int, optional) – number of points in each axis around each atom. Defaults to 6.

  • length (float, optional) – absolute value of the max distance from the atom. Defaults to 2.

  • border_length (float, optional) – length of the border. Defaults to 2.

Returns:

grid points (Npts,3)

Return type:

np.ndarray

qmctorch.utils.interpolate.interpolator_irreg_grid(func: Callable[[numpy.ndarray], torch.Tensor], grid_pts: numpy.ndarray) Callable[source]

Compute a linear ND interpolator

Parameters:
  • func (Callable[[np.ndarray], torch.Tensor]) – Function to compute the values to interpolate.

  • grid_pts (np.ndarray) – Grid points used for interpolation.

Returns:

Interpolation function.

Return type:

Callable

qmctorch.utils.interpolate.interpolate_irreg_grid(interpfunc: Callable[[numpy.ndarray], numpy.ndarray], pos: torch.Tensor) torch.Tensor[source]

Interpolate the function

Parameters:
  • interpfunc (callable) – function to interpolate the data points

  • pos (torch.tensor) – positions of the walkers Nbatch x 3*Nelec

Returns:

interpolated values of the function evaluated at pos

Return type:

torch.tensor

qmctorch.utils.plot_data module

qmctorch.utils.plot_data.plot_energy(local_energy: numpy.ndarray, e0: float | None = None, show_variance: bool = False, clip: bool = False, q: float = 0.15) None[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.

  • clip (bool, optional) – Clip the values to remove outliers. Defaults to False.

  • q (float, optional) – Quantile used for the interquartile range. Defaults to 0.15.

qmctorch.utils.plot_data.plot_data(observable: SimpleNamespace, obsname: str) None[source]

Plot the evolution of a given data

Parameters:
  • observable (SimpleNamespace) – namespace of observable

  • obsname (str) – name (key) of the desired observable

qmctorch.utils.plot_data.plot_walkers_traj(eloc: numpy.ndarray, walkers: int | str | None = 'mean') None[source]

Plot the trajectory of all the individual walkers

Parameters:
  • eloc (np.ndarray) – Local energy array (Nstep, Nwalkers)

  • walkers (int, str, optional) – all, mean or index of a given walker Defaults to ‘mean’

Returns:

None

qmctorch.utils.plot_data.plot_correlation_coefficient(eloc: numpy.ndarray, size_max: int = 100) Tuple[numpy.ndarray, float][source]

Plot the correlation coefficient of the local energy and fit the curve to an exp to extract the correlation time.

Parameters:
  • eloc (np.ndarray) – values of the local energy (Nstep, Nwalk)

  • size_max (int, optional) – maximu number of MC step to consider. Defaults to 100.

Returns:

  • rho (np.ndarray) – correlation coefficients (size_max, Nwalkers)

  • tau_fit (float) – correlation time

qmctorch.utils.plot_data.plot_integrated_autocorrelation_time(eloc: numpy.ndarray, rho: numpy.ndarray = None, size_max: int = 100, C: int = 5) int[source]

Compute and plot the integrated autocorrelation time.

Parameters:
  • eloc (np.ndarray) – Local energy values (Nstep, Nwalkers).

  • rho (np.ndarray, optional) – Correlation coefficient. Defaults to None.

  • size_max (int, optional) – Maximum number of MC steps to consider. Defaults to 100.

  • C (int, optional) – A constant used for thresholding. Defaults to 5.

Returns:

Index where the mean integrated autocorrelation time meets the condition.

Return type:

int

qmctorch.utils.plot_data.plot_blocking_energy(eloc: numpy.ndarray, block_size: int, walkers: str = 'mean') numpy.ndarray[source]

Plot the blocked energy values

Parameters:
  • eloc (np.ndarray) – values of the local energies

  • block_size (int) – size of the block

  • walkers (str, optional) – which walkers to plot (mean, all, index or list). Defaults to ‘mean’.

Returns:

blocked energy values

Return type:

np.ndarray

Raises:

ValueError – [description]

qmctorch.utils.plot_data.plot_correlation_time(eloc: numpy.ndarray) None[source]

Plot the blocking thingy

Parameters:

eloc (np.ndarray) – values of the local energy

qmctorch.utils.plot_data.plot_block(eloc: numpy.ndarray) None[source]

Plot the standard error of the blocked energies.

Parameters:

eloc (np.ndarray) – Values of the local energy.

Returns:

None

qmctorch.utils.provenance module

qmctorch.utils.provenance.get_git_tag() str[source]

Retrieves the current Git tag for the repository.

This function determines the directory of the current file, then executes a Git command to describe the current commit with the most recent tag.

Returns:

The Git tag string representing the current state of the repository.

Return type:

str

qmctorch.utils.stat_utils module

qmctorch.utils.stat_utils.blocking(x: numpy.ndarray, block_size: int, expand: bool = False) numpy.ndarray[source]

block the data

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

  • block_size (int) – size of the block

  • expand (bool, optional) – expand the blocked data to the original size.

Returns:

blocked data

Return type:

np.ndarray

qmctorch.utils.stat_utils.correlation_coefficient(x: numpy.ndarray, norm: bool = True) numpy.ndarray[source]

Computes the correlation coefficient using the FFT

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

  • norm (bool, optional) – If True, normalizes the correlation coefficients. Defaults to True.

Returns:

The computed correlation coefficients.

Return type:

np.ndarray

qmctorch.utils.stat_utils.integrated_autocorrelation_time(correlation_coeff: numpy.ndarray, size_max: int) numpy.ndarray[source]

Computes the integrated autocorrelation time

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

  • size_max (int) – max size

Returns:

The computed integrated autocorrelation time

Return type:

np.ndarray

qmctorch.utils.stat_utils.fit_correlation_coefficient(coeff: numpy.ndarray) Tuple[float, numpy.ndarray][source]
Fit the correlation coefficient

to get the correlation time.

Parameters:

coeff (np.ndarray) – correlation coefficient

Returns:

correlation time np.ndarray: fitted curve

Return type:

float

qmctorch.utils.torch_utils module

qmctorch.utils.torch_utils.set_torch_double_precision() None[source]

Set the default precision to double for all torch tensors.

qmctorch.utils.torch_utils.set_torch_single_precision() None[source]

Set the default precision to single for all torch tensors.

qmctorch.utils.torch_utils.fast_power(x: torch.Tensor, k: torch.Tensor, mask0: torch.Tensor | None = None, mask2: torch.Tensor | None = None) torch.Tensor[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

qmctorch.utils.torch_utils.gradients(out: torch.Tensor, inp: torch.Tensor) torch.Tensor[source]

Return the gradients of out wrt inp

Parameters:
Returns:

Gradient of out wrt inp

Return type:

torch.Tensor

qmctorch.utils.torch_utils.hessian(out: torch.Tensor, inp: torch.Tensor) Tuple[torch.Tensor, torch.Tensor][source]

Compute the Hessian and the gradient of out wrt inp.

Parameters:
Returns:

The Hessian and the gradient.

Return type:

Tuple[torch.Tensor, torch.Tensor]

qmctorch.utils.torch_utils.diagonal_hessian(out: torch.Tensor, inp: torch.Tensor) torch.Tensor[source]

Return the diagonal Hessian of out with respect to inp.

Parameters:
  • out (torch.Tensor) – The output tensor.

  • inp (torch.Tensor) – The input tensor.

  • return_grads (bool, optional) – Whether to return gradients. Defaults to False.

Returns:

Diagonal elements of the Hessian. torch.Tensor (optional): Gradients of out with respect to inp if return_grads is True.

Return type:

torch.Tensor

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

Bases: Dataset

Creates a torch data set

Parameters:

data (torch.Tensor) – data

class qmctorch.utils.torch_utils.DataLoader(data: torch.Tensor, batch_size: int, pin_memory: bool = False)[source]

Bases: object

Simple DataLoader to replace torch 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.

Module contents

Utils module API.

qmctorch.utils.set_torch_double_precision() None[source]

Set the default precision to double for all torch tensors.

qmctorch.utils.set_torch_single_precision() None[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 (torch.Tensor) – data

class qmctorch.utils.DataLoader(data: torch.Tensor, batch_size: int, pin_memory: bool = False)[source]

Bases: object

Simple DataLoader to replace torch 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: torch.Tensor, k: torch.Tensor, mask0: torch.Tensor | None = None, mask2: torch.Tensor | None = None) torch.Tensor[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: str) int[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

Returns:

index of the highest MO to inlcude in the interpoaltion

Return type:

int

interpolate_mo_irreg_grid(pos: torch.Tensor, n: int, orb: str) torch.Tensor[source]

Interpolate the molecular orbitals occupied in the configs.

Parameters:
  • pos (torch.Tensor) – Sampling points with shape (Nbatch, 3*Nelec).

  • n (int) – Interpolation order.

  • orb (str) – Type of orbitals to interpolate, either ‘occupied’ or ‘all’.

Returns:

Interpolated molecular orbital values with shape (Nbatch, Nelec, Nmo).

Return type:

torch.Tensor

interpolate_mo_reg_grid(pos: torch.Tensor, res: int, blength: float, orb: str) torch.Tensor[source]

Interpolate the mo occupied in the configs.

Parameters:
  • pos (torch.tensor) – sampling points (Nbatch, 3*Nelec)

  • res (int) – resolution of the regular grid

  • blength (float) – border length of the regular grid

  • orb (str) – Type of orbitals to interpolate, either ‘occupied’ or ‘all’

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: int = 6, length: float = 2) None[source]

evaluate the interpolation function.

Parameters:
  • n (int, optional) – number of points on each log axis. Defaults to 6.

  • length (float, optional) – half length of the grid. Defaults to 2.

Returns:

None

qmctorch.utils.btrace(M: torch.Tensor) torch.Tensor[source]

Computes the trace of batched matrices

Parameters:

M – matrices of size (Na, Nb, … Nx, N, N)

Returns:

trace of matrices (Na, Nb, … Nx)

qmctorch.utils.bdet2(M: torch.Tensor) torch.Tensor[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: torch.Tensor, P: torch.Tensor) torch.Tensor[source]

Project batched matrices using P^T M P

Parameters:
Returns:

Projected matrices

Return type:

torch.Tensor

qmctorch.utils.diagonal_hessian(out: torch.Tensor, inp: torch.Tensor) torch.Tensor[source]

Return the diagonal Hessian of out with respect to inp.

Parameters:
  • out (torch.Tensor) – The output tensor.

  • inp (torch.Tensor) – The input tensor.

  • return_grads (bool, optional) – Whether to return gradients. Defaults to False.

Returns:

Diagonal elements of the Hessian. torch.Tensor (optional): Gradients of out with respect to inp if return_grads is True.

Return type:

torch.Tensor

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

Return the gradients of out wrt inp

Parameters:
Returns:

Gradient of out wrt inp

Return type:

torch.Tensor

qmctorch.utils.hessian(out: torch.Tensor, inp: torch.Tensor) Tuple[torch.Tensor, torch.Tensor][source]

Compute the Hessian and the gradient of out wrt inp.

Parameters:
Returns:

The Hessian and the gradient.

Return type:

Tuple[torch.Tensor, torch.Tensor]

qmctorch.utils.blocking(x: numpy.ndarray, block_size: int, expand: bool = False) numpy.ndarray[source]

block the data

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

  • block_size (int) – size of the block

  • expand (bool, optional) – expand the blocked data to the original size.

Returns:

blocked data

Return type:

np.ndarray

qmctorch.utils.correlation_coefficient(x: numpy.ndarray, norm: bool = True) numpy.ndarray[source]

Computes the correlation coefficient using the FFT

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

  • norm (bool, optional) – If True, normalizes the correlation coefficients. Defaults to True.

Returns:

The computed correlation coefficients.

Return type:

np.ndarray

qmctorch.utils.integrated_autocorrelation_time(correlation_coeff: numpy.ndarray, size_max: int) numpy.ndarray[source]

Computes the integrated autocorrelation time

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

  • size_max (int) – max size

Returns:

The computed integrated autocorrelation time

Return type:

np.ndarray

qmctorch.utils.get_git_tag() str[source]

Retrieves the current Git tag for the repository.

This function determines the directory of the current file, then executes a Git command to describe the current commit with the most recent tag.

Returns:

The Git tag string representing the current state of the repository.

Return type:

str