Real Quantum Hardware Examples¶
Examples demonstrating how to use KOSMOS with real quantum hardware.
IBM Runtime¶
This example demonstrates how to run a smoke test on IBM Quantum hardware using IBM’s Runtime service via the IBMRuntimeRunner.
ibm_runtime_example.py¶
1from qiskit_ibm_runtime import QiskitRuntimeService
2
3from kosmos.circuit_runner.ibm_runtime_utils import available_backends_list, minimal_circuit
4from kosmos.circuit_runner.qiskit_runner import IBMRuntimeRunner
5
6
7def ibm_runtime_example() -> None:
8 """Run example of using IBM Runtime to execute a minimal circuit."""
9 circuit = minimal_circuit()
10
11 # Initialize the Qiskit Runtime service used to access the IBM Quantum platform
12 # See https://quantum.cloud.ibm.com/docs/de/api/qiskit-ibm-runtime/qiskit-runtime-service
13 qiskit_runtime_service = QiskitRuntimeService()
14
15 # Print available backends
16 print(available_backends_list(qiskit_runtime_service)) # noqa: T201
17
18 # Initialize the IBM Runtime runner that can be used to execute circuits
19 runner = IBMRuntimeRunner(
20 qiskit_runtime_service=qiskit_runtime_service,
21 backend_name=None, # Use the least busy backend
22 min_num_qubits=circuit.num_qubits,
23 num_shots=256,
24 )
25
26 # Run the circuit using real hardware and compute expectation values
27 expectation_values = runner.expectation_values([circuit])
28
29 print(f"Expectation value: {expectation_values[0][0]:.3f}") # noqa: T201
30
31
32if __name__ == "__main__":
33 ibm_runtime_example()