netket_foundation.operator.FermionOperator2nd

netket_foundation.operator.FermionOperator2nd#

class netket_foundation.operator.FermionOperator2nd(hilbert, terms=None, weights=None, constant=0, cutoff=1e-10, dtype=None)[source]#

A fermionic operator in \(2^{nd}\) quantization, using Numba for indexing.

Warning

This class is not a Pytree, so it cannot be used inside of jax-transformed functions like jax.grad or jax.jit.

The standard usage is to index into the operator from outside the jax function transformation and pass the results to the jax-transformed functions.

To use this operator inside of a jax function transformation, convert it to a jax operator (class:netket.operator.FermionOperator2ndJax) by using netket.operator.FermionOperator2nd.to_jax_operator().

When using native (experimental) sharding, or when working with GPUs, we reccomend using the Jax implementations of the operators for potentially better performance.

Parameters:
__init__(hilbert, terms=None, weights=None, constant=0, cutoff=1e-10, dtype=None)[source]#

Constructs a fermion operator given the single terms (set of creation/annihilation operators) in second quantization formalism.

This class can be initialized in the following form: FermionOperator2nd(hilbert, terms, weights …). The term contains pairs of (idx, dagger), where idx ∈ range(hilbert.size) (it identifies an orbital) and dagger is a True/False flag determining if the operator is a creation or destruction operator. A term of the form \(\hat{a}_1^\dagger \hat{a}_2\) would take the form ((1,1), (2,0)), where (1,1) represents \(\hat{a}_1^\dagger\) and (2,0) represents \(\hat{a}_2\). To split up per spin, use the creation and annihilation operators to build the operator.

Parameters:
  • hilbert (AbstractHilbert) – hilbert of the resulting FermionOperator2nd object

  • terms (list[str] | list[list[list[int]]]) – single term operators (see example below)

  • weights (list[float | complex] | None) – corresponding coefficients of the single term operators (defaults to a list of 1)

  • constant (Number) – constant contribution, corresponding to the identity operator * constant (default = 0)

  • cutoff (float) – threshold for the weights, if the absolute value of a weight is below the cutoff, it’s discarded.

  • dtype (Union[None, str, type[Any], dtype, _SupportsDType]) – The datatype to use for the matrix elements. Defaults to double precision if available.

Returns:

A FermionOperator2nd object.

Example

Constructs the fermionic hamiltonian in \(2^{nd}\) quantization \((0.5-0.5j)*(a_0^\dagger a_1) + (0.5+0.5j)*(a_2^\dagger a_1)\).

>>> import netket as nk
>>> terms, weights = (((0,1),(1,0)),((2,1),(1,0))), (0.5-0.5j,0.5+0.5j)
>>> hi = nk.hilbert.SpinOrbitalFermions(3)
>>> op = nk.operator.FermionOperator2nd(hi, terms, weights)
>>> op
FermionOperator2nd(hilbert=SpinOrbitalFermions(n_orbitals=3), n_operators=2, dtype=complex128)
>>> terms = ("0^ 1", "2^ 1")
>>> op = nk.operator.FermionOperator2nd(hi, terms, weights)
>>> op
FermionOperator2nd(hilbert=SpinOrbitalFermions(n_orbitals=3), n_operators=2, dtype=complex128)
>>> op.hilbert
SpinOrbitalFermions(n_orbitals=3)
>>> op.hilbert.size
3

Methods

__init__(hilbert[, terms, weights, ...])

Constructs a fermion operator given the single terms (set of creation/annihilation operators) in second quantization formalism.

apply(v)

collect()

Returns a guaranteed concrete instance of an operator.

conj(*[, concrete])

conjugate(*[, concrete])

Returns the complex conjugate of this operator.

copy(*[, dtype, cutoff])

Creates a deep copy of this operator, potentially changing the dtype of the operator and internal arrays.

from_openfermion(hilbert[, ...])

Converts an openfermion FermionOperator into a netket FermionOperator2nd.

get_conn(x)

Finds the connected elements of the Operator.

get_conn_flattened(x, sections[, pad])

Finds the connected elements of the Operator.

get_conn_padded(x)

Finds the connected elements of the Operator.

n_conn(x[, out])

Return the number of states connected to x.

operator_string()

Return a readable string describing all the operator terms

reduce([order, inplace, cutoff])

Prunes the operator by removing all terms with zero weights, grouping, and normal ordering (inplace).

to_dense()

Returns the dense matrix representation of the operator.

to_jax_operator()

Returns the jax version of this operator, which is an instance of netket.operator.FermionOperator2ndJax.

to_linear_operator()

to_normal_order()

Reoder the operators to normal order.

to_pair_order()

Reoder the operators to pair order.

to_qobj()

Convert the operator to a qutip's Qobj.

to_sparse()

Returns the sparse matrix representation of the operator.

transpose(*[, concrete])

Returns the transpose of this operator.

Attributes

H

Returns the Conjugate-Transposed operator

T

Returns the transposed operator

cutoff

Threshold for the weights, if the absolute value of a weight is below the cutoff, it's discarded.

dtype

The dtype of the operator's matrix elements ⟨σ|Ô|σ'⟩.

hilbert

The hilbert space associated to this observable.

is_hermitian

Returns true if this operator is hermitian.

max_conn_size

The maximum number of non zero ⟨x|O|x'⟩ for every x.

operators

Returns a dictionary with (term, weight) key-value pairs, with terms in tuple notation.

terms

Returns the list of all terms in the tuple notation.

weights

Returns the list of the weights correspoding to the operator terms.