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

FileSizeContents
gate_matrices.json8 KBAll 16 gate matrices + unitarity verification. I, X, Y, Z, H, S, T, Rx(θ), Ry(θ), Rz(θ) etc.
qft_matrices.json4 MBExact QFT unitary matrices for n=1..8 qubits. Verified: first row is all 1/√N.
molecule_hamiltonians.json4 KBPauli-string Hamiltonians: H₂, LiH, BeH₂, H₂O. FCI energies, nuclear repulsion, all terms.
pauli_table.json7 KBComplete Pauli group multiplication table. Commutation, eigenvalues, Z-basis signs.
grover_table.json18 KBOptimal Grover iteration counts for all (nQ, M) up to nQ=20. Success probabilities.
noise_kraus.json40 KBKraus operators: depolarising, amplitude damping, phase damping, bit/phase flip. 13 error rates × 189 T1/T2 combos.
circuit_identities.json4 KBGate simplification rules: self-inverse, power rules, basis changes, rotation merging.
molecular_energies.json2 KBFCI/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']}")