This graduate level project emulates Shor's algorithm in an HPC environment utilizing the OpenMP library to manage qubit register states with threads. A single thread manages an initial qubit register state of "0...0" and applies the quantum gates listed in the circuit by updating that state appropriately. However, whenever a Hadamard gate is encountered in the circuit, the 'omp task' pragma is used to spawn a new thread that allows for a branching of possible qubit states. Each thread updates the qubit's state and probability amplitude and then both threads continue processing the remaining quantum gates in the circuit.
At the end of the circuit, the 'task_reduction' pragma is used to sum the probability amplitudes for each possible output state across all the resulting threads. Measurements are performed by randomly sampling the set of resulting states given their probability distributions. This program also executes the classical component of Shor's algorithm that takes the period of the function, found by the quantum algorithm, and computes the factors for N.
The final_project folder contains the C++ code for running the program to execute Shor's algorithm for N=15. This work served as a proof of concept design for how one would emulate a quantum algorithm within a high performance computing environment. The program, upon completion, will read out on the command line the factors of N=15, the number of times the quantum algorithm had to run (in the case that it measured a period of 0, which is not informative and prompts another re-run), and the total processing time. The circuit contains 5 Hadamard gates which creates a total of 32 threads (OMP_NUM_THREADS set to 32 allows for the program to run a parallel capacity more similar to how the quantum algorithm works on quantum hardware where the parallelness comes for free.
Example of how to run the compiled program and the output:
./shors
>>Performing Shor's Algorithm to factor 15 with 12 threads.
>>The estimate of the factors of 15 are 3, 5.
>>Number of tries: 3, using 12 threads, time spent processing: 2741675 ns.
The circuit to carry out the period estimation for
The quantum_ops folder explores this idea by building out a framework to build circuits dynamically. In order to build the algorithm for a generalized a and b, then it dynamically builds the circuit to perform addition of those those two numbers and repeats the addition X number of times. Performance benefits of strong scaling (increasing number of threads to use) can be easily seen once these larger circuits are run.