qmctorch.wavefunction package
Subpackages
- qmctorch.wavefunction.jastrows package
- Subpackages
- Submodules
- qmctorch.wavefunction.jastrows.combine_jastrow module
- qmctorch.wavefunction.jastrows.jastrow_factor_combined_terms module
- Module contents
- qmctorch.wavefunction.orbitals package
- Subpackages
- Submodules
- qmctorch.wavefunction.orbitals.atomic_orbitals module
- qmctorch.wavefunction.orbitals.atomic_orbitals_backflow module
- qmctorch.wavefunction.orbitals.molecular_orbitals module
- qmctorch.wavefunction.orbitals.norm_orbital module
- qmctorch.wavefunction.orbitals.radial_functions module
- qmctorch.wavefunction.orbitals.spherical_harmonics module
- Module contents
- qmctorch.wavefunction.pooling package
- Submodules
- qmctorch.wavefunction.pooling.orbital_configurations module
- qmctorch.wavefunction.pooling.orbital_projector module
- qmctorch.wavefunction.pooling.slater_pooling module
SlaterPoolingSlaterPooling.forward()SlaterPooling.get_slater_matrices()SlaterPooling.det_explicit()SlaterPooling.det_single_double()SlaterPooling.det_ground_state()SlaterPooling.det_unique_single_double()SlaterPooling.operator()SlaterPooling.operator_ground_state()SlaterPooling.operator_explicit()SlaterPooling.operator_single_double()SlaterPooling.operator_unique_single_double()SlaterPooling.op_single()SlaterPooling.op_multiexcitation()SlaterPooling.op_squared_single()SlaterPooling.op_squared_multiexcitation()SlaterPooling.compute_inverse_occupied_mo_matrix()
- Module contents
Submodules
qmctorch.wavefunction.slater_jastrow module
- class qmctorch.wavefunction.slater_jastrow.SlaterJastrow(*args: Any, **kwargs: Any)[source]
Bases:
WaveFunctionSlater Jastrow wave function with electron-electron Jastrow factor
\[\Psi(R_{at}, r) = J(r)\sum_n c_n D^\uparrow_n(r^\uparrow)D^\downarrow_n(r^\downarrow)\]with
\[J(r) = \exp\left( K_{ee}(r) \right)\]with K, a kernel function depending only on the electron-eletron distances
- Parameters:
mol (Molecule) – a QMCTorch molecule object
jastrow (str, optional) – Class that computes the jastrow kernels. Defaults to ‘default’.
backflow (BackFlowKernelBase, optional) – kernel function of the backflow transformation. Defaults to None.
configs (str, optional) – defines the CI configurations to be used. Defaults to ‘ground_state’. - ground_state : only the ground state determinant in the wave function - single(n,m) : only single excitation with n electrons and m orbitals - single_double(n,m) : single and double excitation with n electrons and m orbitals - cas(n, m) : all possible configuration using n eletrons and m orbitals
kinetic (str, optional) – method to compute the kinetic energy. Defaults to ‘jacobi’. - jacobi : use the Jacobi formula to compute the kinetic energy - auto : use automatic differentiation to compute the kinetic energy
cuda (bool, optional) – turns GPU ON/OFF Defaults to False..
include_all_mo (bool, optional) – include either all molecular orbitals or only the ones that are popualted in the configs. Defaults to False
orthogonalize_mo (bool, optional) – orthogonalize the molecular orbitals. Defaults to False
- Examples::
>>> from qmctorch.scf import Molecule >>> from qmctorch.wavefunction import SlaterJastrow >>> mol = Molecule('h2o.xyz', calculator='adf', basis = 'dzp') >>> wf = SlaterJastrow(mol, configs='cas(2,2)')
- init_atomic_orb(backflow: BackFlowTransformation | None) None[source]
Initialize the atomic orbital layer.
- init_molecular_orb(include_all_mo, mix_mo, orthogonalize_mo)[source]
initialize the molecular orbital layers
- init_config(configs: str) None[source]
Initialize the electronic configurations desired in the wave function.
- init_jastrow(jastrow: str | torch.nn.Module | None) None[source]
Init the jastrow factor calculator
- set_combined_jastrow(jastrow: torch.nn.Module)[source]
Initialize the jastrow factor as a sum of jastrows
- init_kinetic(kinetic: str, backflow: BackFlowTransformation | None) None[source]
“Init the calculator of the kinetic energies
- forward(x: torch.Tensor, ao: torch.Tensor | None = None) torch.Tensor[source]
computes the value of the wave function for the sampling points
\[\Psi(R) = J(R) \sum_{n} c_n D^{u}_n(r^u) \times D^{d}_n(r^d)\]- Parameters:
x (torch.tensor) – sampling points (Nbatch, 3*Nelec)
ao (torch.tensor, optional) – values of the atomic orbitals (Nbatch, Nelec, Nao)
- Returns:
values of the wave functions at each sampling point (Nbatch, 1)
- Return type:
torch.tensor
- Examples::
>>> mol = Molecule('h2.xyz', calculator='adf', basis = 'dzp') >>> wf = SlaterJastrow(mol, configs='cas(2,2)') >>> pos = torch.rand(500,6) >>> vals = wf(pos)
- ao2mo(ao: torch.Tensor) torch.Tensor[source]
transforms AO values in to MO values.
- pos2mo(x: torch.Tensor, derivative: int | None = 0, sum_grad: bool | None = True) torch.Tensor[source]
Compute the MO vals from the pos
- kinetic_energy_jacobi(x: torch.Tensor, **kwargs) torch.Tensor[source]
Compute the value of the kinetic enery using the Jacobi Formula. C. Filippi, Simple Formalism for Efficient Derivatives .
\[\frac{\Delta \Psi(R)}{\Psi(R)} = \Psi(R)^{-1} \sum_n c_n (\frac{\Delta D_n^u}{D_n^u} + \frac{\Delta D_n^d}{D_n^d}) D_n^u D_n^d\]We compute the laplacian of the determinants through the Jacobi formula
\[\frac{\Delta \det(A)}{\det(A)} = Tr(A^{-1} \Delta A)\]Here \(A = J(R) \phi\) and therefore :
\[\Delta A = (\Delta J) D + 2 \nabla J \nabla D + (\Delta D) J\]- Parameters:
x (torch.tensor) – sampling points (Nbatch, 3*Nelec)
- Returns:
values of the kinetic energy at each sampling points
- Return type:
torch.tensor
- gradients_jacobi(x: torch.Tensor, sum_grad: bool | None = False, pdf: bool | None = False) torch.Tensor[source]
Compute the gradients of the wave function (or density) using the Jacobi Formula C. Filippi, Simple Formalism for Efficient Derivatives.
\[\frac{K(R)}{\Psi(R)} = Tr(A^{-1} B_{grad})\]The gradients of the wave function
\[\Psi(R) = J(R) \sum_n c_n D^{u}_n D^{d}_n = J(R) \Sigma\]are computed following
\[\nabla \Psi(R) = \left( \nabla J(R) \right) \Sigma + J(R) \left(\nabla \Sigma \right)\]with
\[\nabla \Sigma = \sum_n c_n (\frac{\nabla D^u_n}{D^u_n} + \frac{\nabla D^d_n}{D^d_n}) D^u_n D^d_n\]that we compute with the Jacobi formula as:
\[\nabla \Sigma = \sum_n c_n (Tr( (D^u_n)^{-1} \nabla D^u_n) + Tr( (D^d_n)^{-1} \nabla D^d_n)) D^u_n D^d_n\]- Parameters:
x (torch.tensor) – sampling points (Nbatch, 3*Nelec)
pdf (bool, optional) – if true compute the grads of the density
- Returns:
values of the gradients wrt the walker pos at each sampling points
- Return type:
torch.tensor
- get_kinetic_operator(x: torch.Tensor, ao: torch.Tensor, dao: torch.Tensor, d2ao: torch.Tensor, mo: torch.Tensor) torch.Tensor[source]
Compute the Bkin matrix
- Parameters:
x (torch.tensor) – sampling points (Nbatch, 3*Nelec)
mo (torch.tensor, optional) – precomputed values of the MOs
- Returns:
matrix of the kinetic operator
- Return type:
torch.tensor
- kinetic_energy_jacobi_backflow(x: torch.Tensor, **kwargs) torch.Tensor[source]
Compute the value of the kinetic enery using the Jacobi Formula.
\[\frac{\Delta (J(R) \Psi(R))}{ J(R) \Psi(R)} = \frac{\Delta J(R)}{J(R} + 2 \frac{\nabla J(R)}{J(R)} \frac{\nabla \Psi(R)}{\Psi(R)} + \frac{\Delta \Psi(R)}{\Psi(R)}\]The lapacian of the determinental part is computed via
\[\Delta_i \Psi(R) \sum_n c_n ( \frac{\Delta_i D_n^{u}}{D_n^{u}} + \frac{\Delta_i D_n^{d}}{D_n^{d}} + 2 \frac{\nabla_i D_n^{u}}{D_n^{u}} \frac{\nabla_i D_n^{d}}{D_n^{d}} ) D_n^{u} D_n^{d}\]Since the backflow orbitals are multi-electronic the laplacian of the determinants are obtained
\[\frac{\Delta det(A)}{det(A)} = Tr(A^{-1} \Delta A) + Tr(A^{-1} \nabla A) Tr(A^{-1} \nabla A) + Tr( (A^{-1} \nabla A) (A^{-1} \nabla A ))\]- Parameters:
x (torch.tensor) – sampling points (Nbatch, 3*Nelec)
- Returns:
values of the kinetic energy at each sampling points
- Return type:
torch.tensor
- gradients_jacobi_backflow(x: torch.Tensor, sum_grad: bool | None = True, pdf: bool | None = False)[source]
Computes the gradients of the wf using Jacobi’s Formula
- Parameters:
x ([type]) – [description]
qmctorch.wavefunction.wf_base module
- class qmctorch.wavefunction.wf_base.WaveFunction(*args: Any, **kwargs: Any)[source]
Bases:
ModuleBase class for wave functions.
- Parameters:
- Returns:
None
- forward(x: torch.Tensor)[source]
Compute the value of the wave function. for a multiple conformation of the electrons
- Parameters:
parameters – variational param of the wf
pos – position of the electrons
Returns: values of psi
- electronic_potential(pos: torch.Tensor) torch.Tensor[source]
Computes the electron-electron term
- Parameters:
x (torch.tensor) – sampling points (Nbatch, 3*Nelec)
- Returns:
values of the electon-electron energy at each sampling points
- Return type:
torch.tensor
- nuclear_potential(pos: torch.Tensor) torch.Tensor[source]
Computes the electron-nuclear term
- Parameters:
x (torch.tensor) – sampling points (Nbatch, 3*Nelec)
- Returns:
values of the electon-nuclear energy at each sampling points
- Return type:
torch.tensor
- nuclear_repulsion() torch.Tensor[source]
Computes the nuclear-nuclear repulsion term
- Returns:
values of the nuclear-nuclear energy at each sampling points
- Return type:
torch.tensor
- gradients_autograd(pos: torch.Tensor, pdf: bool | None = False) torch.Tensor[source]
Computes the gradients of the wavefunction (or density) w.r.t the values of the pos.
- Parameters:
pos (torch.tensor) – positions of the walkers
pdf (bool, optional) – if true compute the grads of the density
- Returns:
values of the gradients
- Return type:
torch.tensor
- kinetic_energy_autograd(pos: torch.Tensor) torch.Tensor[source]
Compute the kinetic energy through the 2nd derivative w.r.t the value of the pos.
Note: this could be replaced by >>> compute_batch_hessian = vmap(hessian(self.forward), argnums=0), in_dims=0) >>> batch_hess = compute_batch_hessian(pos).squeeze() >>> batch_hess = torch.diagonal(batch_hess, dim1=-2, dim2=-1).view(-1,1) >>> return 0.5 * batch_hess / self.forward(pos) However this approach seems to requires 10x more memory
- Parameters:
pos (torch.tensor) – positions of the walkers
- Returns:
values of nabla^2 * Psi
- local_energy(pos: torch.Tensor) torch.Tensor[source]
Computes the local energy
\[E = K(R) + V_{ee}(R) + V_{en}(R) + V_{nn}\]- Parameters:
pos (torch.tensor) – sampling points (Nbatch, 3*Nelec)
- Returns:
values of the local enrgies at each sampling points
- Return type:
[torch.tensor]
- Examples::
>>> mol = Molecule('h2.xyz', calculator='adf', basis = 'dzp') >>> wf = SlaterJastrow(mol, configs='cas(2,2)') >>> pos = torch.rand(500,6) >>> vals = wf.local_energy(pos)
Note
by default kinetic_energy refers to kinetic_energy_autograd users can overwrite it to poit to any other methods see kinetic_energy_jacobi in wf_orbital
- energy(pos: torch.Tensor) torch.Tensor[source]
Total energy for the sampling points.
- variance(pos: torch.Tensor) torch.Tensor[source]
Variance of the energy at the sampling points.
- sampling_error(eloc: torch.Tensor) torch.Tensor[source]
Compute the statistical uncertainty. Assuming the samples are uncorrelated.
- pdf(pos: torch.Tensor, return_grad: bool | None = False) torch.Tensor[source]
density of the wave function.
Module contents
- class qmctorch.wavefunction.WaveFunction(*args: Any, **kwargs: Any)[source]
Bases:
ModuleBase class for wave functions.
- Parameters:
- Returns:
None
- forward(x: torch.Tensor)[source]
Compute the value of the wave function. for a multiple conformation of the electrons
- Parameters:
parameters – variational param of the wf
pos – position of the electrons
Returns: values of psi
- electronic_potential(pos: torch.Tensor) torch.Tensor[source]
Computes the electron-electron term
- Parameters:
x (torch.tensor) – sampling points (Nbatch, 3*Nelec)
- Returns:
values of the electon-electron energy at each sampling points
- Return type:
torch.tensor
- nuclear_potential(pos: torch.Tensor) torch.Tensor[source]
Computes the electron-nuclear term
- Parameters:
x (torch.tensor) – sampling points (Nbatch, 3*Nelec)
- Returns:
values of the electon-nuclear energy at each sampling points
- Return type:
torch.tensor
- nuclear_repulsion() torch.Tensor[source]
Computes the nuclear-nuclear repulsion term
- Returns:
values of the nuclear-nuclear energy at each sampling points
- Return type:
torch.tensor
- gradients_autograd(pos: torch.Tensor, pdf: bool | None = False) torch.Tensor[source]
Computes the gradients of the wavefunction (or density) w.r.t the values of the pos.
- Parameters:
pos (torch.tensor) – positions of the walkers
pdf (bool, optional) – if true compute the grads of the density
- Returns:
values of the gradients
- Return type:
torch.tensor
- kinetic_energy_autograd(pos: torch.Tensor) torch.Tensor[source]
Compute the kinetic energy through the 2nd derivative w.r.t the value of the pos.
Note: this could be replaced by >>> compute_batch_hessian = vmap(hessian(self.forward), argnums=0), in_dims=0) >>> batch_hess = compute_batch_hessian(pos).squeeze() >>> batch_hess = torch.diagonal(batch_hess, dim1=-2, dim2=-1).view(-1,1) >>> return 0.5 * batch_hess / self.forward(pos) However this approach seems to requires 10x more memory
- Parameters:
pos (torch.tensor) – positions of the walkers
- Returns:
values of nabla^2 * Psi
- local_energy(pos: torch.Tensor) torch.Tensor[source]
Computes the local energy
\[E = K(R) + V_{ee}(R) + V_{en}(R) + V_{nn}\]- Parameters:
pos (torch.tensor) – sampling points (Nbatch, 3*Nelec)
- Returns:
values of the local enrgies at each sampling points
- Return type:
[torch.tensor]
- Examples::
>>> mol = Molecule('h2.xyz', calculator='adf', basis = 'dzp') >>> wf = SlaterJastrow(mol, configs='cas(2,2)') >>> pos = torch.rand(500,6) >>> vals = wf.local_energy(pos)
Note
by default kinetic_energy refers to kinetic_energy_autograd users can overwrite it to poit to any other methods see kinetic_energy_jacobi in wf_orbital
- energy(pos: torch.Tensor) torch.Tensor[source]
Total energy for the sampling points.
- variance(pos: torch.Tensor) torch.Tensor[source]
Variance of the energy at the sampling points.
- sampling_error(eloc: torch.Tensor) torch.Tensor[source]
Compute the statistical uncertainty. Assuming the samples are uncorrelated.
- pdf(pos: torch.Tensor, return_grad: bool | None = False) torch.Tensor[source]
density of the wave function.
- class qmctorch.wavefunction.SlaterJastrow(*args: Any, **kwargs: Any)[source]
Bases:
WaveFunctionSlater Jastrow wave function with electron-electron Jastrow factor
\[\Psi(R_{at}, r) = J(r)\sum_n c_n D^\uparrow_n(r^\uparrow)D^\downarrow_n(r^\downarrow)\]with
\[J(r) = \exp\left( K_{ee}(r) \right)\]with K, a kernel function depending only on the electron-eletron distances
- Parameters:
mol (Molecule) – a QMCTorch molecule object
jastrow (str, optional) – Class that computes the jastrow kernels. Defaults to ‘default’.
backflow (BackFlowKernelBase, optional) – kernel function of the backflow transformation. Defaults to None.
configs (str, optional) – defines the CI configurations to be used. Defaults to ‘ground_state’. - ground_state : only the ground state determinant in the wave function - single(n,m) : only single excitation with n electrons and m orbitals - single_double(n,m) : single and double excitation with n electrons and m orbitals - cas(n, m) : all possible configuration using n eletrons and m orbitals
kinetic (str, optional) – method to compute the kinetic energy. Defaults to ‘jacobi’. - jacobi : use the Jacobi formula to compute the kinetic energy - auto : use automatic differentiation to compute the kinetic energy
cuda (bool, optional) – turns GPU ON/OFF Defaults to False..
include_all_mo (bool, optional) – include either all molecular orbitals or only the ones that are popualted in the configs. Defaults to False
orthogonalize_mo (bool, optional) – orthogonalize the molecular orbitals. Defaults to False
- Examples::
>>> from qmctorch.scf import Molecule >>> from qmctorch.wavefunction import SlaterJastrow >>> mol = Molecule('h2o.xyz', calculator='adf', basis = 'dzp') >>> wf = SlaterJastrow(mol, configs='cas(2,2)')
- init_atomic_orb(backflow: BackFlowTransformation | None) None[source]
Initialize the atomic orbital layer.
- init_molecular_orb(include_all_mo, mix_mo, orthogonalize_mo)[source]
initialize the molecular orbital layers
- init_config(configs: str) None[source]
Initialize the electronic configurations desired in the wave function.
- init_jastrow(jastrow: str | torch.nn.Module | None) None[source]
Init the jastrow factor calculator
- set_combined_jastrow(jastrow: torch.nn.Module)[source]
Initialize the jastrow factor as a sum of jastrows
- init_kinetic(kinetic: str, backflow: BackFlowTransformation | None) None[source]
“Init the calculator of the kinetic energies
- forward(x: torch.Tensor, ao: torch.Tensor | None = None) torch.Tensor[source]
computes the value of the wave function for the sampling points
\[\Psi(R) = J(R) \sum_{n} c_n D^{u}_n(r^u) \times D^{d}_n(r^d)\]- Parameters:
x (torch.tensor) – sampling points (Nbatch, 3*Nelec)
ao (torch.tensor, optional) – values of the atomic orbitals (Nbatch, Nelec, Nao)
- Returns:
values of the wave functions at each sampling point (Nbatch, 1)
- Return type:
torch.tensor
- Examples::
>>> mol = Molecule('h2.xyz', calculator='adf', basis = 'dzp') >>> wf = SlaterJastrow(mol, configs='cas(2,2)') >>> pos = torch.rand(500,6) >>> vals = wf(pos)
- ao2mo(ao: torch.Tensor) torch.Tensor[source]
transforms AO values in to MO values.
- pos2mo(x: torch.Tensor, derivative: int | None = 0, sum_grad: bool | None = True) torch.Tensor[source]
Compute the MO vals from the pos
- kinetic_energy_jacobi(x: torch.Tensor, **kwargs) torch.Tensor[source]
Compute the value of the kinetic enery using the Jacobi Formula. C. Filippi, Simple Formalism for Efficient Derivatives .
\[\frac{\Delta \Psi(R)}{\Psi(R)} = \Psi(R)^{-1} \sum_n c_n (\frac{\Delta D_n^u}{D_n^u} + \frac{\Delta D_n^d}{D_n^d}) D_n^u D_n^d\]We compute the laplacian of the determinants through the Jacobi formula
\[\frac{\Delta \det(A)}{\det(A)} = Tr(A^{-1} \Delta A)\]Here \(A = J(R) \phi\) and therefore :
\[\Delta A = (\Delta J) D + 2 \nabla J \nabla D + (\Delta D) J\]- Parameters:
x (torch.tensor) – sampling points (Nbatch, 3*Nelec)
- Returns:
values of the kinetic energy at each sampling points
- Return type:
torch.tensor
- gradients_jacobi(x: torch.Tensor, sum_grad: bool | None = False, pdf: bool | None = False) torch.Tensor[source]
Compute the gradients of the wave function (or density) using the Jacobi Formula C. Filippi, Simple Formalism for Efficient Derivatives.
\[\frac{K(R)}{\Psi(R)} = Tr(A^{-1} B_{grad})\]The gradients of the wave function
\[\Psi(R) = J(R) \sum_n c_n D^{u}_n D^{d}_n = J(R) \Sigma\]are computed following
\[\nabla \Psi(R) = \left( \nabla J(R) \right) \Sigma + J(R) \left(\nabla \Sigma \right)\]with
\[\nabla \Sigma = \sum_n c_n (\frac{\nabla D^u_n}{D^u_n} + \frac{\nabla D^d_n}{D^d_n}) D^u_n D^d_n\]that we compute with the Jacobi formula as:
\[\nabla \Sigma = \sum_n c_n (Tr( (D^u_n)^{-1} \nabla D^u_n) + Tr( (D^d_n)^{-1} \nabla D^d_n)) D^u_n D^d_n\]- Parameters:
x (torch.tensor) – sampling points (Nbatch, 3*Nelec)
pdf (bool, optional) – if true compute the grads of the density
- Returns:
values of the gradients wrt the walker pos at each sampling points
- Return type:
torch.tensor
- get_kinetic_operator(x: torch.Tensor, ao: torch.Tensor, dao: torch.Tensor, d2ao: torch.Tensor, mo: torch.Tensor) torch.Tensor[source]
Compute the Bkin matrix
- Parameters:
x (torch.tensor) – sampling points (Nbatch, 3*Nelec)
mo (torch.tensor, optional) – precomputed values of the MOs
- Returns:
matrix of the kinetic operator
- Return type:
torch.tensor
- kinetic_energy_jacobi_backflow(x: torch.Tensor, **kwargs) torch.Tensor[source]
Compute the value of the kinetic enery using the Jacobi Formula.
\[\frac{\Delta (J(R) \Psi(R))}{ J(R) \Psi(R)} = \frac{\Delta J(R)}{J(R} + 2 \frac{\nabla J(R)}{J(R)} \frac{\nabla \Psi(R)}{\Psi(R)} + \frac{\Delta \Psi(R)}{\Psi(R)}\]The lapacian of the determinental part is computed via
\[\Delta_i \Psi(R) \sum_n c_n ( \frac{\Delta_i D_n^{u}}{D_n^{u}} + \frac{\Delta_i D_n^{d}}{D_n^{d}} + 2 \frac{\nabla_i D_n^{u}}{D_n^{u}} \frac{\nabla_i D_n^{d}}{D_n^{d}} ) D_n^{u} D_n^{d}\]Since the backflow orbitals are multi-electronic the laplacian of the determinants are obtained
\[\frac{\Delta det(A)}{det(A)} = Tr(A^{-1} \Delta A) + Tr(A^{-1} \nabla A) Tr(A^{-1} \nabla A) + Tr( (A^{-1} \nabla A) (A^{-1} \nabla A ))\]- Parameters:
x (torch.tensor) – sampling points (Nbatch, 3*Nelec)
- Returns:
values of the kinetic energy at each sampling points
- Return type:
torch.tensor
- gradients_jacobi_backflow(x: torch.Tensor, sum_grad: bool | None = True, pdf: bool | None = False)[source]
Computes the gradients of the wf using Jacobi’s Formula
- Parameters:
x ([type]) – [description]