QVNT
Advanced quantum computation simulator, written in Rust
Features
- Ability to simulate up to 64 qubits. Common machine with 4-16 Gb of RAM is able to simulate 26-28 qubits, which is enough for several study cases;
- Set of 1- or 2-qubits operations to build your own quantum circuits;
- Quantum operations are tested and debugged to be safe in use;
- Circuit execution is accelerated using multithreading Rayon library;
- Complex quantum registers manipulations: tensor product of two registers and aliases for qubit to simplify interaction with register.
Usage
Add this lines to your Cargo.toml file to use QVNT crate:
[]
= { = "https://github.com/MucTepDayH16/qvnt", = "qasm_interpreter", = ["interpreter"] }
Quantum register and operators are controlled by bitmasks. Each bit in it will act on a specific qubit.
use *;
// Create quantum register with 10 qubits
let mut q_reg = new;
// or with initial state, where 5th, 6th and 7th qubits are already in state |1>.
let mut q_reg = new.init_state;
// Create qft (Quantum Fourier Transform) operation, acting on first 5 qubits in q_reg.
let op = qft;
// Apply created operation
q_reg.apply;
// Measure and write first 3 qubit, which leads to collapse of q_reg wave function.
// Measured variable will contain one of the following values:
// 0b000, 0b001, 0b010, 0b011, 0b100, 0b101, 0b110, 0b111
let measured = q_reg.measure_mask;
You're able to use VReg to simplify operations definition:
use *;
let mut q_reg = new;
let q = q_reg.get_vreg;
// Crate Hadamard operator, that act on odd qubits.
let op = h;
// This is equivalent to op::h(0b0101010101);
Implemented operations
- Pauli's X, Y & Z operators;
- Square and fourth root of Z - S & T operators;
- Phase shift operator - phi;
- 1-qubit rotation operators - rx, ry & rz;
- 2-qubits rotation operators, aka Ising coupling gates, - rxx, ryy & rzz;
- SWAP, iSWAP operators and square rooted ones;
- Quantum Fourier and Hadamard Transform;
- Universal U1, U2 and U3 operators;
ALL operators have inverse versions, accessing by .dgr() method:
use *;
let usual_op = s;
// Inverse S operator
let inverse_op = s.dgr;
Also, ALL these operators could be turned into controlled ones, using .c(...) method:
use *;
let usual_op = x;
// NOT gate, controlled by 2 qubits, aka CCNOT gate, aka Toffoli gate
let controlled_op = x.c.unwrap;
Controlled operation has to be unwrapped, since it could be None if its mask overlaps with the mask of operator. For example, this code will panic:
use *;
let _ = x.c.unwrap;
QVNT interpreter
About
It is REPL interpreter, that could be used to process quantum operation without compiling code.
Installation:
cargo install qvnt --bin qvnt-i --features=cli
How to
Now, you are able to 'run' quantum simulator with OpenQASM language.
*.qasm files should be passed to interpreter via cli:
qvnt-i --input ./cirquit.qasm
|Q> :go
or via interpreter:
qvnt-i
|Q> :load ./cirquit.qasm
|Q> :go
Another way of running simulator is writing cirquit on OpenQASM language directly in REPL:
qvnt-i
|Q> qreg q[4];
|Q> creg c[4];
|Q> h q;
|Q> measure q -> c;
|Q> :go
|Q> :class
:go- process the simulation;:class- acquire the result from classical register.
REPL is lazy: it only starts computation, if it encounters :go.
This example will shows the single number every time:
|Q> qreg q[4];
|Q> creg c[4];
|Q> h q;
|Q> measure q -> c;
|Q> :go
|Q> :class
|Q> :class
|Q> :class
|Q> :class
...
Unlike that, repeating :go will proceed with different result every time:
|Q> qreg q[4];
|Q> creg c[4];
|Q> h q;
|Q> measure q -> c;
|Q> :go
|Q> :class
|Q> :go
|Q> :class
|Q> :go
|Q> :class
...
Commands
All commands should be preceeded with :.
Otherwise, REPL considers to parse line as OpenQASM source.
The full list of commands:
loop N Repeat following commands N time
tags TAG Create TAG with current state
goto TAG Swap current state to TAG's state
class Show state of classical registers
polar Show state of quantum registers in polar form
prob Show state of quantum registers in probability form
ops Snow current quantum operations queue
go Start modulating quantum computer
reset Clear current state
names Show aliases for quantum and classical bits
load FILE Load state from FILE according to QASM language script
help Show this reference
quit Exit interpreter
License
Licensed under MIT License