qbin is a minimal, lossless binary encoding for a useful subset of OpenQASM 3.
It focuses on code you actually run on hardware (single‑/two‑qubit gates, rotations,
measurement, and simple conditionals), so state‑init circuits and large templated programs
shrink dramatically versus plain text QASM.
This repository contains:
- spec/ — the QBIN file format and quick reference
- compiler/ —
qbin-compile(OpenQASM → QBIN) - decompiler/ —
qbin-decompile(QBIN → OpenQASM) - tests/ — round‑trip tests (QASM → QBIN → QASM) wired into CTest
- Size matters: Initialization / state‑prep circuits and large parametrized templates can be huge in text.
qbinremoves whitespace/identifiers and uses compact encodings (ULEB128, f32 angles), so artifacts are much smaller. - Streaming‑friendly: One pass, sectioned layout (
INST, more later). - Round‑trip exactness: For the supported OpenQASM subset, decompilation reproduces the same source (incl. EOF newline).
See the full format in spec/qbin-spec.md and the quick sheet in spec/qbin-quickref.md.
qbin/
├─ spec/ # spec and quickref
├─ compiler/ # qbin-compile (QASM -> QBIN)
├─ decompiler/ # qbin-decompile (QBIN -> QASM)
├─ tests/ # CTest harness + data/*.qasm
├─ scripts/ # helper scripts (bootstrap.sh)
├─ .github/workflows/ci.yml # GitHub Actions CI
├─ README.md LICENSE CONTRIBUTING.md CODE_OF_CONDUCT.md SECURITY.md
Requirements: CMake ≥ 3.16, a C++17 compiler, and Python 3.
# If git reports "password auth not supported", see Troubleshooting below.
./scripts/bootstrap.sh # Release build
# or
./scripts/bootstrap.sh Debug # Debug buildcmake --preset dev # or: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build --preset dev # or: cmake --build build --parallel
ctest --preset dev --output-on-failureArtifacts (after a preset build):
build/compiler/qbin-compile
build/decompiler/qbin-decompile
Requirements: Visual Studio 2022 with C++ workload, CMake ≥ 3.20, and Python 3.
cmake --preset win-release
cmake --build --preset win-release --config Release
ctest --preset win-release -C Release --output-on-failurecmake --preset win-debug
cmake --build --preset win-debug --config Debug
ctest --preset win-debug -C Debug --output-on-failureAfter building you will find the executables in:
build\win-release\Release\qbin-compile.exe
build\win-release\Release\qbin-decompile.exe
(or the win-debug\Debug\ folder if you built Debug).
build/compiler/qbin-compile path/to/input.qasm -o out.qbinbuild/decompiler/qbin-decompile out.qbin -o roundtrip.qasmThe decompiler preserves canonical formatting for the supported subset and ends with a blank line to match our tests’ byte‑for‑byte comparison.
Tests live in tests/ and are run by CTest.
- Add your
.qasmvectors totests/data/. - Each file becomes a test: QASM → QBIN → QASM, then exact compare.
Run tests manually:
ctest --test-dir build --output-on-failureA GitHub Actions workflow builds the compiler & decompiler and runs the round‑trip tests on Ubuntu for pushes and PRs. See .github/workflows/ci.yml.
Either run with bash:
bash scripts/bootstrap.shor fix the bit once (and commit it so it stays executable):
chmod +x scripts/bootstrap.sh
git update-index --chmod=+x scripts/bootstrap.sh
git commit -m "Make bootstrap executable"; git pushEnsure you rebuilt the latest decompiler: it must read operands in this order:
a → b → c → angle(tag+payload) → aux_u32 → imm8 (IF only).
Do a clean build of decompiler/.
- Single‑qubit:
x,y,z,h,s,sdg,t,tdg,sx,sxdg,rx(θ),ry(θ),rz(θ),phase(θ) - Two‑qubit:
cx,cz,swap(+ some controlled/XX/YY/ZZ rotations reserved) - Classical I/O:
c[i] = measure q[j]; - Control flow: single‑line
if (c[k] ==/!= v) { <stmt>; } - Declarations (
qubit[N] q;,bit[M] c;) are inferred on decompile.
See spec for opcodes, masks, and extensibility.
Copyright (c) Quantag IT Solutions GmbH
Licensed under the terms in LICENSE.
- Please read CONTRIBUTING.md before sending PRs.
- Report vulnerabilities via SECURITY.md.
Thanks to the OpenQASM community and the broader quantum‑stack ecosystem for prior art and inspiration.