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

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

BackendToQPU

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 "qasm_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.

set_backend(backend=None, token=None, ibmq_backend='ibmq_qasm_simulator')

Sets the backend that will execute circuits.

Parameters
  • backend – The Backend Qiskit object to be wrapped

  • plugins – Any plugins to be added (c.f qat.core documentation)

  • token – Qiskit IBMQ login token. If not supplied, loaded from env variable QISKIT_TOKEN. Only used if backend is None.

  • ibmq_backend – Name of the IBM Quantum Experience backend, default value is ‘ibmq_qasm_simulator’, which goes up to 32qubits

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)

Submits a Job to execute on a Qiskit backend.

Parameters

qlm_jobJob object

Returns

Result object

AsyncBackendToQPU

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 "qasm_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

set_backend(backend=None, token=None, ibmq_backend='ibmq_qasm_simulator')

Sets the backend that will execute circuits. If no backend and no token are specified, the backend will be a simulator.

Parameters
  • backend – The Backend Qiskit object to be wrapped

  • token – Qiskit IBMQ login token. If not supplied, loaded from env variable QISKIT_TOKEN. Only used if backend is None

  • ibmq_backend – Name of the IBM Quantum Experience backend, default value is ‘ibmq_qasm_simulator’, which goes up to 32qubits

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 BaseJob for the user to have information on their job execution

submit_job(qlm_job)

Submits a QLM job to be executed on the previously selected backend, if no backends are chosen an exception is raised.

Parameters

qlm_jobJob object to be executed

Returns

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

QiskitJob

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.

QPUToBackend

class qat.interop.qiskit.QPUToBackend(qpu=None, configuration=BackendConfiguration(backend_name='QiskitConnector', backend_version='0.0.1', basis_gates=['id', 'iden', 'u0', 'u1', 'u2', 'u3', 'x', 'y', 'z', 'h', 's', 'sdg', 't', 'tdg', 'rx', 'ry', 'rz', 'cx', 'cy', 'cz', 'ch', 'crz', 'cu1', 'cu3', 'swap', 'ccx', 'cswap', 'r'], conditional=True, coupling_map=None, gates=[GateConfig(FOO, [], BAR)], local=True, max_shots=4096, memory=False, n_qubits=100, open_pulse=False, simulator=True), provider=None)

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