All Projects → jtiosue → Quantum-Computer-Simulator-with-Algorithms

jtiosue / Quantum-Computer-Simulator-with-Algorithms

Licence: MIT license
C++ simulator of quantum registers and quantum algorithms

Programming Languages

C++
36643 projects - #6 most used programming language
python
139335 projects - #7 most used programming language
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Quantum-Computer-Simulator-with-Algorithms

Quantum-Computing-Collection-Of-Resources
A Well Maintained Repository On Quantum Computing Resources [Code+Theory] Updated Regularly During My Time At IBM, Qubit x Qubit And The Coding School's Introduction To Quantum Computing Course '21
Stars: ✭ 183 (+1120%)
Mutual labels:  quantum, quantum-computing, quantum-algorithms, qubits
qibo
A framework for quantum computing with hardware acceleration.
Stars: ✭ 120 (+700%)
Mutual labels:  quantum, quantum-computing, quantum-algorithms
learn-qc-with-python-and-qsharp
Companion code for Learn Quantum Computing with Python and Q# Book by Dr. Sarah Kaiser and Dr. Chris Granade 💖
Stars: ✭ 62 (+313.33%)
Mutual labels:  quantum, quantum-computing, quantum-algorithms
Blueqat
Quantum Computer Library for Everyone
Stars: ✭ 298 (+1886.67%)
Mutual labels:  quantum, quantum-computing, quantum-algorithms
Quantum-Computing-Resources
This repository contains the best resources for learning practical quantum computing. This repository will be updated frequently.
Stars: ✭ 60 (+300%)
Mutual labels:  quantum, quantum-computing, quantum-algorithms
launchpad
Resources to get started in Quantum Computing!
Stars: ✭ 21 (+40%)
Mutual labels:  quantum-computing, quantum-algorithms, qubits
miniqubit
Quantum emulator of the IBM Quantum experience
Stars: ✭ 24 (+60%)
Mutual labels:  quantum, quantum-computing, quantum-computer-simulator
qcl
Quantum Computation Language port from http://tph.tuwien.ac.at/~oemer/qcl.html
Stars: ✭ 29 (+93.33%)
Mutual labels:  quantum, quantum-computing, quantum-algorithms
unitaryhack
Rules and information for the 2021 unitaryHACK event hosted by @unitaryfund
Stars: ✭ 16 (+6.67%)
Mutual labels:  quantum, quantum-computing, quantum-algorithms
Strawberryfields
Strawberry Fields is a full-stack Python library for designing, simulating, and optimizing continuous variable (CV) quantum optical circuits.
Stars: ✭ 505 (+3266.67%)
Mutual labels:  quantum, quantum-computing, quantum-algorithms
Grove
Quantum algorithms built using pyQuil.
Stars: ✭ 332 (+2113.33%)
Mutual labels:  quantum, quantum-computing, quantum-algorithms
Qpanda 2
QPanda 2 is an open source quantum computing framework developed by OriginQC that can be used to build, run, and optimize quantum algorithms.
Stars: ✭ 128 (+753.33%)
Mutual labels:  quantum, quantum-computing, quantum-algorithms
Teach Me Quantum
⚛ 10 week Practical Course on Quantum Information Science and Quantum Computing - with Qiskit and IBMQX
Stars: ✭ 118 (+686.67%)
Mutual labels:  quantum, quantum-computing, quantum-algorithms
Awesome Quantum Machine Learning
Here you can get all the Quantum Machine learning Basics, Algorithms ,Study Materials ,Projects and the descriptions of the projects around the web
Stars: ✭ 1,940 (+12833.33%)
Mutual labels:  quantum, quantum-computing, qubits
Quimb
A python library for quantum information and many-body calculations including tensor networks.
Stars: ✭ 170 (+1033.33%)
Mutual labels:  quantum, quantum-computing
Quantum Neural Networks
This repository contains the source code used to produce the results presented in the paper "Continuous-variable quantum neural networks". Due to subsequent interface upgrades, these scripts will work only with Strawberry Fields version <= 0.10.0.
Stars: ✭ 207 (+1280%)
Mutual labels:  quantum, quantum-computing
qc portfolio optimization
A program that implements the portfolio optimization experiments using a hybrid quantum computing algorithm from arXiv:1911.05296. The code was developed as part of the 2020 Quantum mentorship program. Many thanks to my mentor Guoming Wang from Zapata Computing!
Stars: ✭ 21 (+40%)
Mutual labels:  quantum, quantum-computing
Q.js
Quantum computing in your browser.
Stars: ✭ 158 (+953.33%)
Mutual labels:  quantum, quantum-computing
QCompress-1
Quantum Autoencoder Implementation using Forest and OpenFermion
Stars: ✭ 20 (+33.33%)
Mutual labels:  quantum-computing, quantum-algorithms
public research
Publicly available research done by BOHR.TECHNOLOGY.
Stars: ✭ 16 (+6.67%)
Mutual labels:  quantum-computing, quantum-algorithms

Quantum-Computer-Simulator-with-Algorithms

C++11 simulator of quantum registers and quantum algorithms

If you use this anywhere, please cite me and email ([email protected]) me so I can see it too!

To see explanations and proofs of the various algorithms, see explanation/math.pdf. To see examples of how to use this code, look at src/test.cpp. To get started, compile with g++ -std=c++11 -o test *.cpp.

QAlgorithms

I have implemented various algorithms that apply a series of quantum logic gates to a register in order to achieve some goal. There is quantum ripple carry addition, quantum modular arithitic using the quantum and inverse quantum Fourier transforms, Grover's search algorithm, and Shor's factorization algorithm with quantum period finding. See qalgorithms.cpp.

I am able to simulate many qubits fairly well. Finding the factors of 2813 takes on average under ten seconds (Shor(2813)), and 3901 (Shor(3901)) took under a minute on my laptop. From this, we see that simulating quantum systems on a classical computer is indeed exponentially complex.

Example usage

#include "QuantumComputerSimulator.h"
#include <iostream>

int main() {
  
  Register reg(4); // initialize register with 4 qubits
  for(int i=0; i<4; i++) reg.Hadamard(i); // apply Hadamard gate to each qubit
  reg.ControlledNot(1, 3); // apply Controlled-Not gate to the target qubit 3 with control qubit 1
  
  QFT(&reg); // Apply quantum fourier transform to all the qubits.
  IQFT(&reg, 1, 4); // Apply inverse quantum fourier transform to qubits 1 through 3 (4 is non inclusive)
  
  reg.print_states();

  // Apply a function to the states. This particular function sends |x> to |x+1 mod 16>
  // or, in terms of qubits, |0000> goes to |0001>, |0001> goes to |0010>, ...
  // |1111> goes to |0000>.
  auto f = [](string state) {
    string r = base10_to_binary((binary_to_base10(state) + 1) % (int)pow(2, 4));
    while (r.size() < 4) r = "0" + r; // ensure resulting number is represented with 4 qubits
    return r;
  };
  // reg.apply_function will check to make sure that the function f represents a unitary transformation.
  reg.apply_function(f);

  reg.print_states();
  
  char c = reg.measure(0); // measure just qubit 0;
  
  std::cout << "Measured qubit 0 to be " << c << std::endl;
  
  // reg will now be collapsed into a superposition of states with the zeroth qubit being equal to c.
  std::cout << reg << std::endl; // equivalent to reg.print_states();
  
  string state = reg.measure(); // Collapse the whole system.
  
  std::cout << "Measured the register, collapsed into state " << state << std::endl;
  
  // reg will now be in state `state` with probability one.
  std::cout << reg << std::endl;
  
  return 0;
}

Applying your own gates

See quantum.h/quantum.cpp and unitary.h/unitary.cpp. The Register class has a method to apply_gate(Unitary u, vector v); this applies the gate given by u to the qubits given in v.

A few things that cause weird behavior

  • If you get probabilities that sum to more than one, you probably applied a controlled gate with repeated qubits; i.e. apply a controlled-not gate with control and target both being the same qubit.
  • Be very careful with operations involving unsigned ints and ints. I decided to make most types in the code unsigned, but this often causes strange things to happen, and caused me many minutes of confusion. If in doubt, be very explicit; convert everything to an int when doing loops and calculations, and then convert back to unsigned int when sending values into functions.
  • When computing modulo powers, use my mod_power(a, x, N) function from methods.h instead of (int)pow(a, x) % N, because the latter often causes an overflow if a or x are large enough.

Note

A lot of the algorithms could probably be implemented more efficiently in terms of the code, maybe by combining gates or qubit operations. But for me the point was to understand what one would physically do in order to program a quantum computer. Thus, whenever I can, I only use one- or two-qubit logic gates.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].