Skip to content

CaffeineMakesCode/QuantumSim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QuantumSim

Generic badge Generic badge

QuantumSim is a simulator for quantum computing.

Setting up

Clone the repository

git clone https://github.com/CaffeineMakesCode/QuantumSim

Run the tests from the root folder

cd <path-to-repository>/QuantumSim && make check

Usage

The QubitLayer class in src/QubitLayer.cpp defines the functions for the quantum gates and the arrays that store the amplitudes for the qubits. The table below lists the functions that can be used by a QubitLayer object. precision is a typedef for double. The supported gates are:

Quantum Gate Function
Pauli X applyPauliX(int target)
Pauli Y applyPauliY(int target)
Pauli Z applyPauliZ(int target)
Hadamard applyHadamard(int target)
Rotation X applyRx(int target, precision theta)
Rotation Y applyRy(int target, precision theta)
Rotation Z applyRz(int target, precision theta)
Controlled NOT applyCnot(int control, int target)
Toffoli applyToffoli(int control1, int control2, int target)
Multiple controlled CNOT applyMcnot(int *controls, int numControls, int target)
Controlled Z applyCz(int control, int target)
Multiple controlled Z applyMcz(int *controls, int numControls, int target)

Example

Running a quantum circuit is done by writing the circuit in src/main.cpp.

#include <iostream>
#include <complex>
#include "QubitLayer.hpp"
#include "qAlgorithms.hpp"

int main(){
    // create a QubitLayer object
    QubitLayer q;
    // apply a hadamard gate
    q.hadamard(0);
    // apply cnot on the 2 qubits
    q.cnot(0, 1);
    // print qubits
    q.printQubits();
}

This circuit creates an EPR pair.

By default when a QubitLayer object is created, it is initialised with 2 qubits. To setup a larger quantum circuit, a QubitLayer object can be constructed using arguments.

#include <iostream>
#include <complex>
#include "QubitLayer.hpp"
#include "qAlgorithms.hpp"

int main(){
    // create a QubitLayer object with 4 qubits
    QubitLayer q(4);
    // apply hadamard gates
    q.hadamard(0);
    q.hadamard(2);
    // apply cnot gates
    q.cnot(0, 1);
    q.cnot(2, 3);
    // print qubits
    q.printQubits();
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

About

Quantum Circuit Simulator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published