Example: Using VTT QX API

This Jupyter Notebook describes how to access the VTT QX API and perform a simple request to get raw counts of a job.

import os

from iqm.qiskit_iqm import IQMProvider
from qiskit import QuantumCircuit, transpile

Submit a quantum circuit to the backend

circuit = QuantumCircuit(2, name="Bell pair circuit")
circuit.h(0)
circuit.cx(0, 1)
circuit.measure_all()
circuit.draw(output="mpl")
qx_server_url = "https://qx.vtt.fi"
device_path = "api/devices/demo"
provider = IQMProvider(os.path.join(qx_server_url, device_path))
os.environ["IQM_TOKEN"] = ""
backend = provider.get_backend()

print(f"Native operations: {backend.operation_names}")
print(f"Number of qubits: {backend.num_qubits}")
print(f"Coupling map: {backend.coupling_map}")
transpiled_circuit = transpile(circuit, backend)
job = backend.run(transpiled_circuit)
counts = job.result().get_counts()
print(counts)

Fetch counts for the submitted job via the API

import requests

job_id = job.job_id()

url = os.path.join(qx_server_url, f"api/jobs/{job_id}/counts?threshold=0.1")
iqm_token = os.environ.get("IQM_TOKEN")

headers = {"Authorization": f"Bearer {iqm_token}", "Content-Type": "application/json"}

response = requests.get(url, headers=headers)

response.raise_for_status()

print(response.json())