Tools for Pauli Based Computation (PBC), a modality of quantum computation.
src/PBCCompiler.jl- Main module with circuit operations and compiler infrastructuresrc/traversal.jl- Circuit traversal utilities for gate simplificationssrc/affectedqubits.jl- Query functions for qubit indices affected by operationssrc/plotting.jl- Plotting function stubs (scaffolding for extensions)ext/PBCCompilerMakieExt/- Makie extension for circuit visualizationtest/- Test suite using TestItemRunner.jlbenchmark/- Performance benchmarks using BenchmarkTools.jl
- Moshi.jl - Algebraic data types via
@datamacro - QuantumClifford.jl - Pauli operators and stabilizer formalism
Algebraic data type representing quantum circuit operations:
Measurement- Pauli measurement with classical bit outputPauli- Pauli gate applicationExpHalfPiPauli,ExpQuatPiPauli,ExpEighPiPauli- Rotation gates (pi/2, pi/4, pi/8)PrepMagic- Magic state preparationPauliConditional- Pauli gate conditioned on another PauliBitConditional- Operation conditioned on classical bit
The preprocess_circuit function transforms circuits through stages:
- Remove Pauli conditionals
- Commute non-Clifford gates to front
- Group non-Clifford operations
- Commute measurements to end
- Remove non-Clifford gates (introduce magic states)
- Remove post-measurement operations
QuantumRuntime- Abstract type for quantum execution backendsMockRuntime- Testing runtime where measurements return deterministic resultsComputerState- Tracks circuit, instruction pointer, and memory state
The traversal function (src/traversal.jl) applies transformations to adjacent pairs of circuit operations:
traversal(circuit, pair_transformation, direction=:right, starting_index=1, end_index=:end)pair_transformation(op1, op2)returns:(new_op1, new_op2)tuple to replace the pair- Single operation to combine the pair into one
nothingto keep unchanged
- Supports left-to-right (
:right) or right-to-left (:left) traversal - Used for gate commutation, simplification, and compilation passes
Note on Moshi types: Use Moshi.Data.isa_variant(op, CircuitOp.Pauli) instead of op isa CircuitOp.Pauli to check variant types.
The affectedqubits function (src/affectedqubits.jl) returns the sorted list of qubit indices affected by an operation or circuit:
affectedqubits(op::CircuitOp.Type) -> Vector{Int}
affectedqubits(circuit::Circuit) -> Vector{Int}When Makie is loaded, the PBCCompilerMakieExt extension provides circuit plotting:
using CairoMakie # or GLMakie
using PBCCompiler
circuit = Circuit([...])
circuitplot(circuit) # Create a plot
circuitplot!(ax, circuit) # Add to existing axis
circuitplot_axis(fig[1,1], circuit) # Create complete figure panelPlot features:
- Gates shown as colored rectangles spanning affected qubits
- Horizontal qubit wire lines
- Measurement results marked with classical bit index (e.g., "c0")
- Conditional operations marked with dependency index (e.g., "?c0")
- PrepMagic gates not visualized (placeholder for future)
Configurable attributes:
gatewidth,qubitspacing- Gate dimensionswirecolor,wirelinewidth- Wire appearancepaulicolor,measurementcolor, etc. - Gate colors by variant
- Always pull latest master:
git pull - Create feature branches for new work
- Commit often at each change
- Update CLAUDE.md with new functionality
- Run tests before creating PRs
- Add benchmarks for new performance-critical functionality
- Docstrings are for users, not developers
- Do not include implementation details (e.g., "uses pattern matching", "implemented via recursion")
- Focus on: what the function does, its arguments, return values, and usage examples
- Implementation notes belong in code comments, not docstrings
julia -tauto --project -e 'using Pkg; Pkg.test("PBCCompiler")'Benchmarks are managed with BenchmarkTools.jl and run in CI via AirspeedVelocity.jl.
Run benchmarks locally:
julia -tauto --project=benchmark -e 'include("benchmark/benchmarks.jl"); run(SUITE)'When to add benchmarks:
- New compilation passes or transformations
- New traversal operations
- Any function that processes circuits at scale
- Performance-critical code paths
Benchmark file structure:
- Add new benchmarks to
benchmark/benchmarks.jl - Use
evals=1for functions that modify state in-place - Use
setup=to create fresh data for each evaluation - Group related benchmarks using
BenchmarkGroup
Always use the -tauto flag when launching Julia to utilize all available threads, which drastically speeds up compilation times:
julia -tauto --project- QuantumClifford.jl source:
../QuantumClifford.jl - QuantumInterface.jl source:
../QuantumInterface.jl
- "Game of Surface Codes" - https://quantum-journal.org/papers/q-2019-03-05-128/pdf/
- QuantumClifford.jl - Stabilizer formalism
- BPGates.jl - Bell-preserving gates