From ab3936adece2d06de622d5dd3399a218bd7c18c6 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 1 Oct 2026 08:24:22 +0000 Subject: [PATCH] [qec] Share Stim reset assembly in the emitter module Both circuit builders call emit_reset_tick for the prepare-R line. Callers still choose the id list: layout order for single-block memory, sorted unique ids for lattice surgery. Checked-in Stim gold stays byte-identical. Issue 473 stays open. Headers and observable assembly stay in the builders. Co-authored-by: Arnab Ghosh --- quon_qec/src/experiment.rs | 12 ++++-------- quon_qec/src/experiment/stim_emit.rs | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/quon_qec/src/experiment.rs b/quon_qec/src/experiment.rs index 5ffe2b6..4447190 100644 --- a/quon_qec/src/experiment.rs +++ b/quon_qec/src/experiment.rs @@ -493,11 +493,11 @@ fn emit_stim_single_block_memory(expanded: &ExpandedWorkload) -> Result = block .stabilizers @@ -673,11 +673,7 @@ fn emit_stim_lattice_surgery_cx(expanded: &ExpandedWorkload) -> Result\nTICK\n` in caller order. +/// +/// Single-block memory passes layout order. Lattice surgery passes the sorted +/// unique id list. This function does not reorder. +pub(crate) fn emit_reset_tick(out: &mut String, atom_ids: &[u32]) { + out.push('R'); + for id in atom_ids { + out.push_str(&format!(" {id}")); + } + out.push_str("\nTICK\n"); +} + /// Shared Stim state for one lattice-surgery circuit. /// /// Round impls append instructions and record byproduct handles. Observable @@ -671,4 +686,14 @@ mod tests { assert!(ctx.measure_logical.is_none()); assert_eq!(ctx.memory_round_i, 0); } + + #[test] + fn reset_tick_keeps_caller_order() { + let mut out = String::new(); + emit_reset_tick(&mut out, &[4, 0, 4]); + assert_eq!(out, "R 4 0 4\nTICK\n"); + let mut empty = String::new(); + emit_reset_tick(&mut empty, &[]); + assert_eq!(empty, "R\nTICK\n"); + } }