netket.experimental.operator.ParticleNumberAndSpinConservingFermioperator2nd

Contents

netket.experimental.operator.ParticleNumberAndSpinConservingFermioperator2nd#

class netket.experimental.operator.ParticleNumberAndSpinConservingFermioperator2nd[source]#

Bases: DiscreteJaxOperator

Particle-number conserving and spin-Z-conserving fermionc operator

\[\hat H = w + \sum_{ij \sigma} w_{ij \sigma} \hat c_{i \sigma}^\dagger \hat c_{j \sigma} + \sum_{ijkl\sigma \rho} w_{ijkl\sigma\rho} \hat c_{i\sigma}^\dagger \hat c_{j \rho}^\dagger \hat c_{k \rho} \hat c_{l \sigma}\]

Limited to 2-body operators if acting on > 1 sector at a time

To be used with netket.hilbert.SpinOrbitalFermions with a fixed number of fermions.

It uses a custom sparse internal representation, please refer to the docstrings of prepare_data and prepare_data_diagonal for details.

We provide several factory methods to create this operator:

  • ParticleNumberAndSpinConservingFermioperator2nd.from_fermionoperator2nd:

    Conversion form FermionOperator2nd/FermionOperator2ndJax (if possible)

  • ParticleNumberConservingFermioperator2nd.from_pyscf_molecule:

    From pyscf

Furthermore it can be converted to FermionOperator2nd/FermionOperator2ndJax using the .to_fermiop method.

Inheritance
Inheritance diagram of netket.experimental.operator.ParticleNumberAndSpinConservingFermioperator2nd
Attributes
H#

Returns the Conjugate-Transposed operator

T#

Returns the transposed operator

dtype#
hilbert#

The hilbert space associated to this observable.

is_hermitian#
max_conn_size#
Methods
__call__(v)[source]#

Call self as a function.

Return type:

ndarray

Parameters:

v (ndarray)

apply(v)[source]#
Return type:

ndarray

Parameters:

v (ndarray)

collect()[source]#

Returns a guaranteed concrete instance of an operator.

As some operations on operators return lazy wrappers (such as transpose, hermitian conjugate…), this is used to obtain a guaranteed non-lazy operator.

Return type:

AbstractOperator

conj(*, concrete=False)[source]#
Return type:

AbstractOperator

conjugate(*, concrete=False)[source]#

Returns the complex-conjugate of this operator.

Parameters:

concrete – if True returns a concrete operator and not a lazy wrapper

Return type:

AbstractOperator

Returns:

if concrete is not True, self or a lazy wrapper; the complex-conjugated operator otherwise

classmethod from_fermionoperator2nd(ha, cutoff=1e-11)[source]#

Convert from FermionOperator2nd

Parameters:
  • ha (FermionOperator2ndJax) – the original FermionOperator2nd/FermionOperator2ndJax operator

  • cutoff (float) – cutoff to use when converting the operators to the internal format. Use a small but nonzero number, to allow for internal equality checks between arrays.

Throws an error if the original operator is not particle-number conserving, or spin-Z-conserving.

classmethod from_pyscf_molecule(mol, mo_coeff, cutoff=1e-11)[source]#

Constructs the operator from a pyscf molecule

Parameters:
  • mol (pyscf.gto.mole.Mole) – pyscf molecule

  • mo_coeff (Union[ndarray, Array]) – molecular orbital coefficients, e.g. obtained from a HF calculation

  • cutoff (float) – cutoff to use when converting the operators to the internal format. Use a small but nonzero number, to allow for internal equality checks between arrays.

get_conn(x)[source]#

Finds the connected elements of the Operator. Starting from a given quantum number x, it finds all other quantum numbers x’ such that the matrix element \(O(x,x')\) is different from zero. In general there will be several different connected states x’ satisfying this condition, and they are denoted here \(x'(k)\), for \(k=0,1...N_{\mathrm{connected}}\).

Parameters:

x (ndarray) – An array of shape (hilbert.size, ) containing the quantum numbers x.

Returns:

The connected states x’ of shape (N_connected,hilbert.size) array: An array containing the matrix elements \(O(x,x')\) associated to each x’.

Return type:

matrix

Raises:

ValueError – If the given quantum number is not compatible with the hilbert space.

get_conn_flattened(x, sections, pad=False)[source]#

Finds the connected elements of the Operator.

Starting from a given quantum number \(x\), it finds all other quantum numbers \(x'\) such that the matrix element \(O(x,x')\) is different from zero. In general there will be several different connected states \(x'\) satisfying this condition, and they are denoted here \(x'(k)\), for \(k=0,1...N_{\mathrm{connected}}\).

This is a batched version, where x is a matrix of shape (batch_size,hilbert.size).

Parameters:
  • x (ndarray) – A matrix of shape (batch_size, hilbert.size) containing the batch of quantum numbers x.

  • sections (ndarray) – An array of sections for the flattened x’. See numpy.split for the meaning of sections.

  • pad (bool)

Returns:

The connected states x’, flattened together in

a single matrix. An array containing the matrix elements \(O(x,x')\) associated to each x’.

Return type:

(matrix, array)

get_conn_padded(x)[source]#

Finds the connected elements of the Operator. This method can be executed inside of a Jax function transformation.

Starting from a batch of quantum numbers \(x={x_1, ... x_n}\) of size \(B \times M\) where \(B\) size of the batch and \(M\) size of the hilbert space, finds all states \(y_i^1, ..., y_i^K\) connected to every \(x_i\).

Returns a matrix of size \(B \times K_{max} \times M\) where \(K_{max}\) is the maximum number of connections for every \(y_i\).

Parameters:

x – A N-tensor of shape \((...,hilbert.size)\) containing the batch/batches of quantum numbers \(x\).

Returns:

The connected states x’, in a N+1-tensor and an N-tensor containing the matrix elements \(O(x,x')\) associated to each x’ for every batch.

Return type:

(x_primes, mels)

n_conn(x, out=None)[source]#

Return the number of (non-zero) connected entries to x.

Warning

This is not the True number of connected entries, because some elements might appear twice (however this should not be too common.)

Note that this deviates from the Numba implementation, and can generally return a smaller number of connected entries.

Parameters:
  • x (matrix) – A matrix of shape (batch_size,hilbert.size) containing the batch of quantum numbers x.

  • out (array) – If None an output array is allocated.

Returns:

The number of connected states x’ for each x[i].

Return type:

array

replace(**updates)[source]#

Returns a new object replacing the specified fields with new values.

to_dense()[source]#

Returns the dense matrix representation of the operator. Note that, in general, the size of the matrix is exponential in the number of quantum numbers, and this operation should thus only be performed for low-dimensional Hilbert spaces or sufficiently sparse operators.

This method requires an indexable Hilbert space.

Return type:

Array

Returns:

The dense matrix representation of the operator as a jax Array.

to_jax_operator()[source]#

Return the JAX version of this operator.

If this is a JAX operator does nothing.

Return type:

DiscreteJaxOperator

to_linear_operator()[source]#
to_qobj()[source]#

Convert the operator to a qutip’s Qobj.

Returns:

A qutip.Qobj object.

to_sparse(jax_=False)[source]#

Returns the sparse matrix representation of the operator. Note that, in general, the size of the matrix is exponential in the number of quantum numbers, and this operation should thus only be performed for low-dimensional Hilbert spaces or sufficiently sparse operators.

This method requires an indexable Hilbert space.

Parameters:
  • jax – If True, returns an experimental Jax sparse matrix. If False, returns a normal scipy CSR matrix. False by default.

  • jax_ (bool)

Return type:

JAXSparse

Returns:

The sparse jax matrix representation of the operator.

transpose(*, concrete=False)[source]#

Returns the transpose of this operator.

Parameters:

concrete – if True returns a concrete operator and not a lazy wrapper

Return type:

AbstractOperator

Returns:

if concrete is not True, self or a lazy wrapper; the transposed operator otherwise