Skip to content

Commit

Permalink
chore: respond to @erichulburd's review
Browse files Browse the repository at this point in the history
  • Loading branch information
antalsz committed Jan 17, 2025
1 parent bf0e86d commit 0bf10b3
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 10 deletions.
40 changes: 30 additions & 10 deletions quil-rs/src/program/scheduling/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,8 @@ pub enum ScheduleErrorVariant {
#[derive(Debug, Clone, thiserror::Error)]
#[error(
"Error scheduling {}: {}: {variant:?}",
match .instruction_node {
None => "an instruction".to_string(),
Some(ScheduledGraphNode::BlockStart) => "the start of the block".to_string(),
Some(ScheduledGraphNode::InstructionIndex(index)) => format!("instruction {index}"),
Some(ScheduledGraphNode::BlockEnd) => "the block terminator instruction".to_string(),
},
.instruction.to_quil_or_debug()
.instruction_node.map_or_else(|| "an instruction".to_string(), |node| node.to_string()),
.instruction.to_quil_or_debug(),
)]
pub struct ScheduleError {
pub instruction_node: Option<ScheduledGraphNode>,
Expand All @@ -58,14 +53,22 @@ pub struct ScheduleError {

pub type ScheduleResult<T> = Result<T, ScheduleError>;

#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Hash, Ord)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Hash, Ord)]
pub enum ScheduledGraphNode {
BlockStart,
InstructionIndex(usize),
BlockEnd,
}

impl Eq for ScheduledGraphNode {}
impl std::fmt::Display for ScheduledGraphNode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::BlockStart => write!(f, "the start of the block"),
Self::InstructionIndex(ix) => write!(f, "instruction {ix}"),
Self::BlockEnd => write!(f, "the end-of-block terminator"),
}
}
}

/// A MemoryAccessQueue expresses the current state of memory accessors at the time of
/// an instruction's execution.
Expand Down Expand Up @@ -519,14 +522,17 @@ impl<'a> ScheduledBasicBlock<'a> {
}
}

/// A program broken down into its [`ScheduledBasicBlock`]s. All instruction-level scheduling in a
/// program is intra-block; the only dependencies between basic blocks are those resulting from
/// execution flow. For instance, we do *not* track memory dependencies from a write in one block to
/// a read in a subsequent block.
#[derive(Clone, Debug)]
pub struct ScheduledProgram<'a> {
basic_blocks: Vec<ScheduledBasicBlock<'a>>,
}

impl<'a> ScheduledProgram<'a> {
/// Structure a sequential program
#[allow(unused_assignments)]
pub fn from_program(
program: &'a Program,
custom_handler: &mut InstructionHandler,
Expand Down Expand Up @@ -869,6 +875,20 @@ NONBLOCKING CAPTURE 0 "ro_rx" flat(duration: 2.0000000000000003e-06, iq: 1.0, sc
JUMP-WHEN @eq ro
LABEL @eq
PULSE 0 "ro_tx" gaussian(duration: 1, fwhm: 2, t0: 3)
"#
}

build_dot_format_snapshot_test_case! {
no_memory_dependency_across_blocks,
r#"
DECLARE ro BIT
DECLARE depends_on_ro BIT
NONBLOCKING CAPTURE 0 "ro_rx" flat(duration: 2.0000000000000003e-06, iq: 1.0, scale: 1.0, phase: 0.8745492960861506, detuning: 0.0) ro
JUMP @eq
LABEL @eq
MOVE depends_on_ro ro
PULSE 0 "ro_tx" gaussian(duration: 1, fwhm: 2, t0: 3)
"#
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
source: quil-rs/src/program/scheduling/graph.rs
expression: dot_format
---
digraph {
entry -> "block_0_start";
entry [label="Entry Point"];
subgraph cluster_0 {
label="block_0";
node [style="filled"];
"block_0_start" [shape=circle, label="start"];
"block_0_start" -> "block_0_0" [label="ordering
timing"];
"block_0_0" [shape=rectangle, label="[0] NONBLOCKING CAPTURE 0 \"ro_rx\" flat(detuning: 0, duration: 2.0000000000000003e-6, iq: 1, phase: 0.8745492960861506, scale: 1) ro[0]"];
"block_0_0" -> "block_0_end" [label="ordering
timing"];
"block_0_end" [shape=circle, label="end"];
}
"block_0_end" -> "@eq_start" [label="always"];
subgraph cluster_1 {
label="@eq";
node [style="filled"];
"@eq_start" [shape=circle, label="start"];
"@eq_start" -> "@eq_0" [label="ordering"];
"@eq_start" -> "@eq_1" [label="ordering
timing"];
"@eq_start" -> "@eq_end" [label="ordering
timing"];
"@eq_0" [shape=rectangle, label="[0] MOVE depends_on_ro[0] ro[0]"];
"@eq_0" -> "@eq_end" [label="ordering"];
"@eq_1" [shape=rectangle, label="[1] PULSE 0 \"ro_tx\" gaussian(duration: 1, fwhm: 2, t0: 3)"];
"@eq_1" -> "@eq_end" [label="ordering
timing"];
"@eq_end" [shape=circle, label="end"];
}
}

0 comments on commit 0bf10b3

Please sign in to comment.