import os
from IPython.core.display import HTML
from iqm.iqm_client import IQMClient
from iqm.pulse.playlist.visualisation.base import inspect_playlist
from iqm.qiskit_iqm import IQMProvider
from iqm.qiskit_iqm.pulse_level_utils import qiskit_to_iqm, sweep_job_to_qiskit
from qiskit import QuantumCircuit, visualization
from qiskit.compiler import transpileSubmitting Jobs with Pulse-Level Access
This guide demonstrates how to submit quantum computing jobs with pulse-level access using IQMClient. Pulse-level access is part of iqm-client since version 36.0.0, which replaces the former IQM Pulla client.
Overview
What this pulse-level access example does:
- We define quantum circuits at the gate level using Qiskit
- The circuit is transpiled and converted to pulse schedules
- Jobs are executed using
IQMClient
Requirement
This notebook requires a Python virtual environment with iqm-client and its Qiskit extra installed
iqm-client[qiskit]>=37.0.0,<38.0.0Step 1: Import Python library dependencies
Step 2: Initialize the pulse-level client
Initialize IQMClient for pulse-level execution and a Qiskit backend for transpiling the circuit.
os.environ["IQM_TOKEN"] = ""
iqm_server_url = "https://qx.vtt.fi"
device_name = "demo"
client = IQMClient.from_url(iqm_server_url, quantum_computer=device_name)
provider = IQMProvider(iqm_server_url, quantum_computer=device_name)
backend = provider.get_backend()Step 3: Define a quantum circuit
Define the quantum circuit you want to execute. In this example we create a 3-qubit GHZ state — a maximally entangled state — by applying a Hadamard gate followed by two CNOT gates. The circuit is drawn to visualise its structure before execution.
shots = 100
# Define a quantum circuit.
qc = QuantumCircuit(3, 3)
qc.h(0)
qc.cx(0, 1)
qc.cx(0, 2)
qc.measure_all()
qc.draw(output="mpl")Step 4: Transpile and optimise the circuit for the target device
The circuit must be transpiled to match the native gate set and qubit topology of the target device. Transpilation rewrites the circuit using only the gates the device supports (PRX and CZ) and inserts SWAP gates where the connectivity requires it.
qc_transpiled = transpile(qc, backend=backend, layout_method="sabre", optimization_level=3)
qc_transpiled.draw(output="mpl")Step 5: Convert to pulse schedule, inspect the playlist
qiskit_to_iqm converts the optimised Qiskit circuit into IQM circuits and returns a compiler set up with the calibration set of the backend. The compiler then produces an instruction schedule playlist, the low-level pulse waveforms that will drive the hardware. The settings object controls execution parameters such as the shot count.
circuits, compiler = qiskit_to_iqm(backend, qc_transpiled)
# Set the shot count and compile the circuit into an instruction schedule playlist.
settings = compiler.get_settings(circuits=circuits)
settings.set_shots(shots)
playlist, context = compiler.compile(circuits=circuits, settings=settings)
HTML(inspect_playlist(playlist.sweep_definition.playlist, [0]))Step 6: Submit the playlist, convert results back to Qiskit format
IQMClient.submit_playlist() sends the playlist to the device and returns a job tracker. After calling wait_for_completion(), sweep_job_to_qiskit() wraps the raw results in a standard Qiskit Result object so you can use familiar methods like get_counts() and plot_histogram().
# IQMClient.submit_playlist() returns a job tracker.
# The measurements are obtained using job.result() after job.wait_for_completion().
job = client.submit_playlist(playlist, context=context)
job.wait_for_completion()
qiskit_result = sweep_job_to_qiskit(
job,
shots=shots,
)
print(f"Raw results:\n{job.result()}\n")
print(f"Qiskit result counts:\n{qiskit_result.get_counts()}\n")
visualization.plot_histogram(qiskit_result.get_counts())