{"chunks":["<p>QuantumForge began as a holiday exercise: a quantum-circuit simulator written from scratch in Rust. It is a statevector simulator with a Python bridge, so a circuit written for Qiskit can run on it, plus two small variational algorithms built on top.</p>\n<p>It is not a replacement for Qiskit Aer, and the benchmarks below show exactly where it stops keeping up.</p>\n<h2>What is inside</h2>\n<p>The code is a Rust workspace of four crates: <code>tensor_core</code>, <code>rust_kernels</code>, <code>vqe</code> and <code>gqe</code>. The simulator lives in <code>rust_kernels</code>, and it is exposed to Python through PyO3 and built with maturin as the package <code>qhybrid-kernels</code>.</p>\n<p>The state of an <em>n</em>-qubit register is a column of 2ⁿ complex amplitudes. QuantumForge stores it as a 2ⁿ × 2 array of 64-bit floats, one column for the real parts and one for the imaginary parts, which is also the shape it hands back to NumPy. Applying a gate means walking that array and mixing the pairs of amplitudes the gate touches.</p>\n<p>The gate set covers what most textbook circuits need:</p>\n<ul>\n<li>single-qubit: I, X, Y, Z, H, S, S†, T, T†;</li>\n<li>rotations and phases: RX, RY, RZ, P and the general U3;</li>\n<li>controlled: CX, CY, CZ and the Toffoli (CCX).</li>\n</ul>\n<p>Each gate kernel is a straight loop over the state, run with Python&#39;s global interpreter lock released so the Python side is not blocked while Rust works. The loops themselves are serial; rayon is used elsewhere in the workspace, not yet on the statevector path. Parallel gate application is the obvious next step.</p>\n<p>There is also a small noise module: Pauli channels simulated with Monte Carlo trajectories, general Kraus operators on a density matrix, and correlated Pauli noise. The amplitude-damping channel is tested against Qiskit&#39;s own implementation.</p>\n<h2>How it compares</h2>\n<p>The benchmark harness builds one circuit at every size from 4 to 26 qubits, a Hadamard on every qubit followed by a chain of CNOTs, and times it once on each simulator. It compares three:</p>\n<ul>\n<li>a naive NumPy simulator, dropped once a single run takes more than 15 seconds;</li>\n<li>Qiskit Aer on the CPU, with transpilation included in its time;</li>\n<li>QuantumForge.</li>\n</ul>\n<p>At 16 qubits, QuantumForge was about 4,000 times faster than the NumPy simulator. Against Aer, it was faster up to 18 qubits and slower from 19 onwards, where Aer&#39;s optimised, multithreaded kernels take over. The largest state, at 26 qubits, is 2²⁶ amplitudes, which in this layout is 1 GiB.</p>\n","<p>That crossover is the honest summary. For small circuits, where overhead dominates, a lean single-threaded Rust loop wins. For large ones, where the work is the state itself, it needs the parallelism and vectorisation that Aer already has.</p>\n","<p>The timings are single runs on one consumer machine with 48 GB of memory, from my own harness, so the curves say where the crossover is, not what it would be on other hardware.</p>\n<h2>VQE and GQE on the smallest molecule</h2>\n<p>To check the simulator is not just fast but right, I ran two ways of finding a ground-state energy on a two-qubit model of H₂, whose exact ground energy is about −1.857275 hartree.</p>\n<ul>\n<li><strong>VQE</strong>, the variational quantum eigensolver: a four-parameter hardware-efficient circuit whose angles are tuned by Nelder–Mead. The Rust version reached −1.857274, within 1.07 × 10⁻⁶ hartree of exact.</li>\n<li><strong>GQE</strong>, here an evolutionary search over circuits: a population of 50 candidates evolved for 200 generations by tournament selection, mutation and angle tuning. It reached −1.857275030, within 5.15 × 10⁻¹⁴.</li>\n</ul>\n<p>In the same comparison, the Qiskit Aer VQE stopped at −1.848820, 8.45 × 10⁻³ hartree away. I have not yet worked out why the backends disagree by that much on a two-qubit problem, so treat the cross-backend numbers as a prompt to investigate rather than a ranking.</p>\n<p>H₂ with two qubits is the smallest test there is. These results show that the simulator and the optimisers are correct, not that they scale.</p>\n<h2>What I would do next</h2>\n<ul>\n<li>Parallelise gate application across the state, with rayon, which is already a dependency.</li>\n<li>Store amplitudes as interleaved complex numbers and vectorise the inner loops.</li>\n<li>Repeat every benchmark point and record the machine, so the curves come with error bars.</li>\n<li>Add Rust-side tests alongside the eight Python ones.</li>\n</ul>\n"],"figures":[1,2],"words":718,"minutes":3}