Skip to content

maximkha/QVM

Repository files navigation

QVM

About

QVM is a quantum computer simulator that was written by me in JavaScript. I implemented a custom algorithm to ‘group‘ quantum states so that a single qubit operation on a pair of entangled qubits would function properly. The algorithm is implemented in VecGroup.js

Use

When you open demo.html you will see this:

screenA

The top box is where the QVM instructions go and the bottom box displays the result of the quantum computation. The file a.txt contains an example quantum algorithm(Grover’s algorithm) written by Jonathan Hui transcribed by myself. To run it, paste the contents of a.txt into the top box and press the run button. You should immediately see the bottom box filled with:

Probs: 0,0,0,0,0,0,0.5,0.5 Measure: 0,0,0,1,0,0,0,0

“Probs” is the representation of the probability vector. The vector is always ordered from all binary zeros counting up to all binary ones. The probability vector represents the probability like this:

where

is the probability that qubit 0 is measured as a 1 and qubits 2 and 3 are measured as a 0.

So in turn, interpreting our initial result:

So there is a 100% chance that the output will be `110`. This matches perfectly with Jonathan Hui’s simulation. The only difference is that since he used five qubits instead of the minimum three, he got 100% chance of the output `00110`, the two beginning 0s being the two unused bits. After removing the first two unused bits we get `110` which is exactly what QVM calculated.

Operators

All the operators are case insensitive. All operator parameters are separated with space.

Operator # Input Qubits Extra Parameter Official Name Link Usage Example
H 1 N/A Hammard QINSP, Wikipedia H <Affected Qubit> H 0
X 1 N/A Pauli X, NOT QINSP, Wikipedia X <Affected Qubit> X 0
Y 1 N/A Pauli Y QINSP, Wikipedia Y <Affected Qubit> Y 0
Z 1 N/A Pauli Z QINSP, Wikipedia Z <Affected Qubit> Z 0
SNOT 1 N/A Square Root Not Wikipedia SNOT <Affected Qubit> SNOT 0
SWP 2 N/A Swap QINSP, Wikipedia SWP <Qubit A>,<Qubit B> SWP 0,1
SSWP 2 N/A Square Root Swap Wikipedia SSWP <Qubit A>,<Qubit B> SSWP 0,1
CNOT 2 N/A Controlled Not, Controlled X QINSP, Wikipedia CNOT <Affected Qubit A>,<Control Qubit B> CNOT 1,0
CCNOT 3 N/A Toffoli QINSP, Wikipedia CCNOT <Affected Qubit A>,<Control Qubit B>,<Control Qubit C> CCNOT 2,1,0
CSWP 3 N/A Controlled Swap Wikipedia CSWP <Affected Qubit A>,<Affected Qubit B>,<Control Qubit C> CSWP 2,1,0
S 1 N/A Phase QINSP S <Affected Qubit> S 0
I 1 N/A Identity QINSP I <Affected Qubit> I 0
SDAG 1 N/A S Dagger QINSP SDAG <Affected Qubit> SDAG 0
T 1 N/A T QINSP T <Affected Qubit> T 0
TDAG 1 N/A T Dagger QINSP TDAG <Affected Qubit> TDAG 0
CZ 2 N/A Controlled Phase, CPhase QINSP, Wikipedia CZ CNOT <Affected Qubit A>,<Control Qubit B> CZ 0,1
PHASE 1 , being a multiple of , Phase Shift Wikipedia PHASE <, a multiple of > <Affected Qubit A> PHASE .25 0
XX 2 , being a multiple of Ising (XX) coupling Wikipedia XX <, a multiple of > <Qubit A>,<Qubit B> XX .25 0,1
YY 2 , being a multiple of Ising (YY) coupling Wikipedia YY <, a multiple of > <Qubit A>,<Qubit B> YY .25 0,1
ZZ 2 , being a multiple of Ising (ZZ) coupling Wikipedia ZZ <, a multiple of > <Qubit A>,<Qubit B> ZZ .25 0,1
RX 1 , being a multiple of Rotate X QINSP RX <, a multiple of > <Affected Qubit A> RX .25 0
RY 1 , being a multiple of Rotate Y QINSP RY <, a multiple of > <Affected Qubit A> RY .25 0
RZ 1 , being a multiple of Rotate Z QINSP RZ <, a multiple of > <Affected Qubit A> RZ .25 0
CR 2 , being a multiple of Controlled Phase shift QINSP CR <, a multiple of > <Qubit A>,<Control Qubit B> CR .25 0,1
CRK 2 , being a multiple of Parametrized Controlled Phase shift QINSP CRK <, a multiple of > <Qubit A>,<Control Qubit B> CR .25 0,1
INIT N/A N/A Initialize N/A INIT <Number of Qubits your simulation will use> INIT 1
M N/A N/A Measure N/A M <Qubit Number A>,<Qubit Number B>,<Qubit Number C>… M 0

Releases

No releases published

Packages

No packages published