openfermion.ops.PolynomialTensor

Class for storing tensor representations of operators that correspond with multilinear polynomials in the fermionic ladder operators.

For instance, in a quadratic Hamiltonian (degree 2 polynomial) which conserves particle number, there are only terms of the form a^\dagger_p a_q, and the coefficients can be stored in an n_qubits x n_qubits matrix. Higher order terms would be described with tensors of higher dimension. Note that each tensor must have an even number of dimensions, since parity is conserved. Much of the functionality of this class is redundant with FermionOperator but enables much more efficient numerical computations in many cases, such as basis rotations.

n_body_tensors dict or None

A dictionary storing the tensors describing n-body interactions. If None, n_body_tensors are assumed to be generated on-the-fly by other data (for subclassing purposes).

n_qubits int

The number of sites on which the tensor acts.

n_body_tensors dict

A dictionary storing the tensors describing n-body interactions. The keys are tuples that indicate the type of tensor. For instance, n_body_tensors[(1, 0)] would be an (n_qubits x n_qubits) numpy array, and it could represent the coefficients of terms of the form a^\dagger_i a_j, whereas n_body_tensors[(0, 1)] would be an array of the same shape, but instead representing terms of the form a_i a^\dagger_j.

constant The value of the constant term.

Methods

projected_n_body_tensors

View source

Keep only selected elements.

Args
selection Union[int, Iterable[int]

If int, keeps terms with at most (exactly, if exact is True) that many unique indices. If iterable, keeps only terms containing (all of, if exact is True) the specified indices.

exact bool

Whether or not the selection is strict.

rotate_basis

View source

Rotate the orbital basis of the PolynomialTensor.

Args
rotation_matrix A square numpy array or matrix having dimensions of n_qubits by n_qubits. Assumed to be real and invertible.

with_function_applied_elementwise

View source

__add__

View source

__eq__

View source

Return self==value.

__getitem__

View source

Look up matrix element.

Args
args Tuples indicating which coefficient to get. For instance, my_tensor[(6, 1), (8, 1), (2, 0)] returns my_tensor.n_body_tensors[1, 1, 0][6, 8, 2]

__iter__

View source

Iterate over non-zero elements of PolynomialTensor.

__mod__

View source

__mul__

View source

__ne__

View source

Return self!=value.

__neg__

View source

__radd__

View source

__rmul__

View source

__rsub__

View source

__sub__

View source

__truediv__

View source