[][src]Trait qip::qubits::UnitaryBuilder

pub trait UnitaryBuilder {
    fn with_context(&mut self, q: Qubit) -> ConditionalContextBuilder;
fn mat(
        &mut self,
        name: &str,
        q: Qubit,
        mat: Vec<Complex<f64>>
    ) -> Result<Qubit, &'static str>;
fn sparse_mat(
        &mut self,
        name: &str,
        q: Qubit,
        mat: Vec<Vec<(u64, Complex<f64>)>>,
        natural_order: bool
    ) -> Result<Qubit, &'static str>;
fn apply_function(
        &mut self,
        q_in: Qubit,
        q_out: Qubit,
        f: Box<dyn Fn(u64) -> (u64, f64) + Send + Sync>
    ) -> Result<(Qubit, Qubit), &'static str>;
fn split_absolute(
        &mut self,
        q: Qubit,
        selected_indices: Vec<u64>
    ) -> Result<(Qubit, Qubit), &'static str>;
fn merge_with_op(
        &mut self,
        qs: Vec<Qubit>,
        named_operator: Option<(String, QubitOp)>
    ) -> Qubit;
fn stochastic_measure(&mut self, q: Qubit) -> (Qubit, u64);
fn sidechannel_helper(
        &mut self,
        qs: Vec<Qubit>,
        handles: &[MeasurementHandle],
        f: Box<dyn Fn(&mut dyn UnitaryBuilder, Qubit, &[u64]) -> Result<Vec<Qubit>, &'static str>>
    ) -> Vec<Qubit>; fn real_mat(
        &mut self,
        name: &str,
        q: Qubit,
        mat: &[f64]
    ) -> Result<Qubit, &'static str> { ... }
fn sparse_mat_from_fn(
        &mut self,
        name: &str,
        q: Qubit,
        f: Box<dyn Fn(u64) -> Vec<(u64, Complex<f64>)>>,
        natural_order: bool
    ) -> Result<Qubit, &'static str> { ... }
fn real_sparse_mat(
        &mut self,
        name: &str,
        q: Qubit,
        mat: &[Vec<(u64, f64)>],
        natural_order: bool
    ) -> Result<Qubit, &'static str> { ... }
fn not(&mut self, q: Qubit) -> Qubit { ... }
fn x(&mut self, q: Qubit) -> Qubit { ... }
fn y(&mut self, q: Qubit) -> Qubit { ... }
fn z(&mut self, q: Qubit) -> Qubit { ... }
fn hadamard(&mut self, q: Qubit) -> Qubit { ... }
fn swap(
        &mut self,
        qa: Qubit,
        qb: Qubit
    ) -> Result<(Qubit, Qubit), &'static str> { ... }
fn merge(&mut self, qs: Vec<Qubit>) -> Qubit { ... }
fn split(
        &mut self,
        q: Qubit,
        indices: Vec<u64>
    ) -> Result<(Qubit, Qubit), &'static str> { ... }
fn split_absolute_many(
        &mut self,
        q: Qubit,
        index_groups: Vec<Vec<u64>>
    ) -> Result<(Vec<Qubit>, Option<Qubit>), &'static str> { ... }
fn split_all(&mut self, q: Qubit) -> Vec<Qubit> { ... }
fn make_mat_op(
        &self,
        q: &Qubit,
        data: Vec<Complex<f64>>
    ) -> Result<QubitOp, &'static str> { ... }
fn make_sparse_mat_op(
        &self,
        q: &Qubit,
        data: Vec<Vec<(u64, Complex<f64>)>>,
        natural_order: bool
    ) -> Result<QubitOp, &'static str> { ... }
fn make_swap_op(
        &self,
        qa: &Qubit,
        qb: &Qubit
    ) -> Result<QubitOp, &'static str> { ... }
fn make_function_op(
        &self,
        q_in: &Qubit,
        q_out: &Qubit,
        f: Box<dyn Fn(u64) -> (u64, f64) + Send + Sync>
    ) -> Result<QubitOp, &'static str> { ... }
fn single_qubit_classical_sidechannel(
        &mut self,
        q: Qubit,
        handles: &[MeasurementHandle],
        f: Box<dyn Fn(&mut dyn UnitaryBuilder, Qubit, &[u64]) -> Result<Qubit, &'static str>>
    ) -> Qubit { ... }
fn classical_sidechannel(
        &mut self,
        qs: Vec<Qubit>,
        handles: &[MeasurementHandle],
        f: Box<dyn Fn(&mut dyn UnitaryBuilder, Vec<Qubit>, &[u64]) -> Result<Vec<Qubit>, &'static str>>
    ) -> Vec<Qubit> { ... } }

A builder which support unitary operations

Required methods

fn with_context(&mut self, q: Qubit) -> ConditionalContextBuilder

Build a builder which uses q as context.

fn mat(
    &mut self,
    name: &str,
    q: Qubit,
    mat: Vec<Complex<f64>>
) -> Result<Qubit, &'static str>

Build a generic matrix op, apply to q, if q is multiple indices and mat is 2x2, apply to each index, otherwise returns an error if the matrix is not the correct size for the number of indices in q (mat.len() == 2^(2n)).

fn sparse_mat(
    &mut self,
    name: &str,
    q: Qubit,
    mat: Vec<Vec<(u64, Complex<f64>)>>,
    natural_order: bool
) -> Result<Qubit, &'static str>

Build a sparse matrix op, apply to q, if q is multiple indices and mat is 2x2, apply to each index, otherwise returns an error if the matrix is not the correct size for the number of indices in q (mat.len() == 2^n).

fn apply_function(
    &mut self,
    q_in: Qubit,
    q_out: Qubit,
    f: Box<dyn Fn(u64) -> (u64, f64) + Send + Sync>
) -> Result<(Qubit, Qubit), &'static str>

Make an operation from the boxed function f. This maps c|q_in>|q_out> to c*e^itheta|q_in>|q_out ^ indx> where indx and theta are the outputs from the function f(x) = (indx, theta)

fn split_absolute(
    &mut self,
    q: Qubit,
    selected_indices: Vec<u64>
) -> Result<(Qubit, Qubit), &'static str>

Split the qubit q into two qubits, one with selected_indices and one with the remaining.

fn merge_with_op(
    &mut self,
    qs: Vec<Qubit>,
    named_operator: Option<(String, QubitOp)>
) -> Qubit

Merge qubits using a generic state processing function.

fn stochastic_measure(&mut self, q: Qubit) -> (Qubit, u64)

Measure all qubit states and probabilities, does not edit state (thus Unitary). Returns qubit and handle.

fn sidechannel_helper(
    &mut self,
    qs: Vec<Qubit>,
    handles: &[MeasurementHandle],
    f: Box<dyn Fn(&mut dyn UnitaryBuilder, Qubit, &[u64]) -> Result<Vec<Qubit>, &'static str>>
) -> Vec<Qubit>

Loading content...

Provided methods

fn real_mat(
    &mut self,
    name: &str,
    q: Qubit,
    mat: &[f64]
) -> Result<Qubit, &'static str>

Build a matrix op from real numbers, apply to q, if q is multiple indices and mat is 2x2, apply to each index, otherwise returns an error if the matrix is not the correct size for the number of indices in q (mat.len() == 2^(2n)).

fn sparse_mat_from_fn(
    &mut self,
    name: &str,
    q: Qubit,
    f: Box<dyn Fn(u64) -> Vec<(u64, Complex<f64>)>>,
    natural_order: bool
) -> Result<Qubit, &'static str>

fn real_sparse_mat(
    &mut self,
    name: &str,
    q: Qubit,
    mat: &[Vec<(u64, f64)>],
    natural_order: bool
) -> Result<Qubit, &'static str>

Build a sparse matrix op from real numbers, apply to q, if q is multiple indices and mat is 2x2, apply to each index, otherwise returns an error if the matrix is not the correct size for the number of indices in q (mat.len() == 2^n).

fn not(&mut self, q: Qubit) -> Qubit

Apply NOT to q, if q is multiple indices, apply to each

fn x(&mut self, q: Qubit) -> Qubit

Apply X to q, if q is multiple indices, apply to each

fn y(&mut self, q: Qubit) -> Qubit

Apply Y to q, if q is multiple indices, apply to each

fn z(&mut self, q: Qubit) -> Qubit

Apply Z to q, if q is multiple indices, apply to each

fn hadamard(&mut self, q: Qubit) -> Qubit

Apply H to q, if q is multiple indices, apply to each

fn swap(&mut self, qa: Qubit, qb: Qubit) -> Result<(Qubit, Qubit), &'static str>

Apply SWAP to qa and qb

fn merge(&mut self, qs: Vec<Qubit>) -> Qubit

Merge the qubits in qs into a single qubit.

fn split(
    &mut self,
    q: Qubit,
    indices: Vec<u64>
) -> Result<(Qubit, Qubit), &'static str>

Split the qubit q into two qubits, one with relative indices and one with the remaining.

fn split_absolute_many(
    &mut self,
    q: Qubit,
    index_groups: Vec<Vec<u64>>
) -> Result<(Vec<Qubit>, Option<Qubit>), &'static str>

Split the qubit into many qubits, each with the given set of indices.

fn split_all(&mut self, q: Qubit) -> Vec<Qubit>

Split q into a single qubit for each index.

fn make_mat_op(
    &self,
    q: &Qubit,
    data: Vec<Complex<f64>>
) -> Result<QubitOp, &'static str>

Build a generic matrix op.

fn make_sparse_mat_op(
    &self,
    q: &Qubit,
    data: Vec<Vec<(u64, Complex<f64>)>>,
    natural_order: bool
) -> Result<QubitOp, &'static str>

Build a sparse matrix op

fn make_swap_op(&self, qa: &Qubit, qb: &Qubit) -> Result<QubitOp, &'static str>

Build a swap op. qa and qb must have the same number of indices.

fn make_function_op(
    &self,
    q_in: &Qubit,
    q_out: &Qubit,
    f: Box<dyn Fn(u64) -> (u64, f64) + Send + Sync>
) -> Result<QubitOp, &'static str>

Make a function op. f must be boxed so that this function doesn't need to be parameterized.

fn single_qubit_classical_sidechannel(
    &mut self,
    q: Qubit,
    handles: &[MeasurementHandle],
    f: Box<dyn Fn(&mut dyn UnitaryBuilder, Qubit, &[u64]) -> Result<Qubit, &'static str>>
) -> Qubit

Create a circuit portion which depends on the classical results of measuring some qubits.

fn classical_sidechannel(
    &mut self,
    qs: Vec<Qubit>,
    handles: &[MeasurementHandle],
    f: Box<dyn Fn(&mut dyn UnitaryBuilder, Vec<Qubit>, &[u64]) -> Result<Vec<Qubit>, &'static str>>
) -> Vec<Qubit>

Create a circuit portion which depends on the classical results of measuring some qubits.

Loading content...

Implementors

impl UnitaryBuilder for OpBuilder[src]

impl<'a> UnitaryBuilder for ConditionalContextBuilder<'a>[src]

Loading content...