[−][src]Trait qip::qubits::UnitaryBuilder
A builder which support unitary operations
Required methods
fn with_condition(&mut self, q: Qubit) -> ConditionalContextBuilder
Build a builder which uses q
as a condition.
fn mat(
&mut self,
name: &str,
q: Qubit,
mat: Vec<Complex<f64>>
) -> Result<Qubit, &'static str>
&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>
&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>
&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>
&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
&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>
&mut self,
qs: Vec<Qubit>,
handles: &[MeasurementHandle],
f: Box<dyn Fn(&mut dyn UnitaryBuilder, Qubit, &[u64]) -> Result<Vec<Qubit>, &'static str>>
) -> Vec<Qubit>
A helper function for the classical_sidechannel. Takes a set of qubits to pass to the
subcircuit, a set of handles whose measured values will also be passed, and a function
which matches to description of SideChannelHelperFn
. Returns a set of qubits whose indices
match those of the input qubits.
This shouldn't be called in circuits, and is a helper to classical_sidechannel
and
single_qubit_classical_sidechannel
.
Provided methods
fn real_mat(
&mut self,
name: &str,
q: Qubit,
mat: &[f64]
) -> Result<Qubit, &'static str>
&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>
&mut self,
name: &str,
q: Qubit,
f: Box<dyn Fn(u64) -> Vec<(u64, Complex<f64>)>>,
natural_order: bool
) -> Result<Qubit, &'static str>
Build a sparse matrix op from f
, 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 real_sparse_mat(
&mut self,
name: &str,
q: Qubit,
mat: &[Vec<(u64, f64)>],
natural_order: bool
) -> Result<Qubit, &'static str>
&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 phase(&mut self, q: Qubit, theta: f64) -> Qubit
Transforms |psi>
to e^{i*theta}|psi>
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>
&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>
&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>
&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>
&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>
&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
&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>
&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.
Implementors
impl UnitaryBuilder for OpBuilder
[src]
fn with_condition(&mut self, q: Qubit) -> ConditionalContextBuilder
[src]
fn mat(
&mut self,
name: &str,
q: Qubit,
mat: Vec<Complex<f64>>
) -> Result<Qubit, &'static str>
[src]
&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>
[src]
&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>
[src]
&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>
[src]
&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
[src]
&mut self,
qs: Vec<Qubit>,
named_operator: Option<(String, QubitOp)>
) -> Qubit
fn stochastic_measure(&mut self, q: Qubit) -> (Qubit, u64)
[src]
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>
[src]
&mut self,
qs: Vec<Qubit>,
handles: &[MeasurementHandle],
f: Box<dyn Fn(&mut dyn UnitaryBuilder, Qubit, &[u64]) -> Result<Vec<Qubit>, &'static str>>
) -> Vec<Qubit>
impl<'a> UnitaryBuilder for ConditionalContextBuilder<'a>
[src]
fn with_condition(&mut self, q: Qubit) -> ConditionalContextBuilder
[src]
fn mat(
&mut self,
name: &str,
q: Qubit,
mat: Vec<Complex<f64>>
) -> Result<Qubit, &'static str>
[src]
&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>
[src]
&mut self,
name: &str,
q: Qubit,
mat: Vec<Vec<(u64, Complex<f64>)>>,
natural_order: bool
) -> Result<Qubit, &'static str>
fn swap(&mut self, qa: Qubit, qb: Qubit) -> Result<(Qubit, Qubit), &'static str>
[src]
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>
[src]
&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>
[src]
&mut self,
q: Qubit,
selected_indices: Vec<u64>
) -> Result<(Qubit, Qubit), &'static str>
fn make_mat_op(
&self,
q: &Qubit,
data: Vec<Complex<f64>>
) -> Result<QubitOp, &'static str>
[src]
&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>
[src]
&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>
[src]
fn make_function_op(
&self,
q_in: &Qubit,
q_out: &Qubit,
f: Box<dyn Fn(u64) -> (u64, f64) + Send + Sync>
) -> Result<QubitOp, &'static str>
[src]
&self,
q_in: &Qubit,
q_out: &Qubit,
f: Box<dyn Fn(u64) -> (u64, f64) + Send + Sync>
) -> Result<QubitOp, &'static str>
fn merge_with_op(
&mut self,
qs: Vec<Qubit>,
named_operator: Option<(String, QubitOp)>
) -> Qubit
[src]
&mut self,
qs: Vec<Qubit>,
named_operator: Option<(String, QubitOp)>
) -> Qubit
fn stochastic_measure(&mut self, q: Qubit) -> (Qubit, u64)
[src]
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>
[src]
&mut self,
qs: Vec<Qubit>,
handles: &[MeasurementHandle],
f: Box<dyn Fn(&mut dyn UnitaryBuilder, Qubit, &[u64]) -> Result<Vec<Qubit>, &'static str>>
) -> Vec<Qubit>