Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion samplomatic/transpiler/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is a Qiskit project.
#
# (C) Copyright IBM 2025.
# (C) Copyright IBM 2025, 2026.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -13,3 +13,10 @@
"""Transpiler"""

from .generate_boxing_pass_manager import generate_boxing_pass_manager
from .layer_inference import (
LayerInferenceError,
_InferredLayer,
infer_layers,
insert_layer_barriers,
)
from .passes import InsertLayerBarriers
18 changes: 18 additions & 0 deletions samplomatic/transpiler/generate_boxing_pass_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

"""generate_boxing_pass_manager"""

from collections.abc import Iterable, Sequence # noqa: F401
from typing import Literal

from qiskit.transpiler import PassManager
Expand All @@ -26,6 +27,7 @@
AddTerminalRightDressedBoxes,
GroupGatesIntoBoxes,
GroupMeasIntoBoxes,
InsertLayerBarriers,
)
from .passes.insert_noops import AddNoopsActiveAccum, AddNoopsActiveCircuit, AddNoopsAll

Expand Down Expand Up @@ -68,6 +70,7 @@ def generate_boxing_pass_manager(
"immediately", "finally", "after_stratification", "never", True, False
] = "after_stratification",
add_tags: Literal["none", "unique_box", "unique_instance", "noise_ref"] = "none",
infer_layers: "bool | Sequence[Iterable[tuple[int, int]]]" = False,
) -> PassManager:
"""Construct a pass manager to group the operations in a circuit into boxes.

Expand Down Expand Up @@ -234,6 +237,17 @@ def generate_boxing_pass_manager(
skipped (no :class:`~.Tag` is added). Typically used together with a non-``'none'``
``inject_noise_targets`` value.

infer_layers: Whether to insert helper barriers at inferred 2Q layer boundaries
using :class:`~.InsertLayerBarriers` before grouping. The supported values are:

* ``False`` (default) to disable layer inference entirely.
* ``True`` to infer the layer templates from any barrier-separated regions of
the input circuit.
* A sequence of layer templates (each a collection of qubit-index pairs
``(q0, q1)``) to use as explicit layer types. Useful when the input circuit
has had its barriers removed by the transpiler so that the layer pattern
cannot be recovered by inference alone.

Returns:
A pass manager that groups operations into boxes.

Expand All @@ -250,6 +264,10 @@ def generate_boxing_pass_manager(
if remove_barriers == "immediately":
passes.append(RemoveBarriers())

if infer_layers is not False:
templates = None if infer_layers is True else infer_layers
passes.append(InsertLayerBarriers(layer_templates=templates))

if enable_gates:
passes.append(
GroupGatesIntoBoxes([Twirl(group=twirling_group, decomposition=decomposition)])
Expand Down
Loading
Loading