Skip to content

qbee-eu/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.

Cloning and checking

Clone the repository

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

Run the checks 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.

Quantum Gate Function
Pauli X pauliX(int target)
Pauli Y pauliY(int target)
Pauli Z pauliZ(int target)
Hadamard hadamard(int target)
Rotation X rx(int target, precision theta)
Rotation Y ry(int target, precision theta)
Rotation Z rz(int target, precision theta)
Controlled NOT cnot(int control, int target)
Toffoli toffoli(int control1, int control2, int target)
Multiple controlled CNOT mcnot(int *controls, int numControls, int target)
Controlled Phase cphase(int control, int target)
Multiple controlled Phase mcphase(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 Computing Simulator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 75.8%
  • Makefile 24.2%