generate_boxing_pass_manager

samplomatic.transpiler.generate_boxing_pass_manager(enable_gates: bool = True, enable_measures: bool = True, measure_annotations: str = 'twirl', twirling_strategy: TwirlingStrategy | Literal['active', 'active_accum', 'all', 'active_circuit'] = 'active', inject_noise_targets: Literal['none', 'gates', 'measures', 'all'] = 'none', inject_noise_strategy: NoiseInjectionStrategy | Literal['no_modification', 'uniform_modification', 'individual_modification'] = 'no_modification', remove_barriers: bool = True) PassManager[source]

Construct a pass manager to group the operations in a circuit into boxes.

This function can be used to construct a new qiskit.transpiler.PassManager that puts the instructions of the circuit into annotated boxes.

>>> from qiskit.circuit import QuantumCircuit
>>> from samplomatic.transpiler import generate_boxing_pass_manager
>>>
>>> # Create a simple circuit to test with
>>> circuit = QuantumCircuit(3)
>>> circuit.cz(0, 1)
>>> circuit.cz(1, 2)
>>> circuit.measure_all()
>>>
>>> pm = generate_boxing_pass_manager()
>>>
>>> boxed_circuit = pm.run(circuit)
>>> boxed_circuit.draw("mpl")
../../_images/samplomatic-transpiler-generate_boxing_pass_manager-1.png

To group instructions into boxes, a pass manager returned by this function takes the following steps in order:

  • If remove_barriers is True, it removes all the barriers in the input circuit using the qiskit.transpiler.passes.RemoveBarriers pass.

  • If enable_gates is True, using the GroupGatesIntoBoxes pass, it creates boxes containing two-qubit gates and the single-qubit gates that preceed them. The resulting boxes are twirl-annotated and left-dressed, and contain a single layer of two-qubit gates.

  • If enable_measures is True, it uses the GroupMeasIntoBoxes pass to group the measurements. All the resulting boxes are left dressed. Depending on the value of measure_annotations, they own a Twirl annotation, a ChangeBasis annotation, or both.

  • It adds idling qubits to the boxes following the given twirling_strategy.

  • Using the AddTerminalRightDressedBoxes pass, it adds right-dressed boxes to ensure that the resulting pass manager can produce circuits that can be successfully turned into a template/samplex pair by the samplomatic.build() function.

  • If inject_noise_targets is not 'none', it uses the AddInjectNoise pass to add inject noise InjectNoise annotations.

Parameters:
  • enable_gates – Whether to collect single- and multi-qubit gates into boxes using the GroupGatesIntoBoxes pass.

  • enable_measures – Whether to collect measurements into boxes using the GroupMeasIntoBoxes pass.

  • measure_annotations

    The annotations placed on the measurement boxes by GroupMeasIntoBoxes when enable_measures is True. The supported values are:

  • twirling_strategy – The twirling strategy.

  • inject_noise_targets

    The boxes to annotate with an InjectNoise annotation using the AddInjectNoise pass. The supported values are:

    • 'none' to avoid annotating boxes of any kind.

    • 'gates' to annotate all the twirled boxes that contain entanglers, such as those created by the GroupGatesIntoBoxes pass, and avoid annotating all the other boxes.

    • 'measures' to annotate all the twirled boxes that own a classical register, such as those created by the GroupMeasIntoBoxes pass, and avoid annotating all the other boxes.

    • 'all' to target all the twirl-annotated boxes that contain entanglers and/or own classical registers.

  • inject_noise_strategy – The noise injection strategy for the AddInjectNoise pass.

  • remove_barriers – Whether to apply the qiskit.transpiler.passes.RemoveBarriers pass to the input circuit before beginning to group gates and measurements into boxes. Setting this to True generally leads to a smaller number of boxes in the output circuits.

Returns:

A pass manager that groups operations into boxes.

Raises:

TranspilerError – If the user selects a combination of inputs that is not supported.