PyQuil interoperability

Translating quantum circuits

myQLM provides binders to translate quantum circuit from PyQuil to myQLM and vice-verse throught functions pyquil_to_qlm() and qlm_to_pyquil()

from qat.interop.pyquil import pyquil_to_qlm

qlm_circuit = pyquil_to_qlm(your_pyquil_circuit)


from qat.interop.pyquil import qlm_to_pyquil

pyquil_circuit = qlm_to_pyquil(your_qlm_circuit)

Connecting to a QPU

myQLM can be used to connect to a PyQuil QVM. This module is composed of a main class PyquilQPU used to wrap a QVM into a myQLM QPU.

In this section, we assume a QVM is running locally and that this QVM is listenning to the port 15011. The following code defines a myQLM QPU wrapping the PyQuil QVM:

from pyquil.api import QVMConnection
from qat.interop.pyquil import PyquilQPU

# Define port and ip
IP   = ""
PORT = "15011"

# Define a QPU
qvm = QVMConnection(endpoint="http://{ip}:{port}".format(ip=IP, port=PORT))
qpu = PyquilQPU(qvm)

# Submit a job to the QVM
result = qpu.submit(qlm_job)

Source code documentation

Circuit translation

qat.interop.pyquil.pyquil_to_qlm(pyquil_prog, sep_measures=False, **kwargs)

Converts a pyquil circuit into a qlm circuit

  • pyquil_prog – the pyquil circuit to convert

  • sep_measures

    Separates measures from the circuit:

    • if set to True measures won’t be included in the resulting circuits, qubits to be measured will be put in a list, the resulting measureless circuit and this list will be returned in a tuple : (resulting_circuit, list_qubits)

    • if set to False, measures will be converted normally (Default set to False)

  • kwargs – these are the options that you would use on a regular to_circ function, to generate a QLM circuit from a PyAQASM program these are added for more flexibility, for advanced users


If sep_measures is set to:

  • True: the result is a tuple composed of a Circuit and a list of qubits that should be measured

  • False: the result is a Circuit

Return type

tuple or Circuit

qat.interop.pyquil.qlm_to_pyquil(qlm_circuit, program_pragma=None)

Converts a QLM circuit to a pyquil circuit


qlm_circuit – QLM circuit to convert


Pyquil circuit


class qat.interop.pyquil.PyquilQPU(qpu=None, plugins=None, compiler=True)

QPU wrapper over pyquil, to run a QLM circuit on a pyquil simulator or rigetti’s quantum chip

  • qpu – the instance of pyquil’s simulator/connection to real quantum chip or simulator

  • plugins – plugins to use

  • compiler – if set to True(default value) the circuit will be compiled by pyquil, otherwise the user compiles the circuit manually and tells the pyquil qpu to skip compilation


Update the pyquil QPU.


qpu – Pyquil QPU

submit(batch: qat.core.wrappers.batch.Batch, meta_data: Optional[dict] = None) → qat.core.wrappers.result.BatchResult

Executes a batch of jobs and returns the corresponding list of Results.


batch (Batch) – a batch of jobs. If a single job is provided, the job is embedded into a Batch, executed, and the first result is returned.


a batch result

Return type



Execute a myQLM jobs


qlm_job (Job) – job to execute


result of the execution

Return type