convert_observable(qubit_observable, wires=None, tol=100000000.0)[source]

Converts an OpenFermion QubitOperator operator to a Pennylane VQE observable

  • qubit_observable (QubitOperator) – Observable represented as an OpenFermion QubitOperator

  • wires (Wires, list, tuple, dict) – Custom wire mapping used to convert the qubit operator to an observable terms measurable in a PennyLane ansatz. For types Wires/list/tuple, each item in the iterable represents a wire label corresponding to the qubit number equal to its index. For type dict, only int-keyed dict (for qubit-to-wire conversion) is accepted. If None, will use identity map (e.g. 0->0, 1->1, …).

  • tol (float) – Tolerance in machine epsilons for the imaginary part of the coefficients in qubit_observable. Coefficients with imaginary part less than 2.22e-16*tol are considered to be real.


Pennylane VQE observable. PennyLane Hamiltonian represents any operator expressed as linear combinations of observables, e.g., \(\sum_{k=0}^{N-1} c_k O_k\).

Return type



>>> h_of = decompose('./pyscf/sto-3g/h2')
>>> h_pl = convert_observable(h_of)
>>> print(h_pl.coeffs)
[-0.04207898  0.17771287  0.17771287 -0.24274281 -0.24274281  0.17059738
  0.04475014 -0.04475014 -0.04475014  0.04475014  0.12293305  0.16768319
  0.16768319  0.12293305  0.17627641]