Struct qip::builder::LocalBuilder
source · pub struct LocalBuilder<P: Precision> { /* private fields */ }
Expand description
A local circuit builder for constructing circuits out of standard gates. LocalBuilder breaks complicated multi-register gates, like toffoli, into combinations of simple gates like CNOT.
Implementations§
source§impl<P: Precision> LocalBuilder<P>
impl<P: Precision> LocalBuilder<P>
sourcepub fn apply_global_phase(&mut self, r: Qudit, theta: P) -> Qudit
pub fn apply_global_phase(&mut self, r: Qudit, theta: P) -> Qudit
Applies a phase to a qubit. This has no effect by default but has an impact if conditioned.
sourcepub fn apply_global_phase_ratio(&mut self, r: Qudit, theta: Rational64) -> Qudit
pub fn apply_global_phase_ratio(&mut self, r: Qudit, theta: Rational64) -> Qudit
Applied a global phase to a qubit, expressed as a ratio rather than a float.
sourcepub fn apply_global_phase_pi_by(&mut self, r: Qudit, m: i64) -> Qudit
pub fn apply_global_phase_pi_by(&mut self, r: Qudit, m: i64) -> Qudit
Apply a global phase of pi/m for integer m.
sourcepub fn pipeline_depth(&self) -> usize
pub fn pipeline_depth(&self) -> usize
Returns the depth of the current circuit (pipeline).
Trait Implementations§
source§impl<P: Precision> AdvancedCircuitBuilder<P> for LocalBuilder<P>
impl<P: Precision> AdvancedCircuitBuilder<P> for LocalBuilder<P>
source§fn basic_toffoli(
&mut self,
cr: Self::Register,
r: Self::Register
) -> Result<(Self::Register, Self::Register), CircuitError>
fn basic_toffoli( &mut self, cr: Self::Register, r: Self::Register ) -> Result<(Self::Register, Self::Register), CircuitError>
Applies a NOT gate to
r
for the two qubit control state cr = 11
.source§impl<P: Precision> CircuitBuilder for LocalBuilder<P>
impl<P: Precision> CircuitBuilder for LocalBuilder<P>
§type CircuitObject = BuilderCircuitObject<P>
type CircuitObject = BuilderCircuitObject<P>
The struct used to represent circuit objects.
§type StateCalculation = (Vec<Complex<P>, Global>, Measurements<P>)
type StateCalculation = (Vec<Complex<P>, Global>, Measurements<P>)
Return type for state calculations.
source§fn register(&mut self, n: NonZeroUsize) -> Self::Register
fn register(&mut self, n: NonZeroUsize) -> Self::Register
Construct a register with multiple qubits.
source§fn merge_two_registers(
&mut self,
r1: Self::Register,
r2: Self::Register
) -> Self::Register
fn merge_two_registers( &mut self, r1: Self::Register, r2: Self::Register ) -> Self::Register
Merge two registers into a single register with first the r1 indices, then the r2 indices.
source§fn split_register_relative<It>(
&mut self,
r: Self::Register,
indices: It
) -> SplitResult<Self::Register>where
It: IntoIterator<Item = usize>,
fn split_register_relative<It>( &mut self, r: Self::Register, indices: It ) -> SplitResult<Self::Register>where It: IntoIterator<Item = usize>,
Split a register into two, selecting the relative indices from the
indices
iterator.source§fn apply_circuit_object(
&mut self,
r: Self::Register,
c: Self::CircuitObject
) -> CircuitResult<Self::Register>
fn apply_circuit_object( &mut self, r: Self::Register, c: Self::CircuitObject ) -> CircuitResult<Self::Register>
Apply a circuit object to the circuit directly.
source§fn calculate_state_with_init<'a, It>(
&mut self,
it: It
) -> Self::StateCalculationwhere
Self::Register: 'a,
It: IntoIterator<Item = (&'a Self::Register, usize)>,
fn calculate_state_with_init<'a, It>( &mut self, it: It ) -> Self::StateCalculationwhere Self::Register: 'a, It: IntoIterator<Item = (&'a Self::Register, usize)>,
Calculate the state at the end of the circuit using an initial state given by each register
and the classical state in that register.
source§fn qudit(&mut self, n: usize) -> Option<Self::Register>
fn qudit(&mut self, n: usize) -> Option<Self::Register>
Construct a register with multiple qubits. Fails if n=0.
source§fn try_register(&mut self, n: usize) -> Option<Self::Register>
fn try_register(&mut self, n: usize) -> Option<Self::Register>
Construct a register with multiple qubits. Fails if n=0.
source§fn merge_registers<It>(&mut self, rs: It) -> Option<Self::Register>where
It: IntoIterator<Item = Self::Register>,
fn merge_registers<It>(&mut self, rs: It) -> Option<Self::Register>where It: IntoIterator<Item = Self::Register>,
Merge multiple registers together into a single register, returns None if none given.
source§fn split_register_absolute<It>(
&mut self,
r: Self::Register,
indices: It
) -> SplitResult<Self::Register>where
It: IntoIterator<Item = usize>,
fn split_register_absolute<It>( &mut self, r: Self::Register, indices: It ) -> SplitResult<Self::Register>where It: IntoIterator<Item = usize>,
Split a register into two, selecting the indices from the
indices
iterator.source§fn split_all_register(&mut self, r: Self::Register) -> Vec<Self::Register>
fn split_all_register(&mut self, r: Self::Register) -> Vec<Self::Register>
Split the register into
r.n()
individual registers of 1 qubit each.source§fn split_first_qubit(
&mut self,
r: Self::Register
) -> (Option<Self::Register>, Self::Register)
fn split_first_qubit( &mut self, r: Self::Register ) -> (Option<Self::Register>, Self::Register)
Split off the first qubit from the register, returns the optional remaining registers
and the first qubit.
source§fn split_last_qubit(
&mut self,
r: Self::Register
) -> (Self::Register, Option<Self::Register>)
fn split_last_qubit( &mut self, r: Self::Register ) -> (Self::Register, Option<Self::Register>)
Similar to [split_first_qubit] but the last qubit.
source§fn split_relative_index_groups<It: IntoIterator<Item = Itt>, Itt: IntoIterator<Item = usize>>(
&mut self,
r: Self::Register,
indices: It
) -> SplitManyResult<Self::Register>
fn split_relative_index_groups<It: IntoIterator<Item = Itt>, Itt: IntoIterator<Item = usize>>( &mut self, r: Self::Register, indices: It ) -> SplitManyResult<Self::Register>
Split into multiple qubits, each with relative indices given by the sub-iterators. Read more
source§fn calculate_state(&mut self) -> Self::StateCalculation
fn calculate_state(&mut self) -> Self::StateCalculation
Calculate the quantum state at the end of the circuit, using |0> as input.
source§impl<P: Precision> CliffordTBuilder<P> for LocalBuilder<P>
impl<P: Precision> CliffordTBuilder<P> for LocalBuilder<P>
source§fn make_x(&self) -> Self::CircuitObject
fn make_x(&self) -> Self::CircuitObject
Make a circuit object representing the X gate on a single qubit.
Equivalent to calling
matrix_to_circuitobject
with [0, 1, 1, 0]source§fn make_y(&self) -> Self::CircuitObject
fn make_y(&self) -> Self::CircuitObject
Make a circuit object representing the Y gate on a single qubit.
Equivalent to calling
matrix_to_circuitobject
with [0, -i, i, 0]source§fn make_z(&self) -> Self::CircuitObject
fn make_z(&self) -> Self::CircuitObject
Make a circuit object representing the Z gate on a single qubit.
Equivalent to calling
matrix_to_circuitobject
with [1, 0, 0, -1]source§fn make_h(&self) -> Self::CircuitObject
fn make_h(&self) -> Self::CircuitObject
Make a circuit object representing the H gate on a single qubit.
Equivalent to calling
matrix_to_circuitobject
with [1, 1, 1, -1]/sqrt(2)source§fn make_s(&self) -> Self::CircuitObject
fn make_s(&self) -> Self::CircuitObject
Make a circuit object representing the S (phase) gate on a single qubit.
Equivalent to calling
matrix_to_circuitobject
with [1, 0, 0, -i]source§fn make_t(&self) -> Self::CircuitObject
fn make_t(&self) -> Self::CircuitObject
Make a circuit object representing the T gate on a single qubit.
Equivalent to calling
matrix_to_circuitobject
with [1, 0, 0, e^{i pi / 4} ]source§fn make_cnot(&self) -> Self::CircuitObject
fn make_cnot(&self) -> Self::CircuitObject
Make a circuit object representing the CNOT gate on a pair of qubits
Equivalent to calling
matrix_to_circuitobject
with [ I, 0, 0, X ]
where I is the identity matrix and X is the x-gate.source§fn not(&mut self, r: Self::Register) -> Self::Register
fn not(&mut self, r: Self::Register) -> Self::Register
Create and apply an NOT (or X) gate circuit object.
source§fn x(&mut self, r: Self::Register) -> Self::Register
fn x(&mut self, r: Self::Register) -> Self::Register
Create and apply an X (or NOT) gate circuit object.
source§fn y(&mut self, r: Self::Register) -> Self::Register
fn y(&mut self, r: Self::Register) -> Self::Register
Create and apply a Y gate circuit object.
source§fn z(&mut self, r: Self::Register) -> Self::Register
fn z(&mut self, r: Self::Register) -> Self::Register
Create and apply a Z gate circuit object.
source§fn h(&mut self, r: Self::Register) -> Self::Register
fn h(&mut self, r: Self::Register) -> Self::Register
Create and apply an H gate circuit object.
source§fn t(&mut self, r: Self::Register) -> Self::Register
fn t(&mut self, r: Self::Register) -> Self::Register
Create and apply a T gate circuit object.
source§fn t_dagger(&mut self, r: Self::Register) -> Self::Register
fn t_dagger(&mut self, r: Self::Register) -> Self::Register
Create and apply a T^\dagger gate circuit object.
source§fn s(&mut self, r: Self::Register) -> Self::Register
fn s(&mut self, r: Self::Register) -> Self::Register
Create and apply an S gate circuit object.
source§fn s_dagger(&mut self, r: Self::Register) -> Self::Register
fn s_dagger(&mut self, r: Self::Register) -> Self::Register
Create and apply an S^\dagger gate circuit object.
source§impl<P: Precision> Conditionable for LocalBuilder<P>
impl<P: Precision> Conditionable for LocalBuilder<P>
source§fn try_apply_with_condition(
&mut self,
cr: Self::Register,
r: Self::Register,
co: Self::CircuitObject
) -> Result<(Self::Register, Self::Register), CircuitError>
fn try_apply_with_condition( &mut self, cr: Self::Register, r: Self::Register, co: Self::CircuitObject ) -> Result<(Self::Register, Self::Register), CircuitError>
Attempt to condition a circuit object
co
applied to r
with the register cr
.source§fn condition_with(&mut self, cr: Self::Register) -> Conditioned<'_, Self>
fn condition_with(&mut self, cr: Self::Register) -> Conditioned<'_, Self>
Construct a new circuitbuilder which conditions all unitaries with
cr
.source§impl<P: Precision> ConditionableSubcircuit for LocalBuilder<P>
impl<P: Precision> ConditionableSubcircuit for LocalBuilder<P>
source§fn apply_conditioned_subcircuit(
&mut self,
sc: Self::Subcircuit,
cr: Self::Register,
r: Self::Register
) -> Result<(Self::Register, Self::Register), CircuitError>
fn apply_conditioned_subcircuit( &mut self, sc: Self::Subcircuit, cr: Self::Register, r: Self::Register ) -> Result<(Self::Register, Self::Register), CircuitError>
Apply
sc
to register r
using condition cr
.source§impl<P: Default + Precision> Default for LocalBuilder<P>
impl<P: Default + Precision> Default for LocalBuilder<P>
source§fn default() -> LocalBuilder<P>
fn default() -> LocalBuilder<P>
Returns the “default value” for a type. Read more
source§impl<P: Precision> Invertable for LocalBuilder<P>
impl<P: Precision> Invertable for LocalBuilder<P>
§type SimilarBuilder = LocalBuilder<P>
type SimilarBuilder = LocalBuilder<P>
A similar circuit builder which can be used to construct circuits for the parent.
source§fn new_similar(&self) -> Self
fn new_similar(&self) -> Self
Make a similar circuit builder.
source§fn invert_subcircuit(sc: Self::Subcircuit) -> CircuitResult<Self::Subcircuit>
fn invert_subcircuit(sc: Self::Subcircuit) -> CircuitResult<Self::Subcircuit>
Take the output of the similar circuit builder and invert it.
source§fn apply_inverted_subcircuit(
&mut self,
sc: Self::Subcircuit,
r: Self::Register
) -> CircuitResult<Self::Register>
fn apply_inverted_subcircuit( &mut self, sc: Self::Subcircuit, r: Self::Register ) -> CircuitResult<Self::Register>
Apply the inverted subcircuit to a register.
source§impl<P: Precision> MeasurementBuilder for LocalBuilder<P>
impl<P: Precision> MeasurementBuilder for LocalBuilder<P>
§type MeasurementHandle = MeasurementHandle
type MeasurementHandle = MeasurementHandle
Handle which points to measurements.
source§impl<P: Precision> RecursiveCircuitBuilder<P> for LocalBuilder<P>
impl<P: Precision> RecursiveCircuitBuilder<P> for LocalBuilder<P>
§type RecursiveSimilarBuilder = <LocalBuilder<P> as Invertable>::SimilarBuilder
type RecursiveSimilarBuilder = <LocalBuilder<P> as Invertable>::SimilarBuilder
The similar builder which also implements the recursive circuit builder, it may be the same
type or different.
source§impl<P: Precision> RotationsBuilder<P> for LocalBuilder<P>
impl<P: Precision> RotationsBuilder<P> for LocalBuilder<P>
source§fn rz_pi_by(
&mut self,
r: Self::Register,
m: i64
) -> CircuitResult<Self::Register>
fn rz_pi_by( &mut self, r: Self::Register, m: i64 ) -> CircuitResult<Self::Register>
Rotate around z by pi/m
source§fn rz_ratio(
&mut self,
r: Self::Register,
theta: Rational64
) -> CircuitResult<Self::Register>
fn rz_ratio( &mut self, r: Self::Register, theta: Rational64 ) -> CircuitResult<Self::Register>
Rotate around z.
source§fn rx_ratio(
&mut self,
r: Self::Register,
theta: Rational64
) -> CircuitResult<Self::Register>
fn rx_ratio( &mut self, r: Self::Register, theta: Rational64 ) -> CircuitResult<Self::Register>
Rotate around z.
source§fn ry_ratio(
&mut self,
r: Self::Register,
theta: Rational64
) -> CircuitResult<Self::Register>
fn ry_ratio( &mut self, r: Self::Register, theta: Rational64 ) -> CircuitResult<Self::Register>
Rotate around z.
source§impl<P: Precision> StochasticMeasurementBuilder for LocalBuilder<P>
impl<P: Precision> StochasticMeasurementBuilder for LocalBuilder<P>
§type StochasticMeasurementHandle = StochasticMeasurementHandle
type StochasticMeasurementHandle = StochasticMeasurementHandle
Handle which points to measurements.
source§fn measure_stochastic(
&mut self,
r: Self::Register
) -> (Self::Register, Self::StochasticMeasurementHandle)
fn measure_stochastic( &mut self, r: Self::Register ) -> (Self::Register, Self::StochasticMeasurementHandle)
Take a measurement of
r
, return r
and a handle to fetch the result later.source§impl<P: Precision> Subcircuitable for LocalBuilder<P>
impl<P: Precision> Subcircuitable for LocalBuilder<P>
§type Subcircuit = Vec<(Vec<usize, Global>, <LocalBuilder<P> as CircuitBuilder>::CircuitObject), Global>
type Subcircuit = Vec<(Vec<usize, Global>, <LocalBuilder<P> as CircuitBuilder>::CircuitObject), Global>
The export type for the circuit.
source§fn make_subcircuit(&self) -> CircuitResult<Self::Subcircuit>
fn make_subcircuit(&self) -> CircuitResult<Self::Subcircuit>
Export the circuit as a subcircuit if able.
source§fn apply_subcircuit(
&mut self,
sc: Self::Subcircuit,
r: Self::Register
) -> CircuitResult<Self::Register>
fn apply_subcircuit( &mut self, sc: Self::Subcircuit, r: Self::Register ) -> CircuitResult<Self::Register>
Append the subcircuit to the register
r
.source§impl<P: Precision> TemporaryRegisterBuilder for LocalBuilder<P>
impl<P: Precision> TemporaryRegisterBuilder for LocalBuilder<P>
source§fn make_zeroed_temp_qubit(&mut self) -> Self::Register
fn make_zeroed_temp_qubit(&mut self) -> Self::Register
Make a temporary qubit, initialized to zero.
source§fn return_zeroed_temp_register(&mut self, r: Self::Register)
fn return_zeroed_temp_register(&mut self, r: Self::Register)
Return a register which has been reset to zero.
source§fn make_zeroed_temp_register(&mut self, n: NonZeroUsize) -> Self::Register
fn make_zeroed_temp_register(&mut self, n: NonZeroUsize) -> Self::Register
Make a register of multiple qubits, initialized to zero.
source§impl<P: Precision> UnitaryBuilder<P> for LocalBuilder<P>
impl<P: Precision> UnitaryBuilder<P> for LocalBuilder<P>
source§fn vec_matrix_to_circuitobject(
n: usize,
data: Vec<Complex<P>>
) -> Self::CircuitObject
fn vec_matrix_to_circuitobject( n: usize, data: Vec<Complex<P>> ) -> Self::CircuitObject
Make a circuit object out of an arbitrary matrix
Single Qubit matrix is organized as |0><0|, |0><1|, |1><0|, |1><1|
source§fn apply_vec_matrix(
&mut self,
r: Self::Register,
data: Vec<Complex<P>>
) -> CircuitResult<Self::Register>
fn apply_vec_matrix( &mut self, r: Self::Register, data: Vec<Complex<P>> ) -> CircuitResult<Self::Register>
Apply an arbitrary matrix to the circuit given by a vector.
source§fn apply_matrix<const N: usize>(
&mut self,
r: Self::Register,
data: [Complex<P>; N]
) -> CircuitResult<Self::Register>
fn apply_matrix<const N: usize>( &mut self, r: Self::Register, data: [Complex<P>; N] ) -> CircuitResult<Self::Register>
Apply an arbitrary matrix to the circuit given by an array.
source§fn broadcast_single_qubit_matrix(
&mut self,
r: Self::Register,
data: [Complex<P>; 4]
) -> Self::Register
fn broadcast_single_qubit_matrix( &mut self, r: Self::Register, data: [Complex<P>; 4] ) -> Self::Register
Single qubit matrices can be applied to each qubit in a register unambiguously.
Matrix is organized as |0><0|, |0><1|, |1><0|, |1><1|
source§fn matrix_to_circuitobject<const N: usize>(
n: usize,
data: [Complex<P>; N]
) -> Self::CircuitObject
fn matrix_to_circuitobject<const N: usize>( n: usize, data: [Complex<P>; N] ) -> Self::CircuitObject
Make a circuit object out of an arbitrary matrix
Single Qubit matrix is organized as |0><0|, |0><1|, |1><0|, |1><1|
Auto Trait Implementations§
impl<P> RefUnwindSafe for LocalBuilder<P>where P: RefUnwindSafe,
impl<P> Send for LocalBuilder<P>
impl<P> Sync for LocalBuilder<P>
impl<P> Unpin for LocalBuilder<P>where P: Unpin,
impl<P> UnwindSafe for LocalBuilder<P>where P: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more