quantax.operator.Operator#

class quantax.operator.Operator#

Quantum operator

__init__(op_list: list[OpTerm])#
Parameters:

op_list –

The operator represented as a list of OpTerm. Each OpTerm groups all terms that share the same operator string opstr together with their strengths and site indices:

opstr:

a string representing the operator type. The convention is chosen the same as pauli=0 in QuSpin

strength:

a list of interaction strengths, one per term

indices:

a list of site-index tuples, one per term, each matching the length of opstr

__matmul__(other: Operator) Operator#
__matmul__(other: State) DenseState

Apply the operator on a ket state by H @ state to get \(H \left| \psi \right>\), or multiply two operators by H1 @ H2. The exact expectation value \(\left<\psi|H|\psi \right>\) can be computed by state @ H @ state.

__rmatmul__(state: State) DenseState#

Apply the operator on a bra state by state @ H to get \(\left< \psi \right| H\). The exact expectation value \(\left<\psi|H|\psi \right>\) can be computed by state @ H @ state.

__add__(other: float | Operator) Operator#

Add two operators.

__iadd__(other: Operator) Operator#

In-place addition of two operators.

__sub__(other: float | Operator) Operator#

Subtract two operators.

__isub__(other: float | Operator) Operator#

In-place subtraction of two operators.

__mul__(other: Array | ndarray | bool | number | bool | int | float | complex) Operator#

Multiply an operator with a scalar.

__rmul__(other: Array | ndarray | bool | number | bool | int | float | complex) Operator#

Multiply an operator with a scalar.

__imul__(other: Array | ndarray | bool | number | bool | int | float | complex) Operator#

In-place multiplication of an operator with a scalar.

__neg__() Operator#

Negate an operator.

__truediv__(other: float) Operator#

Divide an operator by a scalar.

__itruediv__(other: float) Operator#

In-place division of an operator by a scalar.

property op_list: list[OpTerm]#

Operator represented as a list in the QuSpin format

property quspin_static_list: list#

The operator in the QuSpin static-list format [[opstr, [[strength, *site_indices], ...]], ...].

property jax_op_list: list[tuple[dict[str, Any], tuple[OpTermJAX, ...]]]#

Operator list with jax arrays, made easy for applying operator to basis states.

The format is [(update_mode1, op_terms1), (update_mode2, op_terms2), ...], where each update_mode is a dictionary produced by the update-mode filter and each op_terms is a tuple of OpTermJAX holding the jax-array strengths and indices of the terms in that update mode.

property expression: str#

The operator as a human-readable expression

apply_update_mode_filter(update_mode_filter: Callable[[str, Sequence[int]], dict[str, Any]]) None#

Apply a filter function to update the operator’s jax_op_list with additional update_mode information for each operator term.

Parameters:

update_mode_filter – A function that takes an operator string and its corresponding site indices, and returns a dictionary of update_mode.

get_quspin_op(symm: Symmetry | None = None) quspin.operators.hamiltonian#

Obtain the corresponding QuSpin operator

Parameters:

symm – The symmetry used for generate the operator basis, by default the basis without symmetry

todense(symm: Symmetry | None = None) ndarray#

Obtain the dense matrix representing the operator

Parameters:

symm – The symmetry used for generate the operator basis, by default the basis without symmetry

diagonalize(symm: Symmetry | None = None, k: int | Literal['full'] = 1) tuple[NDArray, NDArray]#

Diagonalize the hamiltonian \(H = V D V^†\)

Parameters:
  • symm – Symmetry for generating basis.

  • k – A number specifying how many lowest states to obtain, or β€œfull” for all eigenstates.

Returns:

w:

Array of k eigenvalues.

v:

An array of k eigenvectors. v[:, i] is the eigenvector corresponding to the eigenvalue w[i].

property H: Operator#

Hermitian conjugate

apply_diag(s: Array) Array#

Apply the diagonal part of the operator to a batch of configurations s, returning the diagonal matrix elements \(\left< s|O|s \right>\).

apply_off_diag(s: Array) list[tuple[dict[str, Any], Array, Array]]#

Apply the off-diagonal part of the operator to a batch of configurations s.

Returns:

A list of (update_mode, s_conn, strength) grouped by update mode, where s_conn are the connected configurations \(s'\) and strength the corresponding matrix elements \(\left< s'|O|s \right>\).

Oloc(state: State, samples: Samples | NDArray[integer] | Array) Array#

Computes the local operator \(O_\mathrm{loc}(s) = \sum_{s'} \frac{\psi_{s'}}{\psi_s} \left< s|O|s' \right>\)

Parameters:
  • state – A quantax.state.State for computing \(\psi\)

  • samples – A batch of samples \(s\)

Returns:

A 1D jax array \(O_\mathrm{loc}(s)\)

expectation(state: State, samples: Samples | Array, return_var: Literal[False] = False) complex#
expectation(state: State, samples: Samples | Array, return_var: Literal[True]) tuple[complex, float]

The expectation value of the operator

Parameters:
  • state – The state for computing \(\psi\) in \(O_\mathrm{loc}\)

  • samples – The samples for estimating \(\left< O_\mathrm{loc} \right>\)

  • return_var – Whether the variance should also be returned, default to False

Returns:

Omean:

Mean value of the operator \(\left< O_\mathrm{loc} \right>\)

Ovar:

Variance of the operator \(\left< |O_\mathrm{loc}|^2 \right> - |\left< O_\mathrm{loc} \right>|^2\), only returned when return_var = True