Compile for a QDMI device¶
An MLIR mlir::CompilerTarget is an immutable snapshot of a circuit-model
device. It contains the device sites, topology, native operations, and available
calibration data. Compilation decomposes supported multi-qubit operations,
optimizes and maps the program, synthesizes native gates, and verifies that the
result conforms to the target.
The snapshot is independent of its originating QDMI session. It can therefore be stored, copied cheaply, and reused for multiple compilations.
Python¶
Open a configured QDMI device and snapshot it as a compiler target:
from mqt.core.mlir import CompilerTarget, OutputFormat, compile_program
target = CompilerTarget.from_device_id("mqt.sc.iqm.garnet")
compiled = compile_program(
"bell.qasm",
target=target,
output=OutputFormat.QCO_OPTIMIZED,
)
Target compilation accepts optimized QCO, QC, or QIR output and uses the
canonical QCO pipeline; it cannot be combined with a custom qco_pipeline.
The target can also be constructed directly. Omitting couplings selects
all-to-all connectivity; omitting operations means that every operation is
native:
target = CompilerTarget(3, couplings=[(0, 1), (1, 2)])
Use compile_for_target() to apply target
compilation to an existing QCO program. For pass-level benchmarking, the C++ API
exposes separate factories for pre-routing optimization, mapping, native
synthesis, and conformance verification.
Command line from a source build¶
List the stable IDs of configured QDMI devices:
mqt-cc --qdmi-list-devices
Select a device when compiling:
mqt-cc --qdmi-device=mqt.sc.iqm.garnet \
--emit=qco-optimized input.qasm
An explicit registry file can be selected before device discovery:
mqt-cc --qdmi-config=/path/to/qdmi.json \
--qdmi-device=example.device input.qasm
Target compilation produces optimized QCO, QC, or QIR. It cannot be combined
with a custom --passes pipeline because the canonical target pipeline owns the
required pass ordering.
C++ source-tree API¶
The source build provides a narrow QDMI bridge between a live QDMI device and the compiler-owned target:
#include "qdmi/Client.hpp"
#include "mlir/Compiler/QDMIAdapter.h"
#include "mlir/Compiler/Programs.h"
#include <llvm/Support/Error.h>
#include <llvm/Support/raw_ostream.h>
auto device = qdmi::Session::openDevice("mqt.sc.iqm.garnet");
auto target = mlir::compilerTargetFromDevice(device);
if (!target) {
llvm::errs() << "Failed to create compiler target: "
<< llvm::toString(target.takeError()) << '\n';
return 1;
}
auto qc = mlir::QCProgram::fromQASMFile("input.qasm");
if (!qc) {
return 1;
}
auto qco = std::move(*qc).intoQCO();
if (!qco || !qco->compileForTarget(*target)) {
return 1;
}
The adapter accepts circuit-model devices whose operations are available throughout the topology in both operand orientations. Operand-symmetric gates, such as CZ, may report each edge once. Neutral-atom zone models require a different compilation model and are rejected with a diagnostic.
The bundled Garnet and Emerald snapshots contain available T1, T2, and fidelity data. Operation durations are absent because they were unavailable. See Superconducting QDMI device for their stable IDs and QDMI device configuration for registry configuration.
If the program should use fewer physical qubits, run the mqt-qubit-reuse
pipeline before target compilation.