Skip to content

Insert ticks

InsertTicks

Bases: RewriteRule


              flowchart TD
              bloqade.stim.rewrite.insert_ticks.InsertTicks[InsertTicks]

              

              click bloqade.stim.rewrite.insert_ticks.InsertTicks href "" "bloqade.stim.rewrite.insert_ticks.InsertTicks"
            

Insert a TICK after every Stim operation.

Operates on a lowered Stim circuit. After each operation statement (gate, reset, measurement, or noise channel) a :class:~bloqade.stim.dialects.auxiliary.stmts.Tick is inserted, so the rendered diagram's columns follow program order rather than ASAP packing.

The rule is idempotent -- an operation already followed by a TICK is left untouched -- so it is safe under :class:~kirin.rewrite.Fixpoint.

is_operation staticmethod

is_operation(stmt: Statement) -> bool

Whether the statement is a moment-advancing Stim operation.

Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/insert_ticks.py
27
28
29
30
@staticmethod
def is_operation(stmt: ir.Statement) -> bool:
    """Whether the statement is a moment-advancing Stim operation."""
    return getattr(stmt, "dialect", None) in OPERATION_DIALECTS

rewrite_Statement

rewrite_Statement(node: Statement) -> RewriteResult

Insert a TICK after node when it is an un-ticked operation.

Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/insert_ticks.py
32
33
34
35
36
37
38
39
40
41
def rewrite_Statement(self, node: ir.Statement) -> RewriteResult:
    """Insert a ``TICK`` after ``node`` when it is an un-ticked operation."""
    if not self.is_operation(node):
        return RewriteResult()

    if isinstance(node.next_stmt, auxiliary.stmts.Tick):
        return RewriteResult()

    auxiliary.stmts.Tick().insert_after(node)
    return RewriteResult(has_done_something=True)