I built a tiny 2-qubit quantum simulator in Rust to learn the math

135 points Cold-Improvement2388 33 comments

Hey everyone,

I’ve been diving into quantum computing lately and decided to build a lightweight simulator called QNano to help me wrap my head around what’s actually happening under the hood.

It’s limited to 2 qubits for now, but it’s been a great exercise in mapping the quantum gates into code.

https://preview.redd.it/wmwx28gjnd9g1.png?width=1200&format=png&auto=webp&s=58a996bdca99a1bccf738aab8771253e41edc0d8

What it does currently:

  • Uses a custom .qnano assembly-style syntax to write circuits.
  • Handles complex probability amplitudes (so it tracks phase, not just basic probability).
  • Supports 7 gates: H, X, Z, S, T, CX, and CZ.
  • Correctly simulates entanglement (Bell States) and interference.

What’s next: I’m working on a CLI visualizer using Ratatui so I can see the "wires" in the terminal, and I still need to implement a proper measure function.

If you're interested in the math or want to see how to handle complex state vectors in Rust, the code is up on GitHub.

https://github.com/Cqsi/qnano