qml.from_openfermion¶
- from_openfermion(openfermion_op, wires=None, tol=1e-16)[source]¶
Convert OpenFermion FermionOperator to PennyLane
FermiWord
orFermiSentence
and OpenFermion QubitOperator to PennyLaneLinearCombination
.- Parameters
openfermion_op (FermionOperator, QubitOperator) – OpenFermion operator.
wires (dict) – Custom wire mapping used to convert the external qubit operator to a PennyLane 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.tol (float) – Tolerance for discarding negligible coefficients.
- Returns
PennyLane operator.
- Return type
Union[FermiWord, FermiSentence, LinearCombination]
Example
>>> import pennylane as qml >>> from openfermion import FermionOperator, QubitOperator >>> of_op = 0.5 * FermionOperator('0^ 2') + FermionOperator('0 2^') >>> pl_op = qml.from_openfermion(of_op) >>> print(pl_op) 0.5 * a⁺(0) a(2) + 1.0 * a(0) a⁺(2)
>>> of_op = QubitOperator('X0', 1.2) + QubitOperator('Z1', 2.4) >>> pl_op = qml.from_openfermion(of_op) >>> print(pl_op) 1.2 * X(0) + 2.4 * Z(1)
code/api/pennylane.from_openfermion
Download Python script
Download Notebook
View on GitHub