# netket.operator.PauliStrings#

class netket.operator.PauliStrings[source]#

Bases: PauliStringsBase

A Hamiltonian consisting of the sum of products of Pauli operators.

Inheritance
__init__(hilbert, operators=None, weights=None, *, cutoff=1e-10, dtype=None)#

Constructs a new PauliStrings operator given a set of Pauli operators. This class has two possible forms for initialization: PauliStrings(hilbert, operators, ...) or PauliStrings(operators, ...). When no hilbert argument is passed, the hilbert defaults to Qubit, where the number of qubits is automatically deduced from the operators.

Parameters:
• hilbert (AbstractHilbert) â€“ A hilbert space, optional (is no AbstractHilbert is passed, default is Qubit)

• operators (list(string)) â€“ A list of Pauli operators in string format, e.g. [â€˜IXXâ€™, â€˜XZIâ€™].

• weights () â€“ A list of amplitudes of the corresponding Pauli operator.

• cutoff (float) â€“ a cutoff to remove small matrix elements (default = 1e-10)

• dtype () â€“ The datatype to use for the matrix elements. Defaults to double precision if available.

Examples

Constructs a new PauliStrings operator X_0*X_1 + 3.*Z_0*Z_1 with both construction schemes.

>>> import netket as nk
>>> operators, weights = ['XX','ZZ'], [1,3]
>>> op = nk.operator.PauliStrings(operators, weights)
>>> op.hilbert
Qubit(N=2)
>>> op.hilbert.size
2
>>> hilbert = nk.hilbert.Spin(1/2, 2)
>>> op = nk.operator.PauliStrings(hilbert, operators, weights)
>>> op.hilbert
Spin(s=1/2, N=2)

Attributes
H#

Returns the Conjugate-Transposed operator

T#

Returns the transposed operator

dtype#

The dtype of the operatorâ€™s matrix elements âŸ¨Ïƒ|OÌ‚|Ïƒâ€™âŸ©.

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#
weights#
Methods
__call__(v)#

Call self as a function.

Return type:

ndarray

Parameters:

v (ndarray) â€“

apply(v)#
Return type:

ndarray

Parameters:

v (ndarray) â€“

collect()#

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)#
Return type:

AbstractOperator

conjugate(*, concrete=False)#

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

copy(*, dtype=None, cutoff=None)#

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

Parameters:
• dtype () â€“ optional dtype

• cutoff â€“ optional override for the cutoff value

classmethod from_openfermion(hilbert, of_qubit_operator=None, *, n_qubits=None)#

Converts an openfermion QubitOperator into a netket PauliStrings.

The hilbert first argument can be dropped, see __init__ for details and default value

Parameters:
• hilbert (AbstractHilbert) â€“ hilbert of the resulting PauliStrings object

• of_qubit_operator â€“ this must be a QubitOperator object . More information about those objects can be found in OpenFermionâ€™s documentation

• n_qubits () â€“ (optional) total number of qubits in the system, default None means inferring it from the QubitOperator. Argument is ignored when hilbert is given.

Return type:

PauliStringsBase

get_conn(x)#

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.

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 (matrix) â€“ A matrix of shape (batch_size,hilbert.size) containing the batch of quantum numbers x.

• sections (array) â€“ An array of size (batch_size) useful to unflatten the output of this function. See numpy.split for the meaning of sections.

Returns:

The connected states xâ€™, flattened together in a single matrix. array: An array containing the matrix elements $$O(x,x')$$ associated to each xâ€™.

Return type:

matrix

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)

classmethod identity(hilbert, **kwargs)#
Parameters:

hilbert (AbstractHilbert) â€“

n_conn(x, out=None)#

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()#

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_jax_operator()[source]#

Returns the jax-compatible version of this operator, which is an instance of netket.operator.PauliStringsJax.

Return type:

PauliStringsJax

to_linear_operator()#
to_qobj()#

Convert the operator to a qutipâ€™s Qobj.

Returns:

A qutip.Qobj object.

to_sparse()#

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

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