Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

b01t_lang-0.1.0.tar.gz (89.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

b01t_lang-0.1.0-py3-none-any.whl (76.1 kB view details)

Uploaded Python 3

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

Hashes for b01t_lang-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e58bfa6780204fd576d523c3faa39e616a0c263cb923c652f7b41d12a0aa5842
MD5 2e0376b199bfbe7fc72b09261b5d02fa
BLAKE2b-256 5d7ae060ed588f0b1245e95189a7dfd5d0fb1e7c89d0a0dbfc9c03ee0cf80141

See more details on using hashes here.

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

Hashes for b01t_lang-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5283b60e3db59ff327332a1da86cdfcea445194f064ddad6ecc1ed5ed7ce974b
MD5 b0cdefa0424c11f44a839636c9461c20
BLAKE2b-256 c194e78811db875ee5ab244feb84b0e19143606374871e05b7f19cbd913f2c27

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page