Skip to main content

qirtoqasm: QIR to OpenQASM translator

Latest Version Supported Python Versions Build status codecov Documentation Status

This library translates QIR programs (the QIR Base Profile and Adaptive Profile) to Braket-compatible OpenQASM 3.0.

Why qirtoqasm?

qirtoqasm bridges the growing ecosystem of QIR-emitting quantum compilers to the OpenQASM 3 format that Amazon Braket accepts. Many quantum frontends emit QIR as their serialization format — qirtoqasm converts that QIR to a Braket-ready OpenQASM 3 program without any further rewriting required by the caller.

The implementation is a pure-Rust core with four public faces:

  • A Python package (qirtoqasm) built via PyO3 + maturin. Single one-stage public function: qirtoqasm.translate(qir_text, *, producer=None) returns Braket-compatible OpenQASM 3. Every tunable is a keyword-only kwarg, so new options can be added without breaking existing callers.
  • A Rust crate (qirtoqasm-core) exposing translate(qir_text, &TranslateOptions) plus a #[non_exhaustive] options struct with builder methods.
  • A C ABI (libqirtoqasm.{a,dylib,so}) whose qirtoqasm_translate(qir, &options, out, err) takes a versioned qirtoqasm_options_t struct (carrying its own struct_version / struct_size so fields can be appended without breaking existing callers). Pass NULL options for defaults.
  • A C++20 header (qirtoqasm/qirtoqasm.hpp) with translate(qir) and translate(qir, const Options&), designed for C++20 designated-initializer syntax.

No LLVM, llvmlite, or any Python runtime dependency — the only external dependency is the platform C runtime. The Python wheel is self-contained.

Braket-targeted by design

The output of qirtoqasm.translate can be handed directly to braket.ir.openqasm.Program — no further rewriting required. Several emit-name choices follow from this:

  • Two-qubit Ising rotations emit as xx / yy / zz (Braket aliases), not the OpenQASM stdgates.inc names rxx / ryy / rzz.
  • CNOT emits as cnot (not cx).
  • Toffoli emits as ccnot (not ccx).
  • Classical registers are declared as plain bit[N] c;, without the OpenQASM output qualifier.
  • No include "stdgates.inc"; is emitted.

Installation

pip install qirtoqasm

Python ≥ 3.11 is required. The wheel is self-contained — no Rust or LLVM is needed at install time. Wheels are published for Linux (manylinux x86_64 / aarch64 + musllinux x86_64), macOS (x86_64 + arm64), and Windows (x86_64).

Python quick start

import qirtoqasm

qasm = qirtoqasm.translate("""
    %Qubit = type opaque
    %Result = type opaque
    define void @main() #0 {
      call void @__quantum__qis__h__body(%Qubit* null)
      call void @__quantum__qis__cnot__body(%Qubit* null, %Qubit* inttoptr (i64 1 to %Qubit*))
      call void @__quantum__qis__mz__body(%Qubit* null, %Result* null)
      call void @__quantum__qis__mz__body(%Qubit* inttoptr (i64 1 to %Qubit*), %Result* inttoptr (i64 1 to %Result*))
      ret void
    }
    declare void @__quantum__qis__h__body(%Qubit*)
    declare void @__quantum__qis__cnot__body(%Qubit*, %Qubit*)
    declare void @__quantum__qis__mz__body(%Qubit*, %Result*) #1
    attributes #0 = { "entry_point" "qir_profiles"="base_profile" "requiredQubits"="2" "requiredResults"="2" }
    attributes #1 = { "irreversible" }
""")
print(qasm)

qirtoqasm.translate accepts QIR as a string. To read from a file, use the standard library:

from pathlib import Path
qasm = qirtoqasm.translate(Path("bell.ll").read_text())

Every output ends with a trailing // generated-by: {"name":"qirtoqasm",…} comment. Callers that wrap qirtoqasm inside a larger toolchain can pass an optional keyword-only producer string to surface their own tool name and version in the comment:

qasm = qirtoqasm.translate(ir_text, producer="mylib 0.1.2")
# last line: // generated-by: {"name":"qirtoqasm","version":"…","profile":"base_profile","producer":"mylib 0.1.2"}

Submitting to Amazon Braket

from pathlib import Path
from braket.devices import LocalSimulator
from braket.ir.openqasm import Program

program = Program(source=qirtoqasm.translate(Path("bell.ll").read_text()))
result = LocalSimulator().run(program, shots=1000).result()
print(result.measurement_counts)

Input format

qirtoqasm accepts QIR as LLVM textual IR (.ll text) only. LLVM bitcode (.bc) is not supported; if you have bitcode, convert it with llvm-dis first. This is deliberate: the Rust core has no LLVM link dependency, which keeps the wheel tiny (no 100+ MB LLVM payload) and keeps the build hermetic.

C++ quick start

Requires a C++20 compiler. The public surface is qirtoqasm::translate plus a small Options struct for tunables:

#include <qirtoqasm/qirtoqasm.hpp>

// Simplest: defaults.
std::string qasm = qirtoqasm::translate(qir_text);

// With options (C++20 designated initializers):
std::string qasm = qirtoqasm::translate(qir_text,
    qirtoqasm::Options{ .producer = "mylib 0.1.2" });
// throws qirtoqasm::TranslationError on failure

From CMake:

find_package(qirtoqasm REQUIRED)
target_link_libraries(my_target PRIVATE qirtoqasm::qirtoqasm)
target_compile_features(my_target PRIVATE cxx_std_20)

C quick start

For C-only consumers, the same C ABI is exposed via a header:

#include <qirtoqasm/qirtoqasm.h>

char *out = NULL, *err = NULL;

// Simplest: NULL options uses defaults.
if (qirtoqasm_translate(qir_text, NULL, &out, &err) != QIRTOQASM_OK) { /* … */ }

// With options — always call qirtoqasm_options_init first so future
// fields inherit correct defaults:
qirtoqasm_options_t opts;
qirtoqasm_options_init(&opts);
opts.producer = "mylib 0.1.2";
if (qirtoqasm_translate(qir_text, &opts, &out, &err) != QIRTOQASM_OK) { /* … */ }

qirtoqasm_free_string(out);
qirtoqasm_free_string(err);

See DEVELOPMENT.md for the native-library build workflow.

Supported QIR constructs

  • QIS gates that match the __quantum__qis__<name>__body naming convention: h, x, y, z, s, t, cnot/cx, cy, cz, swap, rx, ry, rz, ccx/ccnot, rxx, ryy, rzz, reset, measurement (mz / m / mresetz), phasedx, and the __adj adjoints for non-self-adjoint gates.
  • Mid-circuit measurement read via __quantum__qis__read_result__body(%Result*) and the alias __quantum__rt__read_result, driving conditional br i1.
  • Compound Boolean conditions. icmp <pred> i1/iN with all ten LLVM integer predicates (eq, ne, ult/slt, ule/sle, ugt/sgt, uge/sge); direct bitwise i1 and, or, xor (including the xor i1 %x, true logical-NOT idiom); select i1 (including clang's short-circuit shapes select %c, %b, false and select %c, true, %b); and phi i1 short-circuit merges. Covers common frontends' short-circuit encodings and the compound- Boolean forms clang emits for a && b, a || b, !a, a == b, a != b.
  • Integer arithmetic on classical SSA values: add, sub, mul (with the nuw/nsw/exact overflow-flag tokens allowed). The resulting expression is inlined at the use site, so the operands must resolve to classical-register reads, integer constants, or previously bound arithmetic.
  • phi i32 / phi i64 integer accumulation. The mutable count = 0; if r == One { set count = count + 1; } pattern compiles to chained two-incoming phis. The translator lowers the chain to a single OpenQASM 3 int cint_N = 0; classical variable plus conditional cint_N = cint_N + 1; assignments, plus if (cint_N >= T) { … } threshold branches via icmp.
  • select i1 %c, iN A, iN B integer cascade. Optimized QIR produced by LLVM's opt pipeline collapses the integer-accumulation chain into nested selects plus zext / add / icmp ugt on an integer counter. Lowers to the inline arithmetic form (cond) * A + (1 - cond) * B; downstream add / icmp flow through the expanded expression.
  • alloca / bitcast / getelementptr / store / load scalar constant folding for the common list[float] parameter pattern: eagerly-bound scalar values stashed in a local buffer get folded back to their numeric literals at the gate-argument use site, so rx(angles[0], q[0]) with angles=[0.1, 0.2] emits rx(0.1) q[0];.
  • Variadic multi-controlled dispatch via the generalizedInvokeWithRotationsControlsTargets intrinsic lowers to the matching Braket-native gate for the following inner callees: __quantum__qis__x__ctl with 1 or 2 controls (→ cnot / ccnot), y__ctl / z__ctl with 1 control (→ cy / cz), swap__ctl with 1 control and 2 targets (→ cswap), and phaseshift__ctl with 1 control (→ cphaseshift). The adjoint flag maps to inv @. Unmapped (op, numControls, numTargets) tuples produce a descriptive error pointing at upstream decomposition.
  • CFG reduction: sequential blocks, if / if-else, single-exit while loops (one back-edge), and short-circuit phi merges.
  • Structs %Qubit and %Result, plus inline struct-by-value parameter literals ({ double*, i64 }). Other user-defined struct types raise QirToQasmError.

Out of scope (produce a clear error)

All unsupported cases raise qirtoqasm.QirToQasmError with a message naming the root cause.

  • Nested or irreducible CFGs, multi-entry loops, nested loops the reducer cannot structure.
  • Runtime qubit allocation (__quantum__rt__qubit_allocate). All qubits must be assigned statically via inttoptr.
  • Value-typed select for floating-point (select i1 %c, double A, double B used to choose a rotation angle). OpenQASM 3 has no classical ternary in value position; split into if/else arms upstream or precompute. The integer analog select i1 %c, iN A, iN B IS supported via inline arithmetic.
  • Loop-carried phi — integer counters or booleans merging across a true back-edge loop latch. If-merge phis are supported.
  • Controlled-gate combinations not on the mapped list above (e.g. 3-control X, controlled-H). Decompose upstream, or open an issue with the missing mapping.

Contributing and sharing feedback

We welcome feature requests, bug reports, or general feedback, which you can share with us by opening up an issue. We also welcome pull requests — please open an issue describing your work when you get started, or comment on an existing issue with your intentions. For more details on contributing to qirtoqasm, please read the contributing guidelines.

For questions, you can get help via the Quantum Technologies section of AWS RePost. Please tag your question with "Amazon Braket" and mention qirtoqasm in the question title.

Tests

To run qirtoqasm's unit tests, run:

tox -e unit-tests

See DEVELOPMENT.md and the docs site for the full workflow (Rust build, maturin, CMake, coverage, all tox environments).

Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

Metadata

Release files for qirtoqasm 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qirtoqasm 0.3.0
File Size Uploaded Provenance Actions
qirtoqasm-0.3.0.tar.gz 104.7 kB With provenance Details for qirtoqasm-0.3.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for qirtoqasm 0.3.0
File Actions
qirtoqasm-0.3.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for qirtoqasm-0.3.0-cp311-abi3-win_amd64.whl
qirtoqasm-0.3.0-cp311-abi3-musllinux_1_2_x86_64.whl CPython 3.11 abi3 Linux musl 1.2+ x86-64 Details for qirtoqasm-0.3.0-cp311-abi3-musllinux_1_2_x86_64.whl
qirtoqasm-0.3.0-cp311-abi3-musllinux_1_2_aarch64.whl CPython 3.11 abi3 Linux musl 1.2+ ARM64 Details for qirtoqasm-0.3.0-cp311-abi3-musllinux_1_2_aarch64.whl
qirtoqasm-0.3.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details for qirtoqasm-0.3.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
qirtoqasm-0.3.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details for qirtoqasm-0.3.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
qirtoqasm-0.3.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for qirtoqasm-0.3.0-cp311-abi3-macosx_11_0_arm64.whl
qirtoqasm-0.3.0-cp311-abi3-macosx_10_13_x86_64.whl CPython 3.11 abi3 macOS 10.13+ x86-64 Details for qirtoqasm-0.3.0-cp311-abi3-macosx_10_13_x86_64.whl

Total release size: 2.7 MB

Release files / qirtoqasm-0.3.0.tar.gz

Download URL qirtoqasm-0.3.0.tar.gz
Size 104.7 kB
Tags Source
SHA-256 checksum
How to use checksums
79914b947a302e255d19d3d945daaab1215223a5024a79ac97f1a413849c97bb
BLAKE2b-256 checksum
How to use checksums
1f97fb2b816e0160398b8e76a2323f093e0ec815c3bd10d57a883aefa71a6ee1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release files / qirtoqasm-0.3.0-cp311-abi3-win_amd64.whl

Download URL qirtoqasm-0.3.0-cp311-abi3-win_amd64.whl
Size 296.7 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
963393aa1be929bac615ff06a2612e3b1e120d858f4e64762f1fd62d8b100f9d
BLAKE2b-256 checksum
How to use checksums
57d24fd9d2dc89efc5ce571c57b4e5546691d38f4b0e582ad934b94f5d5db9d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release files / qirtoqasm-0.3.0-cp311-abi3-musllinux_1_2_x86_64.whl

Download URL qirtoqasm-0.3.0-cp311-abi3-musllinux_1_2_x86_64.whl
Size 457.7 kB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
931779b79e84d038e392d47172cadc2d92d891ea1696c5337a7e1f18b8a2f77b
BLAKE2b-256 checksum
How to use checksums
317fd5f5b290a382b4ccb366187990b7edf1e79d258b4f40ff95272c9bd09c9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release files / qirtoqasm-0.3.0-cp311-abi3-musllinux_1_2_aarch64.whl

Download URL qirtoqasm-0.3.0-cp311-abi3-musllinux_1_2_aarch64.whl
Size 418.7 kB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
248bb590b023e4a43be777a175d01419aced06973b4db29b77f61f477a715591
BLAKE2b-256 checksum
How to use checksums
a7ffe48e925155d40ddbf9ded68342723999e588e4cf89e82d97565ea9cf79cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release files / qirtoqasm-0.3.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL qirtoqasm-0.3.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 375.0 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
83371ee9a07fac03a09fe6dc9343165a922e85c071624a22e60009471f5f0093
BLAKE2b-256 checksum
How to use checksums
c07f18665d203531ca9f479437ff8a481f7e44972ccb67e69eb1aaa35c936d43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release files / qirtoqasm-0.3.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL qirtoqasm-0.3.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 350.6 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
6c645603597723eb94d75b6a2d1e2e18b934a3342df2c6a987acffcd09b46e65
BLAKE2b-256 checksum
How to use checksums
1522d259d83776551247d0d9a67e7c325d65455be5b60647893a090ea21c70b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release files / qirtoqasm-0.3.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL qirtoqasm-0.3.0-cp311-abi3-macosx_11_0_arm64.whl
Size 335.1 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
444cf37aafdc4b6c6e6d676ff6cae74d2b656e7774063fcf6b0d30f58d802c77
BLAKE2b-256 checksum
How to use checksums
701c38a6a8c789b603738bae042ce1d3178416928ab90db7914af9a2956300e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release files / qirtoqasm-0.3.0-cp311-abi3-macosx_10_13_x86_64.whl

Download URL qirtoqasm-0.3.0-cp311-abi3-macosx_10_13_x86_64.whl
Size 354.2 kB
Tags CPython 3.11 abi3 macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
7b3303141ab562e61ecc70548897326eb2ad7fa24c42fa88005f9f99d618cbea
BLAKE2b-256 checksum
How to use checksums
3f58787c67ba052d688f7fec744a202f52b2ebc88c6c24d707795c74bb218972
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Security for qirtoqasm 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 8 files in this release have been uploaded with provenance metadata.

Select from 8 files

Attestation for qirtoqasm-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page