qml.qchem._qubit_operator_to_terms

_qubit_operator_to_terms(qubit_operator, wires=None)[source]

Converts OpenFermion QubitOperator to a 2-tuple of coefficients and PennyLane Pauli observables.

Parameters
  • qubit_operator (QubitOperator) – Fermionic-to-qubit transformed operator in terms of Pauli matrices

  • 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, …).

Returns

coefficients and their corresponding PennyLane observables in the Pauli basis

Return type

tuple[array[float], Iterable[pennylane.operation.Observable]]

Example

>>> q_op = 0.1*QubitOperator('X0') + 0.2*QubitOperator('Y0 Z2')
>>> q_op
0.1 [X0] +
0.2 [Y0 Z2]
>>> _qubit_operator_to_terms(q_op, wires=['w0','w1','w2','extra_wire'])
(array([0.1, 0.2]), [PauliX(wires=['w0']), PauliY(wires=['w0']) @ PauliZ(wires=['w2'])])