qml.qchem.to_openfermion

to_openfermion(pennylane_op, wires=None, tol=1e-16)[source]

Convert a PennyLane operator to OpenFermion QubitOperator or FermionOperator.

Parameters
  • pennylane_op (Sum, LinearCombination, FermiWord, FermiSentence) – PennyLane operator

  • wires (dict) – Custom wire mapping used to convert a PennyLane qubit operator to the external operator. Only dictionaries with integer keys (for qubit-to-wire conversion) are accepted. If None, the identity map (e.g., 0->0, 1->1, ...) will be used.

Returns

OpenFermion operator

Return type

(QubitOperator, FermionOperator)

Example

>>> import pennylane as qml
>>> w1 = qml.fermi.FermiWord({(0, 0) : '+', (1, 1) : '-'})
>>> w2 = qml.fermi.FermiWord({(0, 1) : '+', (1, 2) : '-'})
>>> fermi_s = qml.fermi.FermiSentence({w1 : 1.2, w2: 3.1})
>>> of_fermi_op = qml.to_openfermion(fermi_s)
>>> of_fermi_op
1.2 [0^ 1] +
3.1 [1^ 2]
>>> sum_op = 1.2 * qml.X(0) + 2.4 * qml.Z(1)
>>> of_qubit_op = qml.to_openfermion(sum_op)
>>> of_qubit_op
(1.2+0j) [X0] +
(2.4+0j) [Z1]