Struct qcgpu::State
[−]
[src]
pub struct State { pub buffer: Buffer<Complex32>, pub num_amps: usize, pub num_qubits: u32, pub backend: usize, // some fields omitted }
Representation of a quantum register
Fields
buffer: Buffer<Complex32>
The OpenCL Buffer for the state vector
num_amps: usize
Number of amplitudes stored in the state vector
num_qubits: u32
Number of qubits in the register
backend: usize
The OpenCL Backend used. Use the method info()
to get the devices identifier
Methods
impl State
[src]
pub fn new(num_qubits: u32, backend: usize) -> State
[src]
Create a new quantum register, with a given number of qubits. The backend is the OpenCL ID of the accelerator to use.
The register will be initialized in the state |00...0>
let state = qcgpu::State::new(2,0);
pub fn from_bit_string(bit_string: &str, backend: usize) -> State
[src]
Create a new quantum register, starting in the State given. The backend is the OpenCL ID of the accelerator to use.
let state = qcgpu::State::from_bit_string("|00>", 1);
pub fn apply_gate(&mut self, target: i32, gate: Gate)
[src]
Apply a gate to the target qubit
pub fn apply_all(&mut self, gate: Gate)
[src]
Apply a gate to every qubit in the register
pub fn apply_controlled_gate(&mut self, control: i32, target: i32, gate: Gate)
[src]
Apply a gate to the register if the control qubit is 1.
pub fn get_probabilities(&mut self) -> Vec<f32>
[src]
Return the probabilities of each outcome.
The probabilitity of a state a|x> being measured is |a|^2.
pub fn get_amplitudes(&mut self) -> Vec<Complex32>
[src]
Return the state vector of the quantum register
pub fn measure(&mut self) -> i32
[src]
Measure the quantum register, returning the measured result
pub fn measure_many(&mut self, num_iterations: i32) -> HashMap<String, i32>
[src]
Preform multiple measurements, returning the results as a HashMap, with the key as the result and the value as the number of times that result was measured
pub fn add_scratch(&mut self, num_scratch: u32)
[src]
Add qubits to the register. The qubits are initialized to zero. This should be used as scratch space.
pub fn measure_scratch(&mut self, num_to_measure: u32)
[src]
Measure the scratch qubits. The measurement is discarded, and
the register size is reduced by num_to_measure
qubits.
pub fn measure_first(
&mut self,
num_to_measure: i32,
num_iterations: i32
) -> HashMap<String, i32>
[src]
&mut self,
num_to_measure: i32,
num_iterations: i32
) -> HashMap<String, i32>
Preform multiple measurements of the first num_to_measure
, returning the results
as a HashMap, with the key as the result and the value as the
number of times that result was measured
pub fn info(&self)
[src]
Print Information About The Device
pub fn h(&mut self, target: i32)
[src]
Hadamard Gate Shorthand Method
Equivilent to state.apply_gate(target, h());
pub fn s(&mut self, target: i32)
[src]
S Gate Shorthand Method
Equivilent to state.apply_gate(target, s());
pub fn t(&mut self, target: i32)
[src]
T Gate Shorthand Method
Equivilent to state.apply_gate(target, t());
pub fn x(&mut self, target: i32)
[src]
Pauli X Gate Shorthand Method
Equivilent to state.apply_gate(target, x());
pub fn y(&mut self, target: i32)
[src]
Pauli Y Gate Shorthand Method
Equivilent to state.apply_gate(target, y());
pub fn z(&mut self, target: i32)
[src]
Pauli Z Gate Shorthand Method
Equivilent to state.apply_gate(target, z());
pub fn cx(&mut self, control: i32, target: i32)
[src]
Controlled Not Gate Shorthand method
Equivilent to state.apply_controlled_gate(control, target, x());
pub fn toffoli(&mut self, control1: i32, control2: i32, target: i32)
[src]
Toffoli (Controlled-Controlled-NOT gate) Shorthand method
pub fn swap(&mut self, first_qubit: i32, second_qubit: i32)
[src]
Swap two qubits in the register
pub fn pow_mod(&mut self, x: i32, n: i32, input_width: i32, output_width: i32)
[src]
Caclulates f(a) = x^a mod n.
Trait Implementations
impl Debug for State
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more