View source on GitHub |
Class for storing tensor representations of operators that correspond with multilinear polynomials in the fermionic ladder operators.
openfermion.ops.PolynomialTensor(
n_body_tensors
)
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.
Methods
projected_n_body_tensors
projected_n_body_tensors(
selection, exact=False
)
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
rotate_basis(
rotation_matrix
)
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
with_function_applied_elementwise(
func
)
__add__
__add__(
addend
)
__eq__
__eq__(
other
)
Return self==value.
__getitem__
__getitem__(
args
)
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__
__iter__()
Iterate over non-zero elements of PolynomialTensor.
__mod__
__mod__(
other
)
__mul__
__mul__(
multiplier
)
__ne__
__ne__(
other
)
Return self!=value.
__neg__
__neg__()
__radd__
__radd__(
addend
)
__rmul__
__rmul__(
multiplier
)
__rsub__
__rsub__(
subtrahend
)
__sub__
__sub__(
subtrahend
)
__truediv__
__truediv__(
dividend
)