Skip to content

Flat block

Validate the flat-block shape that time-ordered rewrites depend on.

Why this exists. A phase frame is a physical quantity: the Z rotation accumulated on an atom, which persists for the whole shot and only makes sense read in the order the hardware executes. EliminateRz therefore carries it forward statement by statement, and is correct only if it is handed statements in execution order.

kirin.rewrite.Walk gives that order within a block, and nowhere else:

  • It enqueues a region's blocks reversed under the default reverse=False, so across two blocks the frame accumulates backwards -- phase from the later block applied to gates in the earlier one.
  • It reaches a nested function's region before the func.Function statement that owns it, so a rule that resets per-region state has that state wiped part-way through the enclosing block.

Both are pinned by python/tests/rewrite/test_walk_order.py rather than assumed, because they are kirin's behaviour and not ours.

Neither hazard produces broken-looking output. The emitted program is structurally valid, verifies, and lowers -- it is just a different circuit than the one the user wrote, differing by phases that a Z-basis measurement cannot see. That is why this is a precondition checked before rewriting rather than a condition a rule detects while running: by the time a rule could notice, the frame it would need to report is already gone.

Why a direct walk and not a Forward analysis, unlike the analysis-backed validations next door (lanes.address.validation, gemini.common.qubit.duplicates). Those resolve values and need the interpreter. This is a structural property of the IR, and a Forward pass only visits reachable code -- an unreachable second block would slip through the very check that exists to reject it. gemini.no_recursion is the in-repo precedent for a structural check written this way.

FlatBlockValidation dataclass

FlatBlockValidation()

Bases: ValidationPass


              flowchart TD
              bloqade.lanes.validation.flat_block.FlatBlockValidation[FlatBlockValidation]

              

              click bloqade.lanes.validation.flat_block.FlatBlockValidation href "" "bloqade.lanes.validation.flat_block.FlatBlockValidation"
            

Require a single-block callable region with no nested functions.