Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

181 Commits

Repository files navigation

QuantumSim

Generic badgeGeneric badge

QuantumSim is a simulator for quantum circuits.

Setting up

Clone the repository

git clone https://github.com/rbudhrani/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 GateFunction
Pauli XapplyPauliX(int target)
Pauli YapplyPauliY(int target)
Pauli ZapplyPauliZ(int target)
HadamardapplyHadamard(int target)
Rotation XapplyRx(int target, precision theta)
Rotation YapplyRy(int target, precision theta)
Rotation ZapplyRz(int target, precision theta)
Controlled NOTapplyCnot(int control, int target)
ToffoliapplyToffoli(int control1, int control2, int target)
Multiple controlled CNOTapplyMcnot(int *controls, int numControls, int target)
Controlled ZapplyCz(int control, int target)
Multiple controlled ZapplyMcz(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"intmain(){
// create a QubitLayer object
QubitLayer q;
// apply a hadamard gate
q.applyHadamard(0);
// apply cnot on the 2 qubits
q.applyCnot(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"intmain(){
// create a QubitLayer object with 4 qubits
QubitLayer q(4);
// apply hadamard gates
q.applyHadamard(0);
q.applyHadamard(2);
// apply cnot gates
q.applyCnot(0, 1);
q.applyCnot(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

1 star

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages