quil_rs/instruction/
timing.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use super::Qubit;
use crate::{expression::Expression, quil::Quil};

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Delay {
    pub duration: Expression,
    pub frame_names: Vec<String>,
    pub qubits: Vec<Qubit>,
}

impl Delay {
    pub fn new(duration: Expression, frame_names: Vec<String>, qubits: Vec<Qubit>) -> Self {
        Self {
            duration,
            frame_names,
            qubits,
        }
    }
}

impl Quil for Delay {
    fn write(
        &self,
        writer: &mut impl std::fmt::Write,
        fall_back_to_debug: bool,
    ) -> crate::quil::ToQuilResult<()> {
        write!(writer, "DELAY")?;
        for qubit in &self.qubits {
            write!(writer, " ")?;
            qubit.write(writer, fall_back_to_debug)?;
        }
        for frame_name in &self.frame_names {
            write!(writer, " \"{}\"", frame_name)?;
        }
        write!(writer, " ",)?;
        self.duration.write(writer, fall_back_to_debug)
    }
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Fence {
    pub qubits: Vec<Qubit>,
}

impl Quil for Fence {
    fn write(
        &self,
        writer: &mut impl std::fmt::Write,
        fall_back_to_debug: bool,
    ) -> Result<(), crate::quil::ToQuilError> {
        write!(writer, "FENCE")?;
        for qubit in &self.qubits {
            write!(writer, " ")?;
            qubit.write(writer, fall_back_to_debug)?;
        }
        Ok(())
    }
}

impl Fence {
    pub fn new(qubits: Vec<Qubit>) -> Self {
        Self { qubits }
    }
}