Struct qvnt::register::QReg

source ·
pub struct QReg { /* private fields */ }
Expand description

Quantum register

The heart of QVNT crate. It represents a set of entangle qubits, their collective wavefunction and techniques for controlling quantum state.

Theoretically it could contain up to 64 qubits, however it would require more than 2_000_000 Terabytes of RAM. For a common computer with 4Gb RAM the limitation is 26 qubits. If you have more than 4Gb just remember, that 1 additional qubit require twice more RAM. More precise formula is:

MAX_QUBIT_COUNT = 24 + log2(MEM_CAPACITY_IN_GB)

For practice purposes it will be enough.

To create quantum computer state, e.g. with 10 qubits, you can use this code:

use qvnt::prelude::*;

let q = QReg::new(10);

The quantum register q starts with state |0>. To vary initial state of register, you may use with_state modifier:

// it will create quantum register in state |123>
let q = QReg::with_state(10, 123);

After creation of quantum computer you would like to be able to control its state. QVNT provide op module, which contains an amount of quantum gates. QReg::apply() method is to apply sorry for tautology :) them:

// quantum gates change state, so register must be mutable
let mut q = QReg::new(2);

// controlled gates have to be unwrapped
let gate =  op::h(0b01) * op::x(0b10).c(0b01).unwrap();
q.apply(&gate);

This is the example of entangled state, which means that if we will apply gate on or measure first(second) qubit, second(first) will change it state automatically. To show that, we will use get_probabilities method. It could show us the probabilities of each state in quantum register:

let mut q = QReg::new(2);
q.apply(&gate);
let prob: Vec<f64> = q.get_probabilities();
println!("{:?}", prob);

Output will be [0.5, 0.0, 0.0, 0.5], which means that quantum state consists only of states |00> and |11>. Thus, measuring first qubit (|_0> or |_1> will always collapse second qubit to the same value. So, this example is just a complicated version if flipping a coin example.

Implementations

Create quantum register with a given number of bits. Initial value will be set to 0.

Create quantum register with a given number of bits and an initial state

Acquire the VReg for a whole quantum register.

Acquire the VReg for a specified part of quantum register.

Apply quantum gate to register. This method only works in single threading model. To accelerate it you may use [apply_sync].

Return complex amplitudes of quantum states of register in polar form.

Return probabilities of quantum states of register.

Return absolute value of wavefunction of quantum register. If you use gates from op module, it always will be 1.

Measure specified qubits into classical register. Wavefunction of quantum register will collapse after measurement.

Measure all qubits into classical register. Wavefunction of quantum register will collapse after measurement.

Make a histogram for quantum register. This histogram also could be obtained by calling measure count times. But sample_all does not collapse wavefunction and executes MUSH FASTER. If you want to simulate the execution of quantum computer, you would prefer sample_all.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
Performs the *= operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.