Skip to main content

FlowEngine

Struct FlowEngine 

Source
pub struct FlowEngine<'c, M> { /* private fields */ }
Expand description

Tracks open flows and completed detectors while chunks are appended.

Open-flow keys borrow the boundary PauliMaps of the appended chunks (lifetime 'c), so matching flows across chunks never clones a key. This works because every appended flow outlives the engine; the engine is a per-pass scratch structure, not a long-lived store.

Implementations§

Source§

impl<'c, M> FlowEngine<'c, M>

Source

pub fn new() -> FlowEngine<'c, M>

Creates an empty flow-composition engine.

Source

pub fn finish(self) -> Result<Vec<CompletedFlow<M>>, FlowError>

Return completed flows after requiring all active flows to terminate. Latent stabilizers that survive the final measured-check span are output logical correlations; observable lowering owns them, not the detector side table.

§Errors

Returns FlowError if any flow remains unterminated.

Source

pub fn append_group_allowing_dangling( &mut self, parts: &[OffsetFlows<'c>], meas_mapper: impl FnMut(usize, &u32) -> M, ) -> Result<(), FlowError>

Append one logical chunk assembled from several offset flow slices (one per node member), while allowing previously-open boundary flows to remain open for later chunks.

The mapper receives the slice index alongside each measurement reference so every member can resolve against its own template measurement table.

§Errors

Returns FlowError if boundaries cannot be translated or composed.

Source

pub fn append_group_allowing_stabilizer_transition( &mut self, parts: &[OffsetFlows<'c>], meas_mapper: impl FnMut(usize, &u32) -> M, ) -> Result<(), FlowError>
where M: Copy,

Append a boundary group while allowing its stabilizer span to differ from the currently-open span. Exact matching remains the fast path. At a gauge transition, products in the two spans’ intersection emit detectors; old-only generators retire and the group’s ordinary creator flows start its new-only generators.

§Errors

Returns FlowError if boundaries cannot be translated or composed.

Source

pub fn append_group_skipping_unmatched_inputs( &mut self, parts: &[OffsetFlows<'c>], meas_mapper: impl FnMut(usize, &u32) -> M, ) -> Result<(), FlowError>

Append chunks while ignoring flows whose start boundary is not already open. This is useful when extracting template-local detectors: flows that enter through a template boundary are handled later by instance lowering, not by the reusable template side table.

§Errors

Returns FlowError if boundaries cannot be translated or composed.

Source

pub fn append_residual_group( &mut self, parts: &[OffsetFlows<'c>], meas_mapper: impl FnMut(usize, &u32) -> M, ) -> Result<(), FlowError>

Append chunks for residual extraction: like Self::append_group_skipping_unmatched_inputs, but a flow whose start is not already open is kept as a boundary-entering chain (recording where it entered) rather than dropped. Combined with Self::into_residual_flows, this composes a template’s open boundary flows into fused chains in one pass: internal detectors fall out via Self::drain_completed as usual, while every flow touching the boundary survives in the residual.

§Errors

Returns FlowError if boundaries cannot be translated or composed.

Source

pub fn drain_completed(&mut self) -> Drain<'_, CompletedFlow<M>> ⓘ

Drains the completed (internal, boundary-detached) detector chains, leaving open flows untouched for later chunks.

Source

pub fn into_residual_flows(self) -> Vec<ResidualFlow<M>>

Consume the engine after a residual composition (chunks appended with Self::append_residual_group) and return every boundary flow as a fused chain: the chains still open (origin_start → open key) plus those that closed against a boundary input (origin_start → ∅). Chains that closed with an empty origin are internal detectors; they collect in completed (drainable via Self::drain_completed) and are excluded here.

The caller owns ordering: open_flows iterates in hash order, so a caller that needs determinism (e.g. reproducible detector emission) must sort the result by a canonical key.

Source§

impl<'c, M> FlowEngine<'c, DetectorTerm<M>>
where M: Copy + Ord,

Source

pub fn start_loop_detector_states( &mut self, body_first_chunk: &[OffsetFlows<'c>], next_loop_state: &mut u32, ) -> Result<PendingLoopDetectorStates<'c, M>, FlowError>

Assign a loop-carried detector state to every open flow the loop body is about to consume: the open measurements become the state’s initial parity and are replaced by a single loop-state term.

Open flows are matched against the first body chunk’s start keys directly; a valid body never consumes the same key twice (the append would fail), so each open flow gains at most one state.

§Errors

Returns FlowError if coordinates or the loop-state id space overflow.

§Panics

Panics if the preflighted loop-state range is internally inconsistent.

Source

pub fn drain_composed_chains( &mut self, ) -> impl Iterator<Item = ComposedChain<M>>

Drain completed chains, classifying each by its fused FlowMarker into a ComposedChain: a Discard-marked or empty-parity chain produces nothing, a Restart chain becomes a restart syndrome, everything else a detector at the chain’s center. This is the shared marker discipline for detector synthesis — the compile-time boundary pass (bloq_compile::lower::detector) and the seam recompose (bloq_ir::edit) both drain through here so the two cannot drift.

Source

pub fn finish_loop_detector_states( &self, pending: PendingLoopDetectorStates<'c, M>, ) -> Vec<LoopCarriedDetectorState<M>>

Completes the pending loop states: each state’s next parity is read from the flow still open at its key after the body was appended.

Trait Implementations§

Source§

impl<'c, M> Clone for FlowEngine<'c, M>
where M: Clone,

Source§

fn clone(&self) -> FlowEngine<'c, M>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<M> Debug for FlowEngine<'_, M>
where M: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<M> Default for FlowEngine<'_, M>

Source§

fn default() -> FlowEngine<'_, M>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'c, M> Freeze for FlowEngine<'c, M>

§

impl<'c, M> RefUnwindSafe for FlowEngine<'c, M>
where M: RefUnwindSafe,

§

impl<'c, M> Send for FlowEngine<'c, M>
where M: Send,

§

impl<'c, M> Sync for FlowEngine<'c, M>
where M: Sync,

§

impl<'c, M> Unpin for FlowEngine<'c, M>
where M: Unpin,

§

impl<'c, M> UnsafeUnpin for FlowEngine<'c, M>

§

impl<'c, M> UnwindSafe for FlowEngine<'c, M>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T, BorrowedSelf> BitwiseMutViaBorrow<BorrowedSelf> for T
where T: BorrowMut<BorrowedSelf>, BorrowedSelf: BitwiseMut + ?Sized,

§

fn assign_index(&mut self, index: usize, to: bool)

§

fn negate_index(&mut self, index: usize)

§

fn clear_bits(&mut self)

§

fn assign_random( &mut self, bit_count: usize, random_number_generator: &mut impl RngExt, )
where BorrowedSelf: BitLength,

§

impl<Bits, Other, BorrowedSelf, BorrowedOther> BitwisePairMutViaBorrow<Other, BorrowedSelf, BorrowedOther> for Bits
where Bits: BorrowMut<BorrowedSelf> + ?Sized, Other: Borrow<BorrowedOther> + ?Sized, BorrowedSelf: Bitwise + BitwisePairMut<BorrowedOther> + ?Sized, BorrowedOther: Bitwise + ?Sized,

§

fn assign(&mut self, other: &Other)

§

fn bitxor_assign(&mut self, other: &Other)

§

fn bitand_assign(&mut self, other: &Other)

§

fn bitor_assign(&mut self, other: &Other)

§

impl<T, Other, BorrowedSelf, BorrowedOther> BitwisePairViaBorrow<Other, BorrowedSelf, BorrowedOther> for T
where T: Borrow<BorrowedSelf> + ?Sized, Other: Borrow<BorrowedOther> + ?Sized, BorrowedSelf: Bitwise + BitwisePair<BorrowedOther> + ?Sized, BorrowedOther: Bitwise + ?Sized,

§

fn dot(&self, other: &Other) -> bool

§

fn and_weight(&self, other: &Other) -> usize

§

fn or_weight(&self, other: &Other) -> usize

§

fn xor_weight(&self, other: &Other) -> usize

§

impl<T, BorrowedSelf> BitwiseViaBorrow<BorrowedSelf> for T
where T: Borrow<BorrowedSelf>, BorrowedSelf: Bitwise + ?Sized,

§

fn index(&self, index: usize) -> bool

§

fn weight(&self) -> usize

§

fn parity(&self) -> bool

§

fn is_zero(&self) -> bool

§

fn is_unit(&self, index: usize) -> bool

§

fn support<'a>(&'a self) -> impl SortedIterator
where BorrowedSelf: 'a,

§

fn max_support(&self) -> Option<usize>

§

fn min_support(&self) -> Option<usize>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.