I wanted to undertsand more about Quantum Computing. Quantum computing is a huge topic, and I felt that just using a ready-made library wasn't enough for me to really 'get' it. I decided to write this simulator from scratch to see what happens behind the scenes
- In-place computation: Memory-efficient bitwise operations.
- Multithreading: Optimized with OpenMP for multicore CPUs.
- CLI Interface: Accepts qubit count and shots as arguments.
This simulator models a quantum system of
where
Quantum gates (X, H, Z, CNOT) are applied not via naive matrix multiplication (which would require sparse matrices of size
Simulating quantum systems on classical hardware requires exponential memory std::complex<double> (16 bytes).
- 10 qubits
$\approx$ 16 KB - 20 qubits
$\approx$ 16 MB - 30 qubits
$\approx$ 16 GB of RAM
Do not simulate more than 28-30 qubits unless you have sufficient physical RAM, or your system will trigger the OOM (Out-Of-Memory) killer.
g++ main.cpp QuantumSimulator.cpp -o qsim -O3 -fopenmp./qsim <number_of_qubits> <number_of_shots>