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>

source

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.

source

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.

source

pub fn apply_global_phase_pi_by(&mut self, r: Qudit, m: i64) -> Qudit

Apply a global phase of pi/m for integer m.

source

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>

source§

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§

fn toffoli( &mut self, cr: Self::Register, r: Self::Register ) -> Result<(Self::Register, Self::Register), CircuitError>

Applies NOT to r if all qubits in cr are 1.
source§

impl<P: Precision> CircuitBuilder for LocalBuilder<P>

§

type Register = Qudit

The register type used for the circuit.
§

type CircuitObject = BuilderCircuitObject<P>

The struct used to represent circuit objects.
§

type StateCalculation = (Vec<Complex<P>, Global>, Measurements<P>)

Return type for state calculations.
source§

fn n(&self) -> usize

Number of qubits in circuit.
source§

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

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>,

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>

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)>,

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 qubit(&mut self) -> Self::Register

Construct a single qubit.
source§

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>

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>,

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>,

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>

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)

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>)

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>

Split into multiple qubits, each with relative indices given by the sub-iterators. Read more
source§

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>

source§

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

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

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

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

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

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

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

Create and apply an NOT (or X) gate circuit object.
source§

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

Create and apply a Y gate circuit object.
source§

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

Create and apply an H gate circuit object.
source§

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

Create and apply a T^\dagger gate circuit object.
source§

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

Create and apply an S^\dagger gate circuit object.
source§

fn cnot( &mut self, cr: Self::Register, r: Self::Register ) -> Result<(Self::Register, Self::Register), CircuitError>

Create and apply a CNOT gate circuit object.
source§

fn swap( &mut self, ra: Self::Register, rb: Self::Register ) -> Result<(Self::Register, Self::Register), CircuitError>

Apply the SWAP gate to a pair of registers of equal sizes.
source§

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>

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>

Construct a new circuitbuilder which conditions all unitaries with cr.
source§

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>

Apply sc to register r using condition cr.
source§

impl<P: Debug + Precision> Debug for LocalBuilder<P>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<P: Default + Precision> Default for LocalBuilder<P>

source§

fn default() -> LocalBuilder<P>

Returns the “default value” for a type. Read more
source§

impl<P: Precision> Invertable for 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

Make a similar circuit builder.
source§

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>

Apply the inverted subcircuit to a register.
source§

impl<P: Precision> MeasurementBuilder for LocalBuilder<P>

§

type MeasurementHandle = MeasurementHandle

Handle which points to measurements.
source§

fn measure( &mut self, r: Self::Register ) -> (Self::Register, Self::MeasurementHandle)

Take a measurement of r, return r and a handle to fetch the result later.
source§

impl<P: Precision> RecursiveCircuitBuilder<P> for LocalBuilder<P>

§

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>

source§

fn rz(&mut self, r: Self::Register, theta: P) -> Self::Register

Rotate around z.
source§

fn rz_pi_by( &mut self, r: Self::Register, m: i64 ) -> CircuitResult<Self::Register>

Rotate around z by pi/m
source§

fn rx(&mut self, r: Self::Register, theta: P) -> Self::Register

Rotate around x.
source§

fn ry(&mut self, r: Self::Register, theta: P) -> Self::Register

Rotate around y.
source§

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>

Rotate around z.
source§

fn ry_ratio( &mut self, r: Self::Register, theta: Rational64 ) -> CircuitResult<Self::Register>

Rotate around z.
source§

fn rx_pi_by( &mut self, r: Self::Register, m: i64 ) -> CircuitResult<Self::Register>

Rotate around x by pi/m
source§

fn ry_pi_by( &mut self, r: Self::Register, m: i64 ) -> CircuitResult<Self::Register>

Rotate around y by pi/m
source§

impl<P: Precision> StochasticMeasurementBuilder for LocalBuilder<P>

§

type StochasticMeasurementHandle = StochasticMeasurementHandle

Handle which points to measurements.
source§

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>

§

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>

Export the circuit as a subcircuit if able.
source§

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>

source§

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)

Return a register which has been reset to zero.
source§

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>

source§

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>

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>

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

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

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V