uniqc.compile.compiler module¶
Enhanced transpiler with chip-characterization-aware routing.
This module provides the canonical compile() entry point for chip-aware
circuit transpilation in UnifiedQuantum. It wraps the existing Qiskit-based
transpiler and adds fidelity-weighted routing, multiple output formats, and a
typed configuration object.
- class uniqc.compile.compiler.CompilationResult(output, fidelity_estimate, routing_overhead, transpiler_messages=<factory>)[source]¶
Bases:
objectResult of a
compile()call.- Variables:
output (Circuit | str) – Compiled circuit. Type depends on
output_formatpassed tocompile().fidelity_estimate (float | None) – Estimated success probability of the compiled circuit on the target chip, computed from per-gate fidelities in the chip characterization.
Noneif no chip_characterization was provided.routing_overhead (int) – Number of SWAP gates inserted by the router. Zero if the circuit already fits the topology.
transpiler_messages (list[str]) – Informational messages from the transpiler.
- Parameters:
- class uniqc.compile.compiler.TranspilerConfig(type='qiskit', level=2, basis_gates=('cz', 'sx', 'rz'), chip_characterization=None)[source]¶
Bases:
objectConfiguration for the
compile()function.- Parameters:
type (str) – Transpiler backend. Currently only
"qiskit"is supported. The string is kept for future extensibility.level (int) – Qiskit optimization level (0–3). Default: 2. 0 = no optimization, 1 = light, 2 = heavy, 3 = heaviest.
basis_gates (tuple[str, ...]) – Target basis gate set. Default:
("cz", "sx", "rz").chip_characterization (ChipCharacterization | None) – Per-qubit and per-pair calibration data. When provided, the router prefers higher-fidelity qubits and edges during SWAP insertion and qubit routing. If
None, routing uses only the connectivity graph.
- uniqc.compile.compiler.compile(circuit, backend_info=None, *, type='qiskit', level=2, basis_gates=None, chip_characterization=None, output_format='circuit', available_qubits=None)[source]¶
Compile a circuit for a specific backend using chip characterization data.
This is the canonical entry point for chip-aware transpilation in UnifiedQuantum. It supersedes
transpile_originirby adding chip-characterization-aware routing, a typed configuration object, and a Circuit return type.Important
compile(at every optimizationlevel, includinglevel=0) requires Qiskit, which is a core dependency installed by default withunified-quantum. Ifimport qiskitfails, the install is broken — reinstall withpip install --upgrade unified-quantum. Withoutqiskitavailable every call raisesCompilationFailedError. There is currently no pure-Python fallback path.- Parameters:
circuit (Any) – The input circuit. Accepts a
uniqc.Circuit, an OriginIR string, an OpenQASM 2.0 string, or aqiskit.QuantumCircuit.backend_info (BackendInfo | None) – Target backend descriptor. Supplies the topology coupling map. If omitted, the topology is taken from
chip_characterization.type (str) – Transpiler backend. Currently only
"qiskit"is supported.level (int) – Qiskit optimization level (0–3). Default: 2.
basis_gates (list[str] | None) – Target basis gate set. Default:
["cz", "sx", "rz"].chip_characterization (ChipCharacterization | None) – Per-qubit and per-pair calibration data. When provided, the router prefers high-fidelity qubits and edges during SWAP insertion. If
None, routing uses only the connectivity graph.output_format (OutputFormat) – Return format.
"circuit"(default) returns a newCircuitobject;"originir"returns an OriginIR string;"qasm"returns a QASM2 string;"auto"matches the detected input format.
- Returns:
The compiled circuit in the requested format.
- Return type:
- Raises:
CompilationFailedError – If transpilation fails.
ValueError – If the transpiler type is unsupported, the optimization level is out of range, or no topology information is available.
TypeError – If the input type is not recognized.
Example
>>> from uniqc.circuit_builder import Circuit >>> from uniqc.compile import compile >>> circuit = Circuit() >>> circuit.h(0); circuit.cnot(0, 1) >>> compiled = compile(circuit, level=2) >>> print(type(compiled).__name__) Circuit
- uniqc.compile.compiler.compile_full(circuit, backend_info=None, *, type='qiskit', level=2, basis_gates=None, chip_characterization=None, output_format='circuit', available_qubits=None)[source]¶
Full compile returning a
CompilationResultwith metadata.Equivalent to
compile()but also returns routing overhead, fidelity estimate, and informational messages.- Parameters:
circuit (Any) – The input circuit. Accepts a
uniqc.Circuit, an OriginIR string, an OpenQASM 2.0 string, or aqiskit.QuantumCircuit.backend_info (BackendInfo | None) – Target backend descriptor.
type (str)
level (int)
chip_characterization (ChipCharacterization | None)
output_format (OutputFormat)
- Return type:
:param : :param available_qubits: Same as
compile().- Returns:
The compiled output plus metadata.
- Return type:
- Parameters:
- uniqc.compile.compiler.compile_with_config(circuit, backend_info, config, output_format, *, available_qubits=None)[source]¶
Internal compile implementation that accepts a
TranspilerConfig.- Parameters:
circuit (Any)
backend_info (BackendInfo | None)
config (TranspilerConfig)
output_format (OutputFormat)
- Return type: