Simulator¶
simulator ¶
DenseSVSimulator ¶
Dense statevector quantum circuit simulator.
Qubit ordering: MSB-first (qubit 0 is the most significant bit). Backends: NumPy (CPU), JAX XLA JIT (CPU/GPU/TPU).
Parameters¶
n_qubits : number of qubits use_gpu : reserved for future CuPy/JAX GPU dispatch use_float32: use complex64 instead of complex128
Source code in dense_evolution/simulator.py
set_initial_state ¶
Reset the simulator.
Parameters¶
state : optional complex array of length 2**n. If None, resets to |0...0⟩. The array is normalised automatically.
Source code in dense_evolution/simulator.py
apply_gate_1q ¶
Apply a 2×2 unitary to qubit via tensor contraction.
Uses reshape + moveaxis + matmul — fully vectorised, no Python loops, compatible with both NumPy and JAX.
Source code in dense_evolution/simulator.py
apply_gate_2q ¶
Apply a 4×4 unitary to qubits (q1, q2) via tensor contraction.
Source code in dense_evolution/simulator.py
apply_cx ¶
CX (CNOT) gate.
JAX path: matrix contraction via apply_gate_2q. NumPy path: fully vectorised index swap — no Python loops.
Source code in dense_evolution/simulator.py
apply_cz ¶
CZ gate.
JAX path: matrix contraction via apply_gate_2q. NumPy path: fully vectorised sign flip — no Python loops.
Source code in dense_evolution/simulator.py
apply_rx ¶
Apply a parameterized RX gate using the active backend (NumPy/JAX).
Source code in dense_evolution/simulator.py
apply_ry ¶
Apply a parameterized RY gate using the active backend (NumPy/JAX).
Source code in dense_evolution/simulator.py
apply_rz ¶
Apply a parameterized RZ gate using the active backend (NumPy/JAX).
Source code in dense_evolution/simulator.py
measure ¶
Projective measurement on qubit_idx.
Returns 0 or 1 and collapses the statevector. Uses MSB-first physical bit index: phys = n - 1 - qubit_idx.
BUG FIX (original): the original NumPy collapse wrote sv_reshaped[:, 1 if result == 0 else 0, :] = 0.0 which zeroed the wrong basis state (0 when result=1, 1 when result=0) and never normalised the JAX path.
Source code in dense_evolution/simulator.py
run_circuit_with_chunking ¶
Execute a circuit in chunks to avoid JIT recompilation on large variable-length circuits.
Each chunk is a separate _compile_and_run_circuit_jit call with a fixed-size ops array, allowing XLA to cache each size.
Source code in dense_evolution/simulator.py
get_probabilities ¶
Return measurement probability distribution as a NumPy float64 array.
Source code in dense_evolution/simulator.py
get_statevector ¶
memory_mb ¶
Statevector memory footprint in megabytes.