pub struct Qasm3Builder {
pub circuit: Qasm3Circuit,
pub num_qubits: usize,
pub num_bits: usize,
}Expand description
Builder for QASM 3.0 circuits
Fields§
§circuit: Qasm3CircuitThe circuit being built
num_qubits: usizeNumber of qubits in the circuit
num_bits: usizeNumber of classical bits in the circuit
Implementations§
Source§impl Qasm3Builder
impl Qasm3Builder
Sourcepub fn gate(&mut self, name: &str, qubits: &[usize]) -> DeviceResult<&mut Self>
pub fn gate(&mut self, name: &str, qubits: &[usize]) -> DeviceResult<&mut Self>
Add a gate operation
Sourcepub fn gate_with_params(
&mut self,
name: &str,
params: &[f64],
qubits: &[usize],
) -> DeviceResult<&mut Self>
pub fn gate_with_params( &mut self, name: &str, params: &[f64], qubits: &[usize], ) -> DeviceResult<&mut Self>
Add a gate with parameters
Sourcepub fn ctrl_gate(
&mut self,
name: &str,
control: usize,
target: usize,
params: &[f64],
) -> DeviceResult<&mut Self>
pub fn ctrl_gate( &mut self, name: &str, control: usize, target: usize, params: &[f64], ) -> DeviceResult<&mut Self>
Add a controlled gate
Sourcepub fn inv_gate(
&mut self,
name: &str,
qubits: &[usize],
) -> DeviceResult<&mut Self>
pub fn inv_gate( &mut self, name: &str, qubits: &[usize], ) -> DeviceResult<&mut Self>
Add an inverse gate
Sourcepub fn measure(&mut self, qubit: usize, bit: usize) -> DeviceResult<&mut Self>
pub fn measure(&mut self, qubit: usize, bit: usize) -> DeviceResult<&mut Self>
Add measurement
Sourcepub fn measure_all(&mut self) -> DeviceResult<&mut Self>
pub fn measure_all(&mut self) -> DeviceResult<&mut Self>
Measure all qubits
Sourcepub fn reset(&mut self, qubit: usize) -> DeviceResult<&mut Self>
pub fn reset(&mut self, qubit: usize) -> DeviceResult<&mut Self>
Add reset operation
Sourcepub fn barrier(&mut self, qubits: &[usize]) -> DeviceResult<&mut Self>
pub fn barrier(&mut self, qubits: &[usize]) -> DeviceResult<&mut Self>
Add barrier
Sourcepub fn if_statement<F>(
&mut self,
condition: &str,
then_block: F,
) -> DeviceResult<&mut Self>
pub fn if_statement<F>( &mut self, condition: &str, then_block: F, ) -> DeviceResult<&mut Self>
Add if statement (dynamic circuit)
Sourcepub fn if_else_statement<F, G>(
&mut self,
condition: &str,
then_block: F,
else_block: G,
) -> DeviceResult<&mut Self>where
F: FnOnce(&mut Qasm3Builder) -> DeviceResult<()>,
G: FnOnce(&mut Qasm3Builder) -> DeviceResult<()>,
pub fn if_else_statement<F, G>(
&mut self,
condition: &str,
then_block: F,
else_block: G,
) -> DeviceResult<&mut Self>where
F: FnOnce(&mut Qasm3Builder) -> DeviceResult<()>,
G: FnOnce(&mut Qasm3Builder) -> DeviceResult<()>,
Add if-else statement (dynamic circuit)
Sourcepub fn while_loop<F>(
&mut self,
condition: &str,
body: F,
) -> DeviceResult<&mut Self>
pub fn while_loop<F>( &mut self, condition: &str, body: F, ) -> DeviceResult<&mut Self>
Add while loop
Sourcepub fn for_loop<F>(
&mut self,
var_name: &str,
range: &str,
body: F,
) -> DeviceResult<&mut Self>
pub fn for_loop<F>( &mut self, var_name: &str, range: &str, body: F, ) -> DeviceResult<&mut Self>
Add for loop
Sourcepub fn switch_statement<F>(
&mut self,
expression: &str,
case_builder: F,
) -> DeviceResult<&mut Self>
pub fn switch_statement<F>( &mut self, expression: &str, case_builder: F, ) -> DeviceResult<&mut Self>
Add switch statement (QASM 3.0 dynamic circuit feature)
§Arguments
expression- The expression to switch on (e.g., “c”)case_builder- A closure that builds the switch cases
§Example
ⓘ
builder.switch_statement("c", |sw| {
sw.case(&[0], |b| b.gate("x", &[0]))?;
sw.case(&[1], |b| b.gate("y", &[0]))?;
sw.default(|b| b.gate("z", &[0]))?;
Ok(())
})?;Sourcepub fn assign(&mut self, target: &str, value: &str) -> &mut Self
pub fn assign(&mut self, target: &str, value: &str) -> &mut Self
Add classical assignment
§Arguments
target- Target variable (e.g.,"c[0]")value- Value expression (e.g.,"c[0] + 1","c[0] & c[1]")
Sourcepub fn build(self) -> DeviceResult<Qasm3Circuit>
pub fn build(self) -> DeviceResult<Qasm3Circuit>
Build the QASM 3.0 circuit
Auto Trait Implementations§
impl Freeze for Qasm3Builder
impl RefUnwindSafe for Qasm3Builder
impl Send for Qasm3Builder
impl Sync for Qasm3Builder
impl Unpin for Qasm3Builder
impl UnwindSafe for Qasm3Builder
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.