Qiskit interoperability

Translating quantum circuits

myQLM provides binders to translate quantum circuits from Qiskit to myQLM and vice-versa through the qiskit_to_qlm() and qlm_to_qiskit() functions:

from qat.interop.qiskit import qiskit_to_qlm

qlm_circuit = qiskit_to_qlm(your_qiskit_circuit)

Or

from qat.interop.qiskit import qlm_to_qiskit

qiskit_circuit = qlm_to_qiskit(your_qlm_circuit)

Connecting to a QPU/Backend

Qiskit Runtime QPUs can be used within myQLM by using the QiskitRuntimeQPU class. This class wraps both the “Sampler” and the “Estimator” primitives, which means that this QPU can measure either:

  • a list of qubits (i.e. sampling mode)

  • an observable (i.e. an observable)

from qat.interop.qiskit.runtime import QiskitRuntimeQPU

# Wraps Qiskit QPU within a myQLM QPU
qpu = QiskitRuntimeQPU(backend="ibmq_qasm_simulator")

# Submit a job to this QPU
result = qpu.submit(job)

By default, QiskitRuntimeQPU uses the QiskitRuntimeService with no parameter. To execute the previous code, your credentials must be stored on your computer

Saving Qiskit Runtime credentials

Function QiskitRuntimeService.save_account can be used to store credentials on your computer. Please refer to the Qiskit documentation to get more information on this function

from qiskit_ibm_runtime import QiskitRuntimeService

# Define your IBM Token
MY_IBM_TOKEN = ...

# Save your credentials
QiskitRuntimeService.save_account(channel="ibm_quantum", token=MY_IBM_TOKEN)

Warning

Qiskit Runtime is designed to replace the Backend API. Please consider using the new Qiskit Runtime API

myQLM can be used to connect to a Qiskit Backend. This module is composed of three main classes:

  • BackendToQPU: Synchronous QPU, capable of running in a Qiskit backend

    from qat.interop.qiskit import BackendToQPU
    
    # Declare your IBM token
    MY_IBM_TOKEN = "..."
    
    # Wrap a Qiskit backend in a QPU
    qpu = BackendToQPU(token=MY_IBM_TOKEN, ibmq_backend="ibmq_armonk")
    
    # Submit a job to IBMQ
    result = qpu.submit(job)
    
  • AsyncBackendToQPU: Asynchronous QPU, capable of running in a Qiskit Backend. This QPU returns instances of QiskitJob

    import time
    from qat.interop.qiskit import AsyncBackendToQPU
    
    # Declare your IBM token
    MY_IBM_TOKEN = "..."
    
    # Wrap a Qiskit backend in a QPU
    async_qpu = AsyncBackendToQPU(token=MY_IBM_TOKEN, ibmq_backend="ibmq_armonk")
    
    # Submit a job to IBMQ
    async_result = async_qpu.submit(job)
    
    # Wait for the result
    while not async_result.result():
        time.sleep(1)
    
    # Get result
    result = async_result.result()
    
  • QPUToBackend: Qiskit backend, capable of running in a QLM QPU

    from qat.qpus import PyLinalg
    from qat.interop.qiskit import QPUToBackend
    from qiskit import execute
    
    # Creates a Qiskit Backend
    qpu = PyLinalg()
    backend = QPUToBackend(qpu)
    
    # Returns a qiskit result
    qiskit_result = execute(qiskit_circuit, backend, shots=15).result()
    

Source code documentation

Circuit translation

qat.interop.qiskit.qiskit_to_qlm(qiskit_circuit, sep_measures=False, **kwargs)

Converts a Qiskit circuit into a QLM circuit.

Parameters
  • qiskit_circuit – The Qiskit circuit to convert

  • sep_measures

    Separates measures from the circuit:

    • if set to True, measures won’t be included in the resulting circuit, 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.qiskit.qlm_to_qiskit(qlm_circuit, qubits=None)

Converts a QLM circuit to a Qiskit circuit.

The supported translatable gates are: H, X, Y, Z, SWAP, I, S, S.dag(), T, T.dag(), RX, RY, RZ, H.ctrl(), CNOT, Y.ctrl(), CSIGN, RZ.ctrl(), CCNOT, SWAP.ctrl(), U, RXX, RZZ, R, MS

Parameters
  • qlm_circuit – The input QLM circuit to convert

  • qubits (list<int>, optional) – measured qubits

Returns

A QuantumCircuit Qiskit object resulting from the conversion

Using a Qiskit QPU in myQLM

myQLM-interop can use two APIs to wrap a Qiskit QPU within a myQLM QPU. These two APIs are:

  • Qiskit Runtime: the new Qiskit API, supporting both Sampling and Observable measurements

  • Qiskit Backend: the old Qiskit API. This API can be used either in:

    • Synchronous mode: The QPU waits until the result are available

    • Asynchronous mode: The QPU returns a “future”

Like the other myQLM QPUs, QiskitRuntimeQPU is synchronous: after having submitted a job to a QPU, the process waits until the result is available an returns the result. In other words, the output of method submit() is a Result

Note

Any Plugin, any BatchGenerator available in myQLM can be piped to this QPU

class qat.interop.qiskit.runtime.QiskitRuntimeQPU(backend: str, skip_transpilation: bool = False, service=None)

IBM Q-Experience QPU. This QPU uses IBM runtime to execute a quantum job. This QPU wraps both the Sampler and Estimator primitives, which means that this QPU can measure both:

  • a list of qubits (i.e. sampling mode)

  • an observable (i.e. observable mode)

Parameters
  • backend_name (str) – Name of the IBM backend used to execute submitted jobs (e.g. "ibmq_qasm_simulator")

  • skip_transpilation (bool, optional) – Skip transpilation - if set to True, Qiskit runtime will not transpile circuits, otherwise, Qiskit runtime will transpile circuits Default: False (transpilation done by Qiskit runtime)

  • service (Runtime service, optional) – Service used to connect to IBM runtime Default: QiskitRuntimeService()

submit(batch: Batch, meta_data: Optional[dict] = None) 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)

Warning

Qiskit Runtime is designed to replace the Backend API. Please consider using the new Qiskit Runtime API

Like the other myQLM QPUs, BackendToQPU is synchronous: after having submitted a job to a QPU, the process waits until the result is available an returns the result. In other words, the output of method submit() is a Result

Note

Any Plugin, any BatchGenerator available in myQLM can be piped to this QPU

class qat.interop.qiskit.BackendToQPU(backend=None, plugins=None, token=None, ibmq_backend='ibmq_qasm_simulator', optimization_level=0)

Wrapper around any Qiskit simulator / quantum chip connection. Despite the asynchronous nature of Qiskit’s backends, this class defines a synchronous QPU. If you need an asynchronous, please use AsyncBackendToQPU.

This QPU can be instantiated using:

  • a Qiskit backend: please use the keyword argument backend

  • an IBM token and the name of the backend: please the keyword arguments token and ibmq_backend (the default backend is "ibmq_qasm_simulator")

  • no argument: the "aer_simulator" is used if no argment is specified

Parameters
  • backend – The Backend Qiskit object that is supposed to execute the circuit.

  • plugins (list) – linked plugins

  • token (str) – Qiskit IBMQ login token. If not supplied, loaded from the environment variable QISKIT_TOKEN

  • ibmq_backend (str, optional) – name of the backend. Defaults to ‘ibmq_qasm_simulator’.

  • optimization_level (int, optional) – 0: No optimization (Default). 1: Light optimization. 2: Heavy optimization. 3: Highest optimization.

submit(batch: Batch, meta_data: Optional[dict] = None) 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)

Qiskit backends are asynchronous: submitting a job to a QPU returns a “future”. This “future” allow the user to download the result later, once available. In other words, the output of method submit() is a promise (i.e. a QiskitJob object in myQLM)

class qat.interop.qiskit.AsyncBackendToQPU(backend=None, token=None, ibmq_backend='ibmq_qasm_simulator')

Wrapper around any Qiskit simulator / quantum chip connection. This class defines an asynchronous QPU. If you need a synchronous QPU, please use BackendToQPU.

This asynchronous QPU can be instantiated using:

  • a Qiskit backend: please use the keyword argument backend

  • an IBM token and the name of the backend: please the keyword arguments token and ibmq_backend (the default backend is "ibmq_qasm_simulator")

  • no argument: the "aer_simulator" is used if no argment is specified

Warning

Since this QPU is asynchronous, plugins can’t be piped to this QPU

Parameters
  • backend – The Backend Qiskit object that is supposed to execute the circuit.

  • token (str) – Qiskit IBMQ login token. If not supplied, loaded from the environment variable QISKIT_TOKEN

  • ibmq_backend (str) – name of the backend. Defaults to ‘ibmq_qasm_simulator’.

retrieve_job(file_name)

Retrieves a QiskitJob from a binary file in which the QLM Batch object - from which the QiskitJob has been created - has been dumped.

Parameters

file_name – Name of the binary file

Returns

QiskitJob object

submit(qlm_batch)

Submits a QLM batch of jobs and returns the corresponding QiskitJob.

Parameters

qlm_batchBatch or Job. If a single job is provided, a batch is created from this job.

Returns

QiskitJob object with the same interface as a job derived from JobV1 for the user to have information on their job execution

class qat.interop.qiskit.QiskitJob(qlm_batch, async_job, max_shots)

Wrapper around Qiskit’s asynchronous jobs.

cancel()

Attempts to cancel the job.

Returns

Boolean indicating whether the attempt was successful or not

dump(file_name)

Dumps the Batch object used for creating the job into a binary file. This file should later be used with AsyncBackendToQPU’s retrieve_job().

Parameters

file_name – Name of the binary file to create

job_id()

Returns the job’s ID.

result()

Returns the result if available.

Returns

Result object or BatchResult object if the batch submitted contains several jobs

status()

Returns the job status.

Using a myQLM QPU in Qiskit

myQLM interop provides tools to wrap an Atos QPU inside a Qiskit Backend

Warning

myQLM QPUs could not be cast into a Qiskit QPU using the Runtime API. Please use the “backend” API to wrap a myQLM QPU inside a Qiskit backend

class qat.interop.qiskit.QPUToBackend(*args: Any, **kwargs: Any)

Basic connector implementing a Qiskit Backend, plugable on a QLM QPU.

Parameters
  • qpuQPUHandler object

  • configuration – BackendConfiguration object, leave default value for standard uses

  • provider – Provider responsible for this backend

set_qpu(qpu)

Sets the QLM QPU that this backend is supposed to use.

Parameters

qpu – QLM QPU object