A Python DSL for safe quantum programming with disciplined ancilla management
Project description
b01t: Safe Quantum Programming
Quantum code has its own class of bugs: dirty ancillae, bad uncomputation, silent decoherence. These pass type checks and compile fine in every existing framework. You only discover them by simulating the density matrix.
b01t is a Python DSL that catches these at build time. Every well-typed safe program is a proven unitary channel (the Hero Theorem, machine-checked in Lean 4).
Example
A phase oracle in six lines:
from b01t import coherent, QReg, cx, z, Certification
from b01t.kit import ancilla, compute, phase, uncompute
@coherent
def oracle(sys: QReg):
with ancilla(1) as anc:
compute(lambda: cx(sys[0], anc[0]))
phase(lambda: z(anc[0]))
uncompute()
prog = oracle.build_exact(("sys", 1))
assert prog.certification == Certification.SAFE # proven unitary, no simulation
The compute block copies system information into the ancilla using only classical-reversible gates. The phase block applies a diagonal rotation. The uncompute auto-generates the inverse. b01t proves at build time that the ancilla returns to |0> and the whole program is a unitary channel.
Now the mistake every quantum programmer makes at least once:
@coherent
def broken(sys: QReg):
with ancilla(1) as anc:
compute(lambda: h(anc[0])) # "just put it in superposition"
phase(lambda: z(anc[0]))
uncompute()
# DSLValidationError: gate 'h' is not allowed in compute blocks
Qiskit, Cirq, and Q# all accept this. It compiles, it runs, it looks fine. But since H is not a permutation gate, it creates superposition, which means the ancilla can end up entangled with the system after "uncomputation." The program silently becomes a mixed channel instead of a unitary.
b01t rejects it: compute blocks allow only permutation gates (X, CX, CCX, MCX), phase blocks allow only diagonal gates (Z, S, T, CZ, CCZ, MCZ). If your program passes these rules, it is a unitary channel.
Install
uv sync
uv run pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file b01t_lang-0.1.0.tar.gz.
File metadata
- Download URL: b01t_lang-0.1.0.tar.gz
- Upload date:
- Size: 89.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e58bfa6780204fd576d523c3faa39e616a0c263cb923c652f7b41d12a0aa5842
|
|
| MD5 |
2e0376b199bfbe7fc72b09261b5d02fa
|
|
| BLAKE2b-256 |
5d7ae060ed588f0b1245e95189a7dfd5d0fb1e7c89d0a0dbfc9c03ee0cf80141
|
File details
Details for the file b01t_lang-0.1.0-py3-none-any.whl.
File metadata
- Download URL: b01t_lang-0.1.0-py3-none-any.whl
- Upload date:
- Size: 76.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5283b60e3db59ff327332a1da86cdfcea445194f064ddad6ecc1ed5ed7ce974b
|
|
| MD5 |
b0cdefa0424c11f44a839636c9461c20
|
|
| BLAKE2b-256 |
c194e78811db875ee5ab244feb84b0e19143606374871e05b7f19cbd913f2c27
|