qml.import_operator

import_operator(qubit_observable, format='openfermion', wires=None, tol=10000000000.0)[source]

Convert an external operator to a PennyLane operator.

The external format currently supported is openfermion.

Parameters
  • qubit_observable – external qubit operator that will be converted

  • format (str) – the format of the operator object to convert from

  • wires (Wires, list, tuple, dict) – Custom wire mapping used to convert the external qubit operator to a PennyLane operator. For types Wires/list/tuple, each item in the iterable represents a wire label for the corresponding qubit index. For type dict, only int-keyed dictionaries (for qubit-to-wire conversion) are accepted. If None, the identity map (e.g., 0->0, 1->1, ...) will be used.

  • tol (float) – Tolerance in machine epsilon 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.

Returns

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

Return type

(Hamiltonian)

Example

>>> from openfermion import QubitOperator
>>> h_of = QubitOperator('X0 X1 Y2 Y3', -0.0548) + QubitOperator('Z0 Z1', 0.14297)
>>> h_pl = import_operator(h_of, format='openfermion')
>>> print(h_pl)
(0.14297) [Z0 Z1]
+ (-0.0548) [X0 X1 Y2 Y3]

Contents

Using PennyLane

Development

API

Internals