[−][src]Trait qip::builders::UnitaryBuilder
A builder which support unitary operations
Required methods
fn with_condition(&mut self, r: Register) -> ConditionalContextBuilder
Build a builder which uses r
as a condition.
fn push_name_scope(&mut self, name: &str)
Add a name scope.
fn pop_name_scope(&mut self) -> Option<String>
Remove and return a name scope.
fn get_name_list(&self) -> &[String]
Get list of names in above scopes.
fn mat(
&mut self,
name: &str,
r: Register,
mat: Vec<Complex<f64>>
) -> Result<Register, CircuitError>
&mut self,
name: &str,
r: Register,
mat: Vec<Complex<f64>>
) -> Result<Register, CircuitError>
Build a generic matrix op, apply to r
, if r
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 r
(mat.len() == 2^(2n)).
fn sparse_mat(
&mut self,
name: &str,
r: Register,
mat: Vec<Vec<(u64, Complex<f64>)>>,
natural_order: bool
) -> Result<Register, CircuitError>
&mut self,
name: &str,
r: Register,
mat: Vec<Vec<(u64, Complex<f64>)>>,
natural_order: bool
) -> Result<Register, CircuitError>
Build a sparse matrix op, apply to r
, if r
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 r
(mat.len() == 2^n).
fn apply_function(
&mut self,
name: &str,
r_in: Register,
r_out: Register,
f: Box<dyn Fn(u64) -> (u64, f64) + Send + Sync>
) -> Result<(Register, Register), CircuitError>
&mut self,
name: &str,
r_in: Register,
r_out: Register,
f: Box<dyn Fn(u64) -> (u64, f64) + Send + Sync>
) -> Result<(Register, Register), CircuitError>
Make an operation from the boxed function f
. This maps c|r_in
>|r_out
> to
c*e^itheta
|r_in
>|r_out
^ indx
> where indx
and theta
are the outputs from the
function f(x) = (indx, theta)
fn split_absolute(
&mut self,
r: Register,
selected_indices: &[u64]
) -> Result<(Register, Register), CircuitError>
&mut self,
r: Register,
selected_indices: &[u64]
) -> Result<(Register, Register), CircuitError>
Split the Register r
into two Registers, one with selected_indices
and one with the remaining.
fn merge_with_op(
&mut self,
rs: Vec<Register>,
named_operator: Option<(String, UnitaryOp)>
) -> Result<Register, CircuitError>
&mut self,
rs: Vec<Register>,
named_operator: Option<(String, UnitaryOp)>
) -> Result<Register, CircuitError>
Merge Registers using a generic state processing function.
fn stochastic_measure(&mut self, r: Register) -> (Register, u64)
Measure all Register states and probabilities, does not edit state (thus Unitary). Returns Register and handle.
fn sidechannel_helper(
&mut self,
rs: Vec<Register>,
handles: &[MeasurementHandle],
f: Box<dyn Fn(&mut dyn UnitaryBuilder, Register, &[u64]) -> Result<Vec<Register>, CircuitError>>
) -> Vec<Register>
&mut self,
rs: Vec<Register>,
handles: &[MeasurementHandle],
f: Box<dyn Fn(&mut dyn UnitaryBuilder, Register, &[u64]) -> Result<Vec<Register>, CircuitError>>
) -> Vec<Register>
A helper function for the classical_sidechannel. Takes a set of Registers 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 Registers whose indices
match those of the input Registers.
This shouldn't be called in circuits, and is a helper to classical_sidechannel
and
single_register_classical_sidechannel
.
Provided methods
fn get_full_name(&self, name: &str) -> String
Get the full name with scope
fn real_mat(
&mut self,
name: &str,
r: Register,
mat: &[f64]
) -> Result<Register, CircuitError>
&mut self,
name: &str,
r: Register,
mat: &[f64]
) -> Result<Register, CircuitError>
Build a matrix op from real numbers, apply to r
, if r
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 r
(mat.len() == 2^(2n)).
fn sparse_mat_from_fn(
&mut self,
name: &str,
r: Register,
f: Box<dyn Fn(u64) -> Vec<(u64, Complex<f64>)>>,
natural_order: bool
) -> Result<Register, CircuitError>
&mut self,
name: &str,
r: Register,
f: Box<dyn Fn(u64) -> Vec<(u64, Complex<f64>)>>,
natural_order: bool
) -> Result<Register, CircuitError>
Build a sparse matrix op from f
, apply to r
, if r
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 r
(mat.len() == 2^n).
fn real_sparse_mat(
&mut self,
name: &str,
r: Register,
mat: &[Vec<(u64, f64)>],
natural_order: bool
) -> Result<Register, CircuitError>
&mut self,
name: &str,
r: Register,
mat: &[Vec<(u64, f64)>],
natural_order: bool
) -> Result<Register, CircuitError>
Build a sparse matrix op from real numbers, apply to r
, if r
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 r
(mat.len() == 2^n).
fn not(&mut self, r: Register) -> Register
Apply NOT to r
, if r
is multiple indices, apply to each
fn x(&mut self, r: Register) -> Register
Apply X to r
, if r
is multiple indices, apply to each
fn y(&mut self, r: Register) -> Register
Apply Y to r
, if r
is multiple indices, apply to each
fn z(&mut self, r: Register) -> Register
Apply Z to r
, if r
is multiple indices, apply to each
fn hadamard(&mut self, r: Register) -> Register
Apply H to r
, if r
is multiple indices, apply to each
fn phase(&mut self, r: Register, theta: f64) -> Register
Transforms |psi>
to e^{i*theta}|psi>
fn swap(
&mut self,
ra: Register,
rb: Register
) -> Result<(Register, Register), CircuitError>
&mut self,
ra: Register,
rb: Register
) -> Result<(Register, Register), CircuitError>
Apply SWAP to ra
and rb
fn cx(&mut self, cr: Register, r: Register) -> (Register, Register)
A controlled x, using cr
as control and r
as input.
fn cy(&mut self, cr: Register, r: Register) -> (Register, Register)
A controlled y, using cr
as control and r
as input.
fn cz(&mut self, cr: Register, r: Register) -> (Register, Register)
A controlled z, using cr
as control and r
as input.
fn cnot(&mut self, cr: Register, r: Register) -> (Register, Register)
A controlled not, using cr
as control and r
as input.
fn cswap(
&mut self,
cr: Register,
ra: Register,
rb: Register
) -> Result<(Register, Register, Register), CircuitError>
&mut self,
cr: Register,
ra: Register,
rb: Register
) -> Result<(Register, Register, Register), CircuitError>
Swap ra
and rb
controlled by cr
.
fn cmat(
&mut self,
name: &str,
cr: Register,
r: Register,
mat: Vec<Complex<f64>>
) -> Result<(Register, Register), CircuitError>
&mut self,
name: &str,
cr: Register,
r: Register,
mat: Vec<Complex<f64>>
) -> Result<(Register, Register), CircuitError>
Apply a unitary matrix to the register. If mat is 2x2 then can broadcast to all qubits.
fn crealmat(
&mut self,
name: &str,
cr: Register,
r: Register,
mat: &[f64]
) -> Result<(Register, Register), CircuitError>
&mut self,
name: &str,
cr: Register,
r: Register,
mat: &[f64]
) -> Result<(Register, Register), CircuitError>
Apply a orthonormal matrix to the register. If mat is 2x2 then can broadcast to all qubits.
fn merge(&mut self, rs: Vec<Register>) -> Result<Register, CircuitError>
Merge the Registers in rs
into a single Register.
fn split(
&mut self,
r: Register,
indices: &[u64]
) -> Result<(Register, Register), CircuitError>
&mut self,
r: Register,
indices: &[u64]
) -> Result<(Register, Register), CircuitError>
Split the Register r
into two Registers, one with relative indices
and one with the remaining.
fn split_absolute_many(
&mut self,
r: Register,
index_groups: &[Vec<u64>]
) -> Result<(Vec<Register>, Option<Register>), CircuitError>
&mut self,
r: Register,
index_groups: &[Vec<u64>]
) -> Result<(Vec<Register>, Option<Register>), CircuitError>
Split the Register into many Registers, each with the given set of indices.
fn split_all(&mut self, r: Register) -> Vec<Register>
Split r
into a single Register for each index.
fn make_mat_op(
&self,
r: &Register,
data: Vec<Complex<f64>>
) -> Result<UnitaryOp, CircuitError>
&self,
r: &Register,
data: Vec<Complex<f64>>
) -> Result<UnitaryOp, CircuitError>
Build a generic matrix op.
fn make_sparse_mat_op(
&self,
r: &Register,
data: Vec<Vec<(u64, Complex<f64>)>>,
natural_order: bool
) -> Result<UnitaryOp, CircuitError>
&self,
r: &Register,
data: Vec<Vec<(u64, Complex<f64>)>>,
natural_order: bool
) -> Result<UnitaryOp, CircuitError>
Build a sparse matrix op
fn make_swap_op(
&self,
ra: &Register,
rb: &Register
) -> Result<UnitaryOp, CircuitError>
&self,
ra: &Register,
rb: &Register
) -> Result<UnitaryOp, CircuitError>
Build a swap op. ra and rb must have the same number of indices.
fn make_function_op(
&self,
r_in: &Register,
r_out: &Register,
f: Box<dyn Fn(u64) -> (u64, f64) + Send + Sync>
) -> Result<UnitaryOp, CircuitError>
&self,
r_in: &Register,
r_out: &Register,
f: Box<dyn Fn(u64) -> (u64, f64) + Send + Sync>
) -> Result<UnitaryOp, CircuitError>
Make a function op. f must be boxed so that this function doesn't need to be parameterized.
fn merge_with_indices(
&mut self,
into: Register,
qubits: Vec<Register>,
at_indices: &[u64]
) -> Result<Register, CircuitError>
&mut self,
into: Register,
qubits: Vec<Register>,
at_indices: &[u64]
) -> Result<Register, CircuitError>
Merge a set of qubits into a given qubit at a set of indices
fn merge_with(
&mut self,
into: Register,
qubit_and_index: Vec<(Register, u64)>
) -> Result<Register, CircuitError>
&mut self,
into: Register,
qubit_and_index: Vec<(Register, u64)>
) -> Result<Register, CircuitError>
Merge a set of qubits into a given qubit at a set of indices
fn single_register_classical_sidechannel(
&mut self,
r: Register,
handles: &[MeasurementHandle],
f: Box<dyn Fn(&mut dyn UnitaryBuilder, Register, &[u64]) -> Result<Register, CircuitError>>
) -> Register
&mut self,
r: Register,
handles: &[MeasurementHandle],
f: Box<dyn Fn(&mut dyn UnitaryBuilder, Register, &[u64]) -> Result<Register, CircuitError>>
) -> Register
Create a circuit portion which depends on the classical results of measuring some Registers.
fn classical_sidechannel(
&mut self,
rs: Vec<Register>,
handles: &[MeasurementHandle],
f: Box<dyn Fn(&mut dyn UnitaryBuilder, Vec<Register>, &[u64]) -> Result<Vec<Register>, CircuitError>>
) -> Vec<Register>
&mut self,
rs: Vec<Register>,
handles: &[MeasurementHandle],
f: Box<dyn Fn(&mut dyn UnitaryBuilder, Vec<Register>, &[u64]) -> Result<Vec<Register>, CircuitError>>
) -> Vec<Register>
Create a circuit portion which depends on the classical results of measuring some Registers.
Implementors
impl UnitaryBuilder for OpBuilder
[src]
fn with_condition(&mut self, r: Register) -> ConditionalContextBuilder
[src]
fn push_name_scope(&mut self, name: &str)
[src]
fn pop_name_scope(&mut self) -> Option<String>
[src]
fn get_name_list(&self) -> &[String]
[src]
fn mat(
&mut self,
name: &str,
r: Register,
mat: Vec<Complex<f64>>
) -> Result<Register, CircuitError>
[src]
&mut self,
name: &str,
r: Register,
mat: Vec<Complex<f64>>
) -> Result<Register, CircuitError>
fn sparse_mat(
&mut self,
name: &str,
r: Register,
mat: Vec<Vec<(u64, Complex<f64>)>>,
natural_order: bool
) -> Result<Register, CircuitError>
[src]
&mut self,
name: &str,
r: Register,
mat: Vec<Vec<(u64, Complex<f64>)>>,
natural_order: bool
) -> Result<Register, CircuitError>
fn apply_function(
&mut self,
name: &str,
r_in: Register,
r_out: Register,
f: Box<dyn Fn(u64) -> (u64, f64) + Send + Sync>
) -> Result<(Register, Register), CircuitError>
[src]
&mut self,
name: &str,
r_in: Register,
r_out: Register,
f: Box<dyn Fn(u64) -> (u64, f64) + Send + Sync>
) -> Result<(Register, Register), CircuitError>
fn split_absolute(
&mut self,
r: Register,
selected_indices: &[u64]
) -> Result<(Register, Register), CircuitError>
[src]
&mut self,
r: Register,
selected_indices: &[u64]
) -> Result<(Register, Register), CircuitError>
fn merge_with_op(
&mut self,
rs: Vec<Register>,
named_operator: Option<(String, UnitaryOp)>
) -> Result<Register, CircuitError>
[src]
&mut self,
rs: Vec<Register>,
named_operator: Option<(String, UnitaryOp)>
) -> Result<Register, CircuitError>
fn stochastic_measure(&mut self, r: Register) -> (Register, u64)
[src]
fn sidechannel_helper(
&mut self,
rs: Vec<Register>,
handles: &[MeasurementHandle],
f: Box<dyn Fn(&mut dyn UnitaryBuilder, Register, &[u64]) -> Result<Vec<Register>, CircuitError>>
) -> Vec<Register>
[src]
&mut self,
rs: Vec<Register>,
handles: &[MeasurementHandle],
f: Box<dyn Fn(&mut dyn UnitaryBuilder, Register, &[u64]) -> Result<Vec<Register>, CircuitError>>
) -> Vec<Register>
impl<'a> UnitaryBuilder for ConditionalContextBuilder<'a>
[src]
fn with_condition(&mut self, r: Register) -> ConditionalContextBuilder
[src]
fn push_name_scope(&mut self, name: &str)
[src]
fn pop_name_scope(&mut self) -> Option<String>
[src]
fn get_name_list(&self) -> &[String]
[src]
fn mat(
&mut self,
name: &str,
r: Register,
mat: Vec<Complex<f64>>
) -> Result<Register, CircuitError>
[src]
&mut self,
name: &str,
r: Register,
mat: Vec<Complex<f64>>
) -> Result<Register, CircuitError>
fn sparse_mat(
&mut self,
name: &str,
r: Register,
mat: Vec<Vec<(u64, Complex<f64>)>>,
natural_order: bool
) -> Result<Register, CircuitError>
[src]
&mut self,
name: &str,
r: Register,
mat: Vec<Vec<(u64, Complex<f64>)>>,
natural_order: bool
) -> Result<Register, CircuitError>
fn swap(
&mut self,
ra: Register,
rb: Register
) -> Result<(Register, Register), CircuitError>
[src]
&mut self,
ra: Register,
rb: Register
) -> Result<(Register, Register), CircuitError>
fn apply_function(
&mut self,
name: &str,
r_in: Register,
r_out: Register,
f: Box<dyn Fn(u64) -> (u64, f64) + Send + Sync>
) -> Result<(Register, Register), CircuitError>
[src]
&mut self,
name: &str,
r_in: Register,
r_out: Register,
f: Box<dyn Fn(u64) -> (u64, f64) + Send + Sync>
) -> Result<(Register, Register), CircuitError>
fn split_absolute(
&mut self,
r: Register,
selected_indices: &[u64]
) -> Result<(Register, Register), CircuitError>
[src]
&mut self,
r: Register,
selected_indices: &[u64]
) -> Result<(Register, Register), CircuitError>
fn make_mat_op(
&self,
r: &Register,
data: Vec<Complex<f64>>
) -> Result<UnitaryOp, CircuitError>
[src]
&self,
r: &Register,
data: Vec<Complex<f64>>
) -> Result<UnitaryOp, CircuitError>
fn make_sparse_mat_op(
&self,
r: &Register,
data: Vec<Vec<(u64, Complex<f64>)>>,
natural_order: bool
) -> Result<UnitaryOp, CircuitError>
[src]
&self,
r: &Register,
data: Vec<Vec<(u64, Complex<f64>)>>,
natural_order: bool
) -> Result<UnitaryOp, CircuitError>
fn make_swap_op(
&self,
ra: &Register,
rb: &Register
) -> Result<UnitaryOp, CircuitError>
[src]
&self,
ra: &Register,
rb: &Register
) -> Result<UnitaryOp, CircuitError>
fn make_function_op(
&self,
r_in: &Register,
r_out: &Register,
f: Box<dyn Fn(u64) -> (u64, f64) + Send + Sync>
) -> Result<UnitaryOp, CircuitError>
[src]
&self,
r_in: &Register,
r_out: &Register,
f: Box<dyn Fn(u64) -> (u64, f64) + Send + Sync>
) -> Result<UnitaryOp, CircuitError>
fn merge_with_op(
&mut self,
rs: Vec<Register>,
named_operator: Option<(String, UnitaryOp)>
) -> Result<Register, CircuitError>
[src]
&mut self,
rs: Vec<Register>,
named_operator: Option<(String, UnitaryOp)>
) -> Result<Register, CircuitError>
fn stochastic_measure(&mut self, r: Register) -> (Register, u64)
[src]
fn sidechannel_helper(
&mut self,
rs: Vec<Register>,
handles: &[MeasurementHandle],
f: Box<dyn Fn(&mut dyn UnitaryBuilder, Register, &[u64]) -> Result<Vec<Register>, CircuitError>>
) -> Vec<Register>
[src]
&mut self,
rs: Vec<Register>,
handles: &[MeasurementHandle],
f: Box<dyn Fn(&mut dyn UnitaryBuilder, Register, &[u64]) -> Result<Vec<Register>, CircuitError>>
) -> Vec<Register>