Quantum and CircuitsReading edition

Python and C++ interface

Reading tools
Reading libraryFind statementsInspect Lean
Switch work

Saved reading

Read side by side

Verification statements describe the retained edition and its recorded evidence. This HTML presentation adds no Lean execution or proof review.

Start reading

Resources & source

Original TeX with line links · Download TeX

The wording and mathematics follow the retained manuscript. This reading format does not add a proof review or extend Lean coverage.

Skip contents and start reading

C.3 Python and C++ interface

C.3.1 Package overview

The Python package catalytic_gate_atlas exports exact primitives for the linear, Clifford, and classical reversible experiments. It requires Python 3.10 or later and has no runtime dependencies.

C.3.2 Installation

cd code
python -m venv .venv
. .venv/bin/activate
python -m pip install -e . --no-build-isolation
python -m pytest tests

On Windows PowerShell, activation is

.\.venv\Scripts\Activate.ps1

C.3.3 Top-level API

from catalytic_gate_atlas import (
    RowGate,
    canonical_ambient_word,
    canonical_restricted_word,
    canonical_six_target,
    snapshot_target,
    verify_canonical_atom,
    exact_clifford_census,
    exact_affine_toffoli_census,
    gate_word_to_openqasm,
)

C.3.4 Linear atom

from catalytic_gate_atlas import verify_canonical_atom

for modulus in (2, 3, 5, 8):
    print(verify_canonical_atom(modulus))

The function evaluates the displayed restricted and ambient words over \({\mathbb Z}/m{\mathbb Z}\) and compares both endpoints with the canonical target.

C.3.5 Snapshot targets

from catalytic_gate_atlas import snapshot_target

# u=4 source updates; snapshots at phases 0, 2, and 4.
A = snapshot_target(4, phases=(0, 2, 4), modulus=2)
for row in A:
    print(row)

The generator checks phase order and produces the exact lower-unitriangular target matrix used in the symbolic family.

C.3.6 Clifford census

from catalytic_gate_atlas import exact_clifford_census

print(exact_clifford_census(2, entangling_cost=True))
print(exact_clifford_census(2, entangling_cost=False))

The optional three-qubit Python census is slower. The release includes an optimized C++ program for the full \(1{,}451{,}520\)-state group.

C.3.7 Affine-versus-Toffoli census

from catalytic_gate_atlas import exact_affine_toffoli_census

print(exact_affine_toffoli_census(3, entangling_cost=False))
print(exact_affine_toffoli_census(3, entangling_cost=True))

The complete ambient enumeration is intentionally limited to three bits.

C.3.8 OpenQASM witness export

from catalytic_gate_atlas import gate_word_to_openqasm

word = ["H1", "CX12", "CX21", "CX20", "CX02", "H0"]
print(gate_word_to_openqasm(word, 3, title="ambient witness"))

The exporter supports the named \(H\), \(S\), \(X\), CX, CZ, and SWAP gates used by the finite atlas and writes OpenQASM 3. The supplied files in examples/ encode the two- and three-qubit restricted and ambient witness words. The Clifford census is performed modulo global phase and Pauli translations, so equality of an exported pair refers to its binary symplectic action unless the ignored Pauli and phase data are separately reconstructed.

PYTHONPATH=. python scripts/export_qasm_examples.py

C.3.9 Search primitives

from catalytic_gate_atlas.search import (
    NamedGenerator,
    breadth_first_distances,
    breadth_first_with_parents,
    zero_one_distances,
    zero_one_with_parents,
    dijkstra_distances,
    reconstruct_path,
    defect_distribution,
)

Every state must be immutable and hashable. The caller supplies a multiplication function with the convention

\[ \texttt{multiply(generator, state)}. \]

C.3.10 Binary matrix primitives

The module algebra.py provides:

  • gf2_identity,

  • gf2_mul,

  • gf2_transpose,

  • gf2_rank,

  • dense modular matrix multiplication,

  • exact permutation composition and inversion.

C.3.11 C++ verifier

g++ -O3 -std=c++20 scripts/clifford_census.cpp -o scripts/clifford_census
./scripts/clifford_census --n 3 --metric total
./scripts/clifford_census --n 3 --metric total --swap
./scripts/clifford_census --n 3 --metric entangling

The executable can write JSON using the --output option.

C.3.12 Figure generation

python scripts/make_monograph_figures.py

All new monograph figures are generated by Matplotlib without external data. The established unitriangular figures are preserved from the Paper I source archive.

C.3.13 Adding a new finite gate model

A new module should implement:

  1. a canonical immutable state representation;

  2. exact multiplication;

  3. named restricted and ambient generators with nonnegative costs;

  4. an exact target-membership test;

  5. a census function returning the standard JSON fields;

  6. smoke tests for group size and witness evaluation.

C.3.14 Standard result schema

A census result should include:

{
    "model": "descriptive-name",
    "size": n,
    "metric": "total-or-weighted",
    "restricted_group_size": ...,
    "ambient_group_size": ...,
    "restricted_diameter": ...,
    "ambient_diameter": ...,
    "defect_count": ...,
    "defect_distribution": {...},
    "maximum_defect": ...,
    "witness": {...},
    "status": "complete finite enumeration"
}

A partial search must not use the status string “complete finite enumeration.”

C.3.15 Error handling

Several entry points validate dimensions, distinct controls, matrix shape, and cost restrictions. The complete affine census rejects widths above three, and the C++ Clifford executable accepts only one through three qubits. Low-level helpers assume well-formed indices and states, so callers should not treat every helper as a fully validated public parser. The search code does not silently truncate its reachable state space.

Source and conversion record

Source SHA-256: c21e2450c5dde03dc9f76e1a9de029281f4509fb7a83471dc316a49177993ba7

Unsupported prose commands stop the build. The mathematical expression sequence is checked against the source, with manuscript macros expanded for display.

Conversion records

Notation in Quantum and Circuits

Look up a symbol without leaving this chapter. Select text before opening help to search for it.

Search this work’s notation.

    Symbols can have different meanings in different passages. Read each result in its own context.

    Open the full notation index