mqt.bench.output¶
Output functions for the MQT Bench module.
Module Contents¶
- class OutputFormat[source]¶
Bases:
enum.StrEnumEnumeration of supported output formats for circuit export.
- QASM2 = 'qasm2'¶
- QASM3 = 'qasm3'¶
- QPY = 'qpy'¶
- QIR = 'qir'¶
- QIR_BITCODE = 'qir-bitcode'¶
- exception MQTBenchExporterError[source]¶
Bases:
ExceptionCustom exception for errors arising during MQT Bench exporting operations.
- generate_header(fmt: OutputFormat, level: BenchmarkLevel, target: Target | None = None, *, generation_options: dict | None = None) str[source]¶
Generate a standardized header for MQT Bench outputs.
- Parameters:
fmt – The chosen output format enum member
level – The level of the circuit (e.g., “nativegates”, “mapped”)
target – The transpilation target, if any.
generation_options – Available generation and compilation settings.
- Returns:
A string containing the formatted header.
- write_circuit(qc: QuantumCircuit, destination: Path | TextIOBase | BinaryIO, level: BenchmarkLevel, fmt: OutputFormat = OutputFormat.QASM3, target: Target | None = None, *, qir_profile: Literal['base', 'adaptive'] = 'base') None[source]¶
Write a circuit to a file or stream.
Text formats include the MQT Bench header as comments. QPY stores it in circuit metadata under
mqt_bench. QIR bitcode carries the QIR metadata from MQT Core.- Parameters:
qc – The QuantumCircuit to export
destination – File path including the extension, text stream for OpenQASM or LLVM text, or binary stream for QPY or QIR bitcode.
level – The level of the circuit (e.g., BenchmarkLevel.MAPPED)
fmt – Desired output format
target – Compilation target required for native and mapped circuits.
qir_profile – Profile for QIR exports. Bind free parameters before exporting.
- Raises:
MQTBenchExporterError – On unsupported export or I/O errors.
- save_circuit(qc: QuantumCircuit, filename: str, level: BenchmarkLevel, output_format: OutputFormat = OutputFormat.QASM3, target: Target | None = None, target_directory: str = '', *, qir_profile: Literal['base', 'adaptive'] = 'base') bool[source]¶
Save a circuit using the filename extension for the selected format.
- Parameters:
qc – Circuit to export
filename – Base filename without extension
level – Level of the circuit (e.g., BenchmarkLevel.MAPPED)
output_format – One of the supported format values, as defined in OutputFormat
target – Compilation target required for native and mapped circuits.
target_directory – Output directory, created if needed.
qir_profile – QIR profile for QIR exports (default:
base).
- Returns:
True on success, or False if export fails and an error is printed to stderr.
- generate_filename(benchmark_name: str, level: BenchmarkLevel, num_qubits: int | None, target: Target | None = None, opt_level: int | None = None, generate_mirror_circuit: bool = False, *, compiler: Literal['qiskit', 'mqt'] = 'qiskit') str[source]¶
Generate a benchmark filename based on the abstraction level and context.
- Parameters:
benchmark_name – name of the quantum circuit
level – abstraction level
num_qubits – number of qubits in the benchmark circuit
target – target device (e.g., BenchmarkLevel.MAPPED)
opt_level – Qiskit optimization level for compiled circuits.
generate_mirror_circuit – Whether this is a mirror circuit.
compiler – Compiler used at compilation levels.
- Returns:
A filename without an extension, containing the benchmark name, level, size, and compilation settings. Factory options are stored in the circuit metadata and export header.