Tools
Python Tools
The Python layer generates pre-computed lookup tables that make the Rust/JavaScript engine 10-100× faster by replacing runtime calculations with table lookups.
precompute.py
A 1,248-line Python script that generates 8 JSON data files:
# Generate all 8 files (~0.7 seconds)
python3 precompute.py
# Verify existing files
python3 precompute.py --check
# Regenerate from scratch
python3 precompute.py --clean
# Generate only one target
python3 precompute.py --target qft
python3 precompute.py --target gate_matrices
python3 precompute.py --target grover
Generated Files
| File | Size | Contents |
|---|---|---|
gate_matrices.json | 8 KB | All 16 gate matrices + unitarity verification. I, X, Y, Z, H, S, T, Rx(θ), Ry(θ), Rz(θ) etc. |
qft_matrices.json | 4 MB | Exact QFT unitary matrices for n=1..8 qubits. Verified: first row is all 1/√N. |
molecule_hamiltonians.json | 4 KB | Pauli-string Hamiltonians: H₂, LiH, BeH₂, H₂O. FCI energies, nuclear repulsion, all terms. |
pauli_table.json | 7 KB | Complete Pauli group multiplication table. Commutation, eigenvalues, Z-basis signs. |
grover_table.json | 18 KB | Optimal Grover iteration counts for all (nQ, M) up to nQ=20. Success probabilities. |
noise_kraus.json | 40 KB | Kraus operators: depolarising, amplitude damping, phase damping, bit/phase flip. 13 error rates × 189 T1/T2 combos. |
circuit_identities.json | 4 KB | Gate simplification rules: self-inverse, power rules, basis changes, rotation merging. |
molecular_energies.json | 2 KB | FCI/HF/CCSD reference energies for H₂, LiH, H₂O, NH₃, N₂, BeH₂. |
Python API Example
import json
from pathlib import Path
# Load Grover table
with open("precomputed/grover_table.json") as f:
grover = json.load(f)
# Look up optimal iterations for 4-qubit register, 1 target
entry = grover["table"]["4"]["single_target"]
print(f"Optimal iters: {entry['optimal_iters']}") # 3
print(f"Success prob: {entry['success_prob']}") # 0.9613
# Load molecule Hamiltonian
with open("precomputed/molecule_hamiltonians.json") as f:
mols = json.load(f)
h2 = mols["hamiltonians"]["H2"]
print(f"H2 FCI: {h2['fci_energy_hartree']} Ha")
for t in h2["terms"][:3]:
print(f" {t['coefficient']:+.6f} × {t['pauli']}")