qml.qchem._terms_to_qubit_operator

_terms_to_qubit_operator(coeffs, ops, wires=None)[source]

Converts a 2-tuple of complex coefficients and PennyLane operations to OpenFermion QubitOperator.

This function is the inverse of _qubit_operator_to_terms.

Parameters
  • coeffs (array[complex]) – coefficients for each observable, same length as ops

  • ops (Iterable[pennylane.operation.Observable]) – List of PennyLane observables as Tensor products of Pauli observables

  • wires (Wires, list, tuple, dict) – Custom wire mapping used to convert to qubit operator from 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 consecutive-int-valued dict (for wire-to-qubit conversion) is accepted. If None, will map sorted wires from all ops to consecutive int.

Returns

an instance of OpenFermion’s QubitOperator.

Return type

QubitOperator

Example

>>> coeffs = np.array([0.1, 0.2])
>>> ops = [
...     qml.operation.Tensor(qml.PauliX(wires=['w0'])),
...     qml.operation.Tensor(qml.PauliY(wires=['w0']), qml.PauliZ(wires=['w2']))
... ]
>>> _terms_to_qubit_operator(coeffs, ops, wires=Wires(['w0', 'w1', 'w2']))
0.1 [X0] +
0.2 [Y0 Z2]