Python Package¶
The Python package for this project is published on PyPI as iqm-qdmi.
It provides a Python entry point for discovering installation paths that are useful
when integrating the IQM QDMI Device into downstream build systems.
Install From PyPI¶
Use uv (or your Python package manager of choice) to install the package:
uv pip install iqm-qdmi
Quick Usage¶
The package itself makes the following variables available for import:
__version__: installed package version.IQM_QDMI_INCLUDE_DIR: include directory for C/C++ headers.IQM_QDMI_CMAKE_DIR: CMake package directory forfind_packageintegration.IQM_QDMI_LIBRARY_PATH: full path to the shared library.
1from iqm.qdmi import __version__, IQM_QDMI_INCLUDE_DIR, IQM_QDMI_CMAKE_DIR, IQM_QDMI_LIBRARY_PATH
2
3print(f"QDMI on IQM version: {__version__}")
4print(f"Include directory: {IQM_QDMI_INCLUDE_DIR}")
5print(f"CMake directory: {IQM_QDMI_CMAKE_DIR}")
6print(f"Library path: {IQM_QDMI_LIBRARY_PATH}")
QDMI on IQM version: 1.0.1
Include directory: /home/runner/work/QDMI-on-IQM/QDMI-on-IQM/.nox/docs/lib/python3.12/site-packages/iqm/qdmi/data/include
CMake directory: /home/runner/work/QDMI-on-IQM/QDMI-on-IQM/.nox/docs/lib/python3.12/site-packages/iqm/qdmi/data/share/cmake
Library path: /home/runner/work/QDMI-on-IQM/QDMI-on-IQM/.nox/docs/lib/python3.12/site-packages/iqm/qdmi/data/lib/libiqm-qdmi-device.so
Command Line Interface¶
The above values can also be conveniently queried from the command line via the iqm-qdmi entry point.
1!iqm-qdmi --help
usage: iqm-qdmi [-h] [--version | --include_dir | --cmake_dir | --lib_path]
Command line interface for the QDMI on IQM library.
options:
-h, --help show this help message and exit
--version show program's version number and exit
--include_dir Print the path to the iqm-qdmi C/C++ include directory
--cmake_dir Print the path to the iqm-qdmi CMake module directory
--lib_path Print the path to the iqm-qdmi shared library
1!iqm-qdmi --version
1.0.1
1!iqm-qdmi --include_dir
/home/runner/work/QDMI-on-IQM/QDMI-on-IQM/.nox/docs/lib/python3.12/site-packages/iqm/qdmi/data/include
1!iqm-qdmi --cmake_dir
/home/runner/work/QDMI-on-IQM/QDMI-on-IQM/.nox/docs/lib/python3.12/site-packages/iqm/qdmi/data/share/cmake
1!iqm-qdmi --lib_path
/home/runner/work/QDMI-on-IQM/QDMI-on-IQM/.nox/docs/lib/python3.12/site-packages/iqm/qdmi/data/lib/libiqm-qdmi-device.so
Qiskit Integration¶
The package includes a wrapper for the IQM QDMI Device library that integrates it with Qiskit.
This wrapper is implemented in the iqm.qdmi.qiskit submodule and is based on the open-source, MIT-licensed MQT Core library.
To use the wrapper, make sure to install the iqm-qdmi package with the qiskit extra:
uv pip install iqm-qdmi[qiskit]
Then, the IQMBackend class can be imported from iqm.qdmi.qiskit and used as a drop-in replacement for any Qiskit backend.
1from iqm.qdmi.qiskit import IQMBackend
2from qiskit.circuit import QuantumCircuit
3from qiskit.compiler import transpile
4
5backend = IQMBackend(
6 base_url="https://resonance.iqm.tech",
7 qc_alias="emerald:mock",
8)
1qc = QuantumCircuit(2)
2qc.h(0)
3qc.cx(0, 1)
4qc.measure_all()
5
6transpiled_qc = transpile(qc, backend)
7result = backend.run(transpiled_qc, shots=128).result()
8print(result.get_counts())
{'00': 61, '11': 67}
If no API token is explicitly provided, like in the example above, the wrapper will attempt to read it from the IQM_TOKEN or RESONANCE_API_KEY environment variables.
Sampler and Estimator Primitives¶
IQMBackend provides small helpers (see sampler() and estimator()) for constructing BaseSamplerV2 and BaseEstimatorV2 primitives bound
to the backend instance.
1sampler_job = backend.sampler().run([(transpiled_qc,)], shots=128)
2counts = sampler_job.result()[0].data["meas"].get_counts()
3print(f"Counts: {counts}")
Counts: {'00': 50, '11': 78}
1from qiskit.quantum_info import SparsePauliOp
2
3transpiled_qc.remove_final_measurements(inplace=True)
4observable = SparsePauliOp("Z" * backend.num_qubits)
5
6estimator_job = backend.estimator().run([(transpiled_qc, observable)])
7data = estimator_job.result()[0].data
8print(f"Expectation values: {data['evs']}")
9print(f"Standard deviations: {data['stds']}")
Expectation values: -0.03515625
Standard deviations: 0.03123068212420757