quil_rs/instruction/
timing.rs1#[cfg(feature = "stubs")]
2use pyo3_stub_gen::derive::gen_stub_pyclass;
3
4use super::Qubit;
5use crate::{expression::Expression, pickleable_new, quil::Quil};
6
7#[derive(Clone, Debug, PartialEq, Eq, Hash)]
8#[cfg_attr(feature = "stubs", gen_stub_pyclass)]
9#[cfg_attr(
10 feature = "python",
11 pyo3::pyclass(module = "quil.instructions", eq, frozen, hash, get_all, subclass)
12)]
13pub struct Delay {
14 pub duration: Expression,
15 pub frame_names: Vec<String>,
16 pub qubits: Vec<Qubit>,
17}
18
19pickleable_new! {
20 impl Delay {
21 pub fn new(duration: Expression, frame_names: Vec<String>, qubits: Vec<Qubit>);
22 }
23}
24
25impl Quil for Delay {
26 fn write(
27 &self,
28 writer: &mut impl std::fmt::Write,
29 fall_back_to_debug: bool,
30 ) -> crate::quil::ToQuilResult<()> {
31 write!(writer, "DELAY")?;
32 for qubit in &self.qubits {
33 write!(writer, " ")?;
34 qubit.write(writer, fall_back_to_debug)?;
35 }
36 for frame_name in &self.frame_names {
37 write!(writer, " \"{frame_name}\"")?;
38 }
39 write!(writer, " ",)?;
40 self.duration.write(writer, fall_back_to_debug)
41 }
42}
43
44#[derive(Clone, Debug, PartialEq, Eq, Hash)]
45#[cfg_attr(feature = "stubs", gen_stub_pyclass)]
46#[cfg_attr(
47 feature = "python",
48 pyo3::pyclass(module = "quil.instructions", eq, frozen, hash, get_all, subclass)
49)]
50pub struct Fence {
51 pub qubits: Vec<Qubit>,
52}
53
54impl Quil for Fence {
55 fn write(
56 &self,
57 writer: &mut impl std::fmt::Write,
58 fall_back_to_debug: bool,
59 ) -> Result<(), crate::quil::ToQuilError> {
60 write!(writer, "FENCE")?;
61 for qubit in &self.qubits {
62 write!(writer, " ")?;
63 qubit.write(writer, fall_back_to_debug)?;
64 }
65 Ok(())
66 }
67}
68
69pickleable_new! {
70 impl Fence {
71 pub fn new(qubits: Vec<Qubit>);
72 }
73}