Run your first Qiskit Serverless workload remotely
Package versions
The code on this page was developed using the following requirements. We recommend using these versions or newer.
qiskit[all]~=1.4.0
qiskit-ibm-runtime~=0.36.1
qiskit-ibm-catalog~=0.4
This section explores how to use qiskit-ibm-catalog to list programs available in Qiskit Serverless, pass inputs into these programs, run them remotely, check their status, and retrieve results and logs.
Be sure you have authenticated to Qiskit Serverless using your API key (see Deploy to IBM Quantum Platform for instructions).
List programs available
You can use QiskitServerless.list() to fetch a list of the available programs to run with Qiskit Serverless. This includes the previously uploaded transpile_remote_serverless.
from qiskit_ibm_catalog import QiskitServerless
serverless = QiskitServerless()
next(
program
for program in serverless.list()
if program.title == "transpile_remote_serverless"
)
QiskitFunction(transpile_remote_serverless)
Run an uploaded program and pass inputs
First, set up your inputs. Your program has three inputs: circuits, backend, and optimization_level. You can use random_circuit to create 30 random circuits:
from qiskit.circuit.random import random_circuit
qc_random = [(random_circuit(4, 4, measure=True, seed=i)) for i in range(10)]
qc_random[0].draw(output="mpl", idle_wires=False)
Next, use QiskitRuntimeService and least_busy to select a backend:
from qiskit_ibm_runtime import QiskitRuntimeService
service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)
print(backend.name)
Set your optimization level:
optimization_level = 3
Select your program with serverless.load('PROGRAM_NAME'):
transpile_remote_serverless = serverless.load("transpile_remote_serverless")
Next, pass your inputs and run it in a pythonic fashion as follows:
job = transpile_remote_serverless.run(
circuits=qc_random,
backend=backend.name,
optimization_level=optimization_level,
)
job.job_id
'118256c5-bbb0-4ea8-9e9f-51aac2220aef'
Check job status
With your Qiskit Serverless job_id, you can check the status of running jobs. This includes the following statuses:
QUEUED: The remote program is in the Qiskit Serverless queue. The queue priority is currently based on how much you've used Qiskit ServerlessINITIALIZING: The remote program is starting; this includes setting up the remote environment and installing dependenciesRUNNING: The program is running. At this stage, if you haveprint()outputs in your program, you can retrieve logs usingjob.logs()DONE: The program is complete, and you can retrieve data stored insave_result()withjob.results()
You can also set more detailed job statuses in Manage Qiskit Serverless compute and data resources.
job.status()
'QUEUED'
# This cell is hidden from users, it checks the job status
assert _ in ["QUEUED", "INITIALIZING", "RUNNING", "DONE"] # noqa: F821
Currently, the IBM Quantum workloads table only reflects Qiskit Runtime workloads. Use job.status() to see your Qiskit Serverless workload's current status.
You've successfully run your first Qiskit Serverless program!