This project is a high-performance, GPU-accelerated quantum circuit simulator. It models the evolution of multi-qubit quantum states by applying quantum gates directly on the GPU using CUDA.
The motivation behind this simulator was to learn more about GPU programming as well as quantum computing.
-
Enable multi qubit gates
-
Probability visualizer
-
Kernel fusion
-
Kernels to enable the use of single qubit gates
-
Circuit visualizer
-
Simple ui
git clone git@github.com:semzit/PsiGPU. #clone
cd PsiGPU
mkdir build #create build directory
cd build
cmake .. # build
make
./PsiGPU # run executable
The state vector is represented as an array of cuDoubleComplex which allows the amplitude to represent both its real and imaginary parts
Amplitude:
The complete state vector for a system of two qubits would be represented by:
Or
Because an iterative approach when applying quantum gates and launching individual gpu kernels every time is expensive this project works by iterating throught the gates within the kernel.
__global__ void applyGate(cuDoubleComplex* stateVec, const Gate* gates, int numQubits, int numGates) {
int idx = blockIdx.x * blockDim.x + threadIdx.x; // Thread index
int dim = 1 << numQubits; // Total amplitude count
if (idx >= dim) return;
// Iterate through gates
for (int gate = 0; gate < numGates; gate++){
int i = gates[gate].targets[0]; // Get control qubit
int pairIdx = idx ^ (1 << i); // Index of second amplitude in the pain (the beta to a given alpha)
if(idx < pairIdx){
cuDoubleComplex a = stateVec[idx];
cuDoubleComplex b = stateVec[pairIdx];
// Multiply and add (matrix-vector multiplication)
stateVec[idx] = cuCadd(cuCmul(gates[gate].matrix[0], a),
cuCmul(gates[gate].matrix[1], b));
stateVec[pairIdx] = cuCadd(cuCmul(gates[gate].matrix[2], a),
cuCmul(gates[gate].matrix[3], b));
}
__syncthreads(); // Dont continue until all threads are done
}
}Because in quantum mechanics the probability is the square of the amplitude, We can sqaure
- Lightweight, fast, GPU powered quantum simulator
- Alternative for high-performance GPU-based quantum emulation
CUDA/GPU programming:
- https://www.cs.emory.edu/~cheung/Courses/355/Syllabus/94-CUDA/SLIDES/
- https://www.learncpp.com/
- https://google.github.io/googletest/primer.html
Quantum Computing:
- https://quantum.country/
- https://youtu.be/tsbCSkvHhMo?si=DjhDKAKPLa0PlkgT
- https://youtu.be/RQWpF2Gb-gU?si=qExsQVy-IvSGIXRE
- Language: C++17, CUDA 11
- Testing: GoogleTest
- GPU: NVIDIA 4060
MIT