View source on GitHub |
FermionOperator stores a sum of products of fermionic ladder operators.
Inherits From: SymbolicOperator
openfermion.ops.FermionOperator(
term=None, coefficient=1.0
)
Used in the notebooks
Used in the guide | Used in the tutorials |
---|---|
In OpenFermion, we describe fermionic ladder operators using the shorthand: 'q^' = a^\dagger_q 'q' = a_q where {'p^', 'q'} = delta_pq
One can multiply together these fermionic ladder operators to obtain a fermionic term. For instance, '2^ 1' is a fermion term which creates at orbital 2 and destroys at orbital 1. The FermionOperator class also stores a coefficient for the term, e.g. '3.17 * 2^ 1'.
The FermionOperator class is designed (in general) to store sums of these terms. For instance, an instance of FermionOperator might represent 3.17 2^ 1 - 66.2 * 8^ 7 6^ 2 The Fermion Operator class overloads operations for manipulation of these objects by the user.
FermionOperator is a subclass of SymbolicOperator. Importantly, it has attributes set as follows::
actions = (1, 0)
action_strings = ('^', '')
action_before_index = False
different_indices_commute = False
See the documentation of SymbolicOperator for more details.
Example | |
---|---|
.. code-block:: python
ham = (FermionOperator('0^ 3', .5)
Equivalentlyham2 = FermionOperator('0^ 3', 0.5) ham2 += FermionOperator('3^ 0', 0.5) |
Note | |
---|---|
Adding FermionOperators is faster using += (as this is done by in-place addition). Specifying the coefficient during initialization is faster than multiplying a FermionOperator with a scalar. |
Methods
accumulate
@classmethod
accumulate( operators, start=None )
Sums over SymbolicOperators.
compress
compress(
abs_tol=EQ_TOLERANCE
)
Eliminates all terms with coefficients close to zero and removes small imaginary and real parts.
Args | |
---|---|
abs_tol
|
float
Absolute tolerance, must be at least 0.0 |
get_operator_groups
get_operator_groups(
num_groups
)
Gets a list of operators with a few terms.
Args | |
---|---|
num_groups
|
int
How many operators to get in the end. |
Returns | |
---|---|
operators
|
[self.__class__]
A list of operators summing up to self. |
get_operators
get_operators()
Gets a list of operators with a single term.
Returns | |
---|---|
operators
|
[self.__class__]
A generator of the operators in self. |
identity
@classmethod
identity()
Returns: multiplicative_identity (SymbolicOperator): A symbolic operator u with the property that ux = xu = x for all operators x of the same class.
induced_norm
induced_norm(
order=1
)
Compute the induced p-norm of the operator.
If we represent an operator as \(\sum_{j} w_j H_j\) where \(w_j\) are scalar coefficients then this norm is \(\left(\sum_{j} \| w_j \|^p \right)^{\frac{1}{p} }\) where \(p\) is the order of the induced norm
Args | |
---|---|
order
|
int
the order of the induced norm. |
is_normal_ordered
is_normal_ordered()
Return whether or not term is in normal order.
In our convention, normal ordering implies terms are ordered from highest tensor factor (on left) to lowest (on right). Also, ladder operators come first.
is_two_body_number_conserving
is_two_body_number_conserving(
check_spin_symmetry=False
)
Query whether operator has correct form to be from a molecule.
Require that term is particle-number conserving (same number of raising and lowering operators). Require that term has 0, 2 or 4 ladder operators. Require that term conserves spin (parity of raising operators equals parity of lowering operators).
Args | |
---|---|
check_spin_symmetry
|
bool
Whether to check if operator conserves spin. |
isclose
isclose(
other, tol=EQ_TOLERANCE
)
Check if other (SymbolicOperator) is close to self.
Comparison is done for each term individually. Return True if the difference between each term in self and other is less than EQ_TOLERANCE
Args | |
---|---|
other
|
SymbolicOperator
SymbolicOperator to compare against. |
many_body_order
many_body_order()
Compute the many-body order of a SymbolicOperator.
The many-body order of a SymbolicOperator is the maximum length of a term with nonzero coefficient.
Returns | |
---|---|
int |
zero
@classmethod
zero()
Returns: additive_identity (SymbolicOperator): A symbolic operator o with the property that o+x = x+o = x for all operators x of the same class.
__add__
__add__(
addend
)
Args: addend (SymbolicOperator): The operator to add.
Returns | |
---|---|
sum (SymbolicOperator) |
__div__
__div__(
divisor
)
For compatibility with Python 2.
__eq__
__eq__(
other
)
Approximate numerical equality (not true equality).
__iter__
__iter__()
__mul__
__mul__(
multiplier
)
Return self * multiplier for a scalar, or a SymbolicOperator.
Args | |
---|---|
multiplier
|
A scalar, or a SymbolicOperator. |
Returns | |
---|---|
product (SymbolicOperator) |
Raises | |
---|---|
TypeError
|
Invalid type cannot be multiply with SymbolicOperator. |
__ne__
__ne__(
other
)
Return self!=value.
__neg__
__neg__()
Returns: negation (SymbolicOperator)
__pow__
__pow__(
exponent
)
Exponentiate the SymbolicOperator.
Args | |
---|---|
exponent
|
int
The exponent with which to raise the operator. |
Returns | |
---|---|
exponentiated (SymbolicOperator) |
Raises | |
---|---|
ValueError
|
Can only raise SymbolicOperator to non-negative integer powers. |
__radd__
__radd__(
addend
)
Args: addend (SymbolicOperator): The operator to add.
Returns | |
---|---|
sum (SymbolicOperator) |
__rmul__
__rmul__(
multiplier
)
Return multiplier * self for a scalar.
We only define rmul for scalars because the left multiply exist for SymbolicOperator and left multiply is also queried as the default behavior.
Args | |
---|---|
multiplier
|
A scalar to multiply by. |
Returns | |
---|---|
product
|
A new instance of SymbolicOperator. |
Raises | |
---|---|
TypeError
|
Object of invalid type cannot multiply SymbolicOperator. |
__rsub__
__rsub__(
subtrahend
)
Args: subtrahend (SymbolicOperator): The operator to subtract.
Returns | |
---|---|
difference (SymbolicOperator) |
__sub__
__sub__(
subtrahend
)
Args: subtrahend (SymbolicOperator): The operator to subtract.
Returns | |
---|---|
difference (SymbolicOperator) |
__truediv__
__truediv__(
divisor
)
Return self / divisor for a scalar.
Note | |
---|---|
This is always floating point division. |
Args | |
---|---|
divisor
|
A scalar to divide by. |
Returns | |
---|---|
A new instance of SymbolicOperator. |
Raises | |
---|---|
TypeError
|
Cannot divide local operator by non-scalar type. |