Skip to content

Fuse gates

FuseAdjacentGates: fuse adjacent same-op same-params R/Rz/StarRz/CZ statements.

A place-dialect → place-dialect rewrite that operates on the body of a place.StaticPlacement. Within that body, runs of textually-adjacent quantum statements with the same opcode, identical non-qubit SSA arguments, and pairwise-disjoint qubit sets are collapsed into a single statement covering the union of the qubits.

See docs/superpowers/specs/2026-04-28-place-stage-gate-fusion-design.md for the full design.

FuseAdjacentGates dataclass

FuseAdjacentGates()

Bases: RewriteRule


              flowchart TD
              bloqade.lanes.rewrite.fuse_gates.FuseAdjacentGates[FuseAdjacentGates]

              

              click bloqade.lanes.rewrite.fuse_gates.FuseAdjacentGates href "" "bloqade.lanes.rewrite.fuse_gates.FuseAdjacentGates"
            

Fuse adjacent same-op same-params R/Rz/CZ statements with disjoint qubits.

GateGroup

GateGroup()

Bases: ABC, Generic[T]


              flowchart TD
              bloqade.lanes.rewrite.fuse_gates.GateGroup[GateGroup]

              

              click bloqade.lanes.rewrite.fuse_gates.GateGroup href "" "bloqade.lanes.rewrite.fuse_gates.GateGroup"
            

A run of textually-adjacent fusable statements of one opcode.

Maintains all_qubits incrementally so disjointness checks are O(1) per statement. Subclasses implement opcode-specific predicate bits (non-qubit SSA arg comparison) and the merged-statement construction.

Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/rewrite/fuse_gates.py
33
34
35
def __init__(self) -> None:
    self.statements: list[T] = []
    self.all_qubits: set[int] = set()

merge_in_place

merge_in_place() -> bool

If the group has ≥2 stmts, replace the tail with one merged op covering all qubits and delete the earlier statements. Returns True iff a merge was performed.

Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/rewrite/fuse_gates.py
41
42
43
44
45
46
47
48
49
50
51
52
def merge_in_place(self) -> bool:
    """If the group has ≥2 stmts, replace the tail with one merged op
    covering all qubits and delete the earlier statements. Returns True
    iff a merge was performed.
    """
    if len(self.statements) < 2:
        return False
    merged = self._build_merged()
    self.statements[-1].replace_by(merged)
    for stmt in reversed(self.statements[:-1]):
        stmt.delete()
    return True