https://github.com/carlowood/quantum
Play with quantum gates
https://github.com/carlowood/quantum
quantum-computer-simulator quantum-computing
Last synced: about 1 month ago
JSON representation
Play with quantum gates
- Host: GitHub
- URL: https://github.com/carlowood/quantum
- Owner: CarloWood
- Created: 2019-03-02T19:25:49.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-11T17:44:39.000Z (9 months ago)
- Last Synced: 2025-04-14T03:09:28.921Z (about 1 month ago)
- Topics: quantum-computer-simulator, quantum-computing
- Language: C++
- Size: 80.1 KB
- Stars: 5
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# quantum
Play with quantum gates## Usage
Edit
src/quantum.cxx
and make a circuit using C++ code, but in a way that looks
much like the normal way quantum circuits are composed. For example,
q[1] - H - co(0) - H - measure(0);
q[0] - CX(0) - S - H - T_inv - H - measure(1);Here each
q[...]
is a qubit,H
is the Hademar gate, etc
(see [Gates.h](https://github.com/CarloWood/quantum/blob/master/src/Gates.h) for a list of all
standard gates).co(int)
is the control input of a controlled CNOT whileCX(int)
with the same int, is the corresponding controlled input. Finally,measure(int)
measures the classical bitint
. You must specify
the number of qubits and classical bits at the moment you createq
.Note that there can only be a single minus sign between the gates.
## Wave function collapse and shots
THIS IMPLEMENTATION DOES NOT COLLAPSE THE WAVE FUNCTION.
This is important to me, because I don't believe in wave function collapses.
That only appears to be the case when you yourself get entangled with the quantum
superposition that you try to measure.Therefore, you can continue to put more gates after a
measure(int)
as well: the state was not changed (it WAS however entangled with the measured
"classical" bit).As a result, you do not need any "shots" (run the circuit many times to get approximate
statistics). The statistics on chance of the measurements are simply calculated in parallel,
using the normal quantum computer power of doing things in parallel.## Accuracy, round off errors and noise.
THIS IMPLEMENTATION HAS NO NOISE, AND NO ROUND OFF ERRORS.
This implementation uses a field extension to the rationals, for which GMP is used
for infinite accuracy. Hence, the results are infinitely precise.For example, the above circuit results in the following output:
0₁0₀: (1/4 + 1/4·i - 1/2·i·√½)·|0₁0₀⟩ Chance: 1/4 - 1/4·√½
1₁0₀: (1/4 + 1/4·i + 1/2·i·√½)·|0₁1₀⟩ Chance: 1/4 + 1/4·√½
0₁1₀: (1/4 - 1/4·i + 1/2·√½)·|1₁0₀⟩ Chance: 1/4 + 1/4·√½
1₁1₀: (1/4 - 1/4·i - 1/2·√½)·|1₁1₀⟩ Chance: 1/4 - 1/4·√½where in the left column, before the colon, you see the possible classical
measurements for classical bits 0 and 1, and on the right the exact chance.
In the middle you see the corresponding (collapsed) wave function of
the circuit that belongs to that reality.## Installation
As usual, I only support linux. If you use something else then you're on your own;
although, I mostly use standard C++ - so porting shouldn't be hard for another
developer.To install this project out-of-the-box you will need to have GNU
[autotools](https://en.wikipedia.org/wiki/GNU_Build_System_autotools) installed.
In order to see debug output, you need to have [libcwd](https://github.com/CarloWood/libcwd)
compiled and installed.This project uses git submodules. To clone this project, have the above installed and simply run:
git clone --recursive https://github.com/CarloWood/quantum.git
cd quantum
./autogen.shAfter that it is the usual,
./configure
makeassuming you're familiar with GNU autotool projects.