ffsim.FermionOperator¶
- class ffsim.FermionOperator(coeffs)¶
Bases:
objectA 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, notop * 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.
Return whether the operator conserves particle number.
Return whether the operator conserves the Z component of spin.
copy()items()keys()Return the many-body order of the operator.
Return the normal ordered form of the operator.
simplify([tol])Remove terms with small coefficients in place.
values()- adjoint()¶
Return the adjoint (Hermitian conjugate) of the operator.
- Returns:
The adjoint of the fermion operator.
- Return type:
- conserves_particle_number()¶
Return whether the operator conserves particle number.
- Returns:
True if the operator conserves particle number, False otherwise.
- Return type:
- conserves_spin_z()¶
Return whether the operator conserves the Z component of spin.
- Returns:
True if the operator conserves the Z component of spin, False otherwise.
- Return type:
- copy()¶
- items()¶
- keys()¶
- many_body_order()¶
Return the many-body order of the operator.
The many-body order is defined as the length of the longest term contained in the operator.
- Returns:
The many-body order of the operator.
- Return type:
- normal_ordered()¶
Return the normal ordered form of the operator.
The normal ordered form of an operator is an equivalent operator in which each term has been reordered into a canonical ordering. In each term of a normal-ordered fermion operator, the operators comprising the term appear from left to right in descending lexicographic order by (action, spin, orb). That is, all creation operators appear before all annihilation operators; within creation/annihilation operators, spin beta operators appear before spin alpha operators, and larger orbital indices appear before smaller orbital indices.
- Returns:
The normal-ordered fermion operator.
- Return type:
- simplify(tol=1e-12)¶
Remove terms with small coefficients in place.
Removes terms with coefficients whose absolute value is below the specified tolerance. Modifies the operator in place.
- Parameters:
tol (float) – The tolerance threshold. Terms with coefficients whose absolute value is less than or equal to this value will be removed.
Example
>>> op = FermionOperator({ ... (cre_a(0), des_a(1)): 1.0, ... (cre_b(2), des_b(3)): 1e-10 ... }) >>> op.simplify() >>> print(op) FermionOperator({ (cre_a(0), des_a(1)): 1 })
- values()¶