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)

Or

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   = "127.0.0.1"
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

Parameters
  • 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

Returns

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

Parameters

qlm_circuit – QLM circuit to convert

Returns

Pyquil circuit

PyquilQPU

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

Parameters
  • 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

set_qpu(qpu)

Update the pyquil QPU.

Parameters

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.

Parameters

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.

Returns

a batch result

Return type

(BatchResult)

submit_job(qlm_job)

Execute a myQLM jobs

Parameters

qlm_job (Job) – job to execute

Returns

result of the execution

Return type

Result