netket.operator._local_operator.LocalOperatorBase#

class netket.operator._local_operator.LocalOperatorBase[source]#

Bases: DiscreteOperator

Base implementation of an operator composed of a sum of local terms, each of which acts on a small number of sites.

Warning

The complexity of the constructor of this operator scales exponentially with the number of sites on which each term acts, and linearly with the number of terms.

The memory requirement scales the same, because this operator stores internally a lookup table as large as the local hilbert space size of each term.

Refrain from using this for terms acting on more than 6-sites. For Spin-1/2 systems, prefer instead netket.operator.PauliStrings. For non spin-1/2 there is nothing that will work efficiently out of the box, but you can easily roll your own.

The runtime complexity is proportional to the number of connected entries max_conn_size

Inheritance
Inheritance diagram of netket.operator._local_operator.LocalOperatorBase
__init__(hilbert, operators=[], acting_on=[], constant=0, dtype=None, *, mel_cutoff=1e-10)[source]#

Constructs a new LocalOperator given a hilbert space and (if specified) a constant level shift.

Parameters:
  • hilbert (AbstractHilbert) – Hilbert space the operator acts on.

  • operators (Union[list[Union[ndarray, Array]], ndarray, Array]) – A list of operators, in matrix form. Supports numpy dense or scipy

  • format (sparse)

  • acting_on (list[int] | list[list[int]]) – A list of list of sites, which the corresponding operators act on. This should be constructed such that operators[i] acts on the sites acting_on[i]. If operators is not a list of operators, acting_on should just be the list of corresponding sites.

  • constant (SupportsComplex | SupportsFloat) – Constant diagonal shift of the operator, equivalent to \(+\text{c}\hat{I}\). Default is 0.0.

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

  • mel_cutoff (float) – a cutoff to remove small matrix elements (default = 1e-10)

Examples

Constructs a LocalOperator without any operators.

>>> from netket.hilbert import Spin
>>> from netket.operator import LocalOperator
>>> hi = Spin(0.5)**20
>>> empty_hat = LocalOperator(hi)
>>> print(len(empty_hat.acting_on))
0
Attributes
H#

Returns the Conjugate-Transposed operator

T#

Returns the transposed operator

acting_on#

List containing the list of the sites on which every operator acts.

Every operator self.operators[i] acts on the sites self.acting_on[i]

constant#

A constant multiplying the identity added to the diagonal of the operator.

dtype#

DType of the matrix elements of this operator.

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.

mel_cutoff#

The cutoff for matrix elements. Only matrix elements such that abs(O(i,i))>mel_cutoff are considered

Type:

float

n_operators#

The total number of operators that were summed upon to build this operator.

This excludes an optional identity term that is tracked by netket.operator.LocalOperator.constant.

operators#

List of the matrices of the operators encoded in this Local Operator. Returns a copy.

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]#

LocalOperator: Returns the complex conjugate of this operator.

copy(*, dtype=None, _cls=None)[source]#

Returns a copy of the operator, while optionally changing the dtype of the operator.

Parameters:

dtype (Union[None, str, type[Any], dtype, _SupportsDType]) – optional dtype

Internal args:

_cls: used to specify the target class

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) – If True, the output x’ is padded to the maximum number of connected states. If False, the output x’ is not padded and the number of connected states is given by the sections array. (Defaults: False)

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.

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 (ndarray) – 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 states connected to x.

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

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:

ndarray

Returns:

The dense matrix representation of the operator as a Numpy array.

to_linear_operator()[source]#
to_pauli_strings(**kwargs)[source]#

Convert to PauliStrings object

Return type:

PauliStringsJax

to_qobj()[source]#

Convert the operator to a qutip’s Qobj.

Returns:

A qutip.Qobj object.

to_sparse()[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.

Return type:

csr_matrix

Returns:

The sparse matrix representation of the operator.

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

LocalOperator: Returns the transpose of this operator.