Skip to content

Circuit2place

CleanUpLogicalInitialize

Bases: RewriteRule


              flowchart TD
              bloqade.lanes.rewrite.circuit2place.CleanUpLogicalInitialize[CleanUpLogicalInitialize]

              

              click bloqade.lanes.rewrite.circuit2place.CleanUpLogicalInitialize href "" "bloqade.lanes.rewrite.circuit2place.CleanUpLogicalInitialize"
            

Clean up any remaining LogicalInitialize statements.

HoistConstants

Bases: RewriteRule


              flowchart TD
              bloqade.lanes.rewrite.circuit2place.HoistConstants[HoistConstants]

              

              click bloqade.lanes.rewrite.circuit2place.HoistConstants href "" "bloqade.lanes.rewrite.circuit2place.HoistConstants"
            

This rewrite rule hoists all constant values to the top of the kernel.

HoistNewQubitsUp

Bases: RewriteRule


              flowchart TD
              bloqade.lanes.rewrite.circuit2place.HoistNewQubitsUp[HoistNewQubitsUp]

              

              click bloqade.lanes.rewrite.circuit2place.HoistNewQubitsUp href "" "bloqade.lanes.rewrite.circuit2place.HoistNewQubitsUp"
            

This rewrite rule shifts all qubit allocations before all gate operations.

InitializeNewQubits

Bases: RewriteRule


              flowchart TD
              bloqade.lanes.rewrite.circuit2place.InitializeNewQubits[InitializeNewQubits]

              

              click bloqade.lanes.rewrite.circuit2place.InitializeNewQubits href "" "bloqade.lanes.rewrite.circuit2place.InitializeNewQubits"
            

Rewrite bare allocation statements (qubit.stmts.New or gemini.operations.NewAt) to place.NewLogicalQubit with default initialization angles (theta=phi=lam=0).

MergePlacementRegions dataclass

MergePlacementRegions(
    merge_heuristic: Callable[
        [Region, Region], bool
    ] = _default_merge_heuristic,
)

Bases: RewriteRule


              flowchart TD
              bloqade.lanes.rewrite.circuit2place.MergePlacementRegions[MergePlacementRegions]

              

              click bloqade.lanes.rewrite.circuit2place.MergePlacementRegions href "" "bloqade.lanes.rewrite.circuit2place.MergePlacementRegions"
            

Merge adjacent placement regions into a single region. This is a placeholder for the actual implementation.

merge_heuristic class-attribute instance-attribute

merge_heuristic: Callable[[Region, Region], bool] = (
    _default_merge_heuristic
)

Heuristic function to decide whether to merge two circuit regions.

MergeStaticPlacement dataclass

MergeStaticPlacement(
    merge_policy: Callable[
        [StaticPlacement, StaticPlacement], bool
    ] = always_merge,
)

Bases: RewriteRule


              flowchart TD
              bloqade.lanes.rewrite.circuit2place.MergeStaticPlacement[MergeStaticPlacement]

              

              click bloqade.lanes.rewrite.circuit2place.MergeStaticPlacement href "" "bloqade.lanes.rewrite.circuit2place.MergeStaticPlacement"
            

Merge adjacent StaticPlacement statements using a caller-supplied policy.

Replaces MergePlacementRegions. Policy receives full StaticPlacement statements (not just body regions) so CZ qubit indices can be resolved.

RewriteInitializeToLogicalInitialize

Bases: RewriteRule


              flowchart TD
              bloqade.lanes.rewrite.circuit2place.RewriteInitializeToLogicalInitialize[RewriteInitializeToLogicalInitialize]

              

              click bloqade.lanes.rewrite.circuit2place.RewriteInitializeToLogicalInitialize href "" "bloqade.lanes.rewrite.circuit2place.RewriteInitializeToLogicalInitialize"
            

Rewrite gemini.logical.Initialize statements to place.LogicalInitialize statement.

RewriteLogicalInitializeToNewLogical

Bases: RewriteRule


              flowchart TD
              bloqade.lanes.rewrite.circuit2place.RewriteLogicalInitializeToNewLogical[RewriteLogicalInitializeToNewLogical]

              

              click bloqade.lanes.rewrite.circuit2place.RewriteLogicalInitializeToNewLogical href "" "bloqade.lanes.rewrite.circuit2place.RewriteLogicalInitializeToNewLogical"
            

Rewrite qubit references in place.LogicalInitialize statements to place.NewLogicalQubit allocations.

Handles both qubit.stmts.New (un-pinned, no location_address) and gemini.operations.NewAt (pinned, with location_address built from constant-folded args).

RewritePhysicalMeasure

Bases: RewriteRule


              flowchart TD
              bloqade.lanes.rewrite.circuit2place.RewritePhysicalMeasure[RewritePhysicalMeasure]

              

              click bloqade.lanes.rewrite.circuit2place.RewritePhysicalMeasure href "" "bloqade.lanes.rewrite.circuit2place.RewritePhysicalMeasure"
            

Lower qubit.stmts.Measure to place.StaticPlacement(EndMeasure).

For the physical pipeline. After AggressiveUnroll, qalloc produces: ilist.New([q0, q1]) — the register and measure receives: ilist.New([reg]) — outer wrapper with one IList[Qubit, N] element

We unwrap one level of nesting to collect individual Qubit SSA values.

RewritePlaceOperations dataclass

RewritePlaceOperations()

Bases: RewriteRule


              flowchart TD
              bloqade.lanes.rewrite.circuit2place.RewritePlaceOperations[RewritePlaceOperations]

              

              click bloqade.lanes.rewrite.circuit2place.RewritePlaceOperations href "" "bloqade.lanes.rewrite.circuit2place.RewritePlaceOperations"
            

Rewrite rule to convert native operations to place operations. This is a placeholder for the actual implementation.

RewriteQubitsToPinnedQubits

Bases: RewriteRule


              flowchart TD
              bloqade.lanes.rewrite.circuit2place.RewriteQubitsToPinnedQubits[RewriteQubitsToPinnedQubits]

              

              click bloqade.lanes.rewrite.circuit2place.RewriteQubitsToPinnedQubits href "" "bloqade.lanes.rewrite.circuit2place.RewriteQubitsToPinnedQubits"
            

Lower all bare qubit allocations to place.NewPinnedQubit.

  • qubit.stmts.New → NewPinnedQubit(location_address=None)
  • gemini.common.NewAt → NewPinnedQubit(location_address=)

Used exclusively by the physical pipeline; the logical pipeline uses InitializeNewQubits instead.

gate_only_merge

gate_only_merge(
    sp1: StaticPlacement, sp2: StaticPlacement
) -> bool

Merge placements whose bodies contain only R, Rz, CZ, and Yield.

Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/rewrite/circuit2place.py
582
583
584
def gate_only_merge(sp1: place.StaticPlacement, sp2: place.StaticPlacement) -> bool:
    """Merge placements whose bodies contain only R, Rz, CZ, and Yield."""
    return _is_pure_gate_block(sp1) and _is_pure_gate_block(sp2)

sq_only_merge

sq_only_merge(
    sp1: StaticPlacement, sp2: StaticPlacement
) -> bool

Merge placements whose bodies contain only R and Rz (no CZ).

Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/rewrite/circuit2place.py
587
588
589
def sq_only_merge(sp1: place.StaticPlacement, sp2: place.StaticPlacement) -> bool:
    """Merge placements whose bodies contain only R and Rz (no CZ)."""
    return _is_sq_only_block(sp1) and _is_sq_only_block(sp2)