ffsim.FermionOperator

class ffsim.FermionOperator(coeffs)

Bases: object

A fermionic operator.

A FermionOperator represents a linear combination of products of fermionic creation and annihilation operators. Initialize a FermionOperator by passing a dictionary mapping the terms in the linear combination to their associated coefficients. FermionOperators Can be added, subtracted, and multiplied, and they support multiplication and division by scalars. When multiplying by a scalar, the scalar should go on the left side of the multiplication operator, e.g. scalar * op, not op * scalar.

See The FermionOperator class for an explanation of how to use this class.

Example:

# Note: Since FermionOperator is an unordered mapping, the order of
# the terms in the print outputs below may vary between runs.

import ffsim

op1 = ffsim.FermionOperator(
    {
        (ffsim.cre_a(0), ffsim.des_a(3)): 0.5,
        (ffsim.cre_a(3), ffsim.des_a(0)): -0.25,
        (ffsim.cre_b(1), ffsim.des_b(5), ffsim.cre_a(4)): 1 + 1j,
    }
)
print(2 * op1)
# prints
# FermionOperator({
#     (cre_b(1), des_b(5), cre_a(4)): 2+2j,
#     (cre_a(3), des_a(0)): -0.5,
#     (cre_a(0), des_a(3)): 1
# })

op2 = ffsim.FermionOperator(
    {
        (ffsim.cre_b(2),): 1j,
        (ffsim.des_a(3), ffsim.des_b(3)): -0.25,
    }
)
print(op1 + op2)
# prints
# FermionOperator({
#     (cre_a(3), des_a(0)): -0.25,
#     (cre_b(2)): 0+1j,
#     (des_a(3), des_b(3)): -0.25,
#     (cre_b(1), des_b(5), cre_a(4)): 1+1j,
#     (cre_a(0), des_a(3)): 0.5
# })

print(op1 * op2)
# prints
# FermionOperator({
#     (cre_b(1), des_b(5), cre_a(4), cre_b(2)): -1+1j,
#     (cre_a(0), des_a(3), des_a(3), des_b(3)): -0.125,
#     (cre_a(3), des_a(0), des_a(3), des_b(3)): 0.0625,
#     (cre_b(1), des_b(5), cre_a(4), des_a(3), des_b(3)): -0.25-0.25j,
#     (cre_a(0), des_a(3), cre_b(2)): 0+0.5j,
#     (cre_a(3), des_a(0), cre_b(2)): 0-0.25j
# })
Parameters:

coeffs (dict[tuple[tuple[bool, bool, int], ...], complex]) – The coefficients of the operator.

Methods

adjoint()

Return the adjoint (Hermitian conjugate) of the operator.

conserves_particle_number()

Return whether the operator conserves particle number.

conserves_spin_z()

Return whether the operator conserves the Z component of spin.

copy()

items()

keys()

many_body_order()

Return the many-body order of the operator.

normal_ordered()

Return the normal ordered form of the operator.

simplify([tol])

Remove terms with small coefficients in place.

values()