Skip to content

CarloWood/quantum

Repository files navigation

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 compsed. 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 for a list of all standard gates). co(int) is the control input of a controlled CNOT while CX(int) with the same int, is the corresponding controlled input. Finally, measure(int) measures to classical bit int. You must specify the number of qubits and classical bits at the moment you create q.

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 installed. In order to see debug output, you need to have 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.sh

After that it is the usual,

./configure
make

assuming you're familiar with GNU autotool projects.