Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions quon_qec/src/experiment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,7 @@ fn emit_stim_single_block_memory(expanded: &ExpandedWorkload) -> Result<String,
measure_basis.as_str(),
);

for (atom, &(x, y)) in block.atoms.iter().zip(block.coords.iter()) {
out.push_str(&format!("QUBIT_COORDS({x}, {y}) {}\n", atom.0));
}
stim_emit::emit_qubit_coords(&mut out, &block.atoms, &block.coords);

// Prepare |0…0⟩ then optional data H for X-init / X-memory (|+⟩^n).
let mut reset_ids = Vec::with_capacity(block.atoms.len());
Expand Down Expand Up @@ -647,9 +645,7 @@ fn emit_stim_lattice_surgery_cx(expanded: &ExpandedWorkload) -> Result<String, E
stim_emit::emit_lattice_surgery_header(&mut out, distance, expanded.blocks.len());

for block in &expanded.blocks {
for (atom, &(x, y)) in block.atoms.iter().zip(block.coords.iter()) {
out.push_str(&format!("QUBIT_COORDS({x}, {y}) {}\n", atom.0));
}
stim_emit::emit_qubit_coords(&mut out, &block.atoms, &block.coords);
}

let mut all_atoms: Vec<u32> = expanded
Expand Down
37 changes: 31 additions & 6 deletions quon_qec/src/experiment/stim_emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
//! kind is a new impl plus one arm in [`lattice_round_emitter`].
//!
//! Both builders share [`emit_reset_tick`] for the prepare-`R` / `TICK` line,
//! [`emit_single_block_header`] / [`emit_lattice_surgery_header`] for the
//! comment preamble, and [`emit_observable_include`] for `OBSERVABLE_INCLUDE`
//! record offsets. `QUBIT_COORDS` stay in the builders. Lattice surgery still
//! appends frame-byproduct records after the shared observable line.
//! [`emit_qubit_coords`] for `QUBIT_COORDS`, [`emit_single_block_header`] /
//! [`emit_lattice_surgery_header`] for the comment preamble, and
//! [`emit_observable_include`] for `OBSERVABLE_INCLUDE` record offsets.
//! Measure lines and closing detectors stay in the builders. Lattice surgery
//! still appends frame-byproduct records after the shared observable line.

use std::collections::HashMap;

use crate::expand::{
ExpandedBlock, ExpandedWorkload, MergeBoundary, PauliFrameUpdate, PhysicalRound, RoundKind,
RoundTerminal,
ExpandedBlock, ExpandedWorkload, MergeBoundary, PauliFrameUpdate, PhysicalAtomId,
PhysicalRound, RoundKind, RoundTerminal,
};
use crate::workload::LogicalBasis;

Expand Down Expand Up @@ -85,6 +86,16 @@ pub(crate) fn emit_single_block_header(
));
}

/// Write `QUBIT_COORDS(x, y) id` in caller order.
///
/// Single-block memory passes one block. Lattice surgery calls this once per
/// block, in workload order. Pairs stop at the shorter slice, matching `zip`.
pub(crate) fn emit_qubit_coords(out: &mut String, atoms: &[PhysicalAtomId], coords: &[(i32, i32)]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve. I would merge this slice on 586f21a.

Both builders call stim_emit::emit_qubit_coords for QUBIT_COORDS(x, y) id. The helper keeps caller order and stops at the shorter slice, the same zip as before. Single-block memory passes one block. Lattice surgery still loops expanded.blocks in workload order and calls the helper once per block.

Measure lines and closing detectors are not in this diff; they stay in the builders. The checked-in Stim gold is not in the diff. The new function has no unwrap or expect. qubit_coords_keep_caller_order locks [4, 0] against [(1, 2), (3, 4)] and the one-pair shorter slice.

Title, body, and the commit mention the issue only as Refs #473. They do not use fixes/closes/resolves, and they do not say the issue stays open. This slice does not move measure lines or closing detectors.

for (atom, &(x, y)) in atoms.iter().zip(coords.iter()) {
out.push_str(&format!("QUBIT_COORDS({x}, {y}) {}\n", atom.0));
}
}

/// Write the lattice-surgery CX comment preamble.
pub(crate) fn emit_lattice_surgery_header(out: &mut String, distance: u32, blocks: usize) {
out.push_str(&format!(
Expand Down Expand Up @@ -794,6 +805,20 @@ mod tests {
);
}

#[test]
fn qubit_coords_keep_caller_order() {
let mut out = String::new();
emit_qubit_coords(
&mut out,
&[PhysicalAtomId(4), PhysicalAtomId(0)],
&[(1, 2), (3, 4)],
);
assert_eq!(out, "QUBIT_COORDS(1, 2) 4\nQUBIT_COORDS(3, 4) 0\n");
let mut short = String::new();
emit_qubit_coords(&mut short, &[PhysicalAtomId(1)], &[(0, 0), (9, 9)]);
assert_eq!(short, "QUBIT_COORDS(0, 0) 1\n");
}

#[test]
fn lattice_surgery_header_matches_gold_preamble() {
let mut out = String::new();
Expand Down
Loading