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()