PassManager#

class PassManager(passes: list[CircuitPass] | None = None)[source]#

A manager for organizing and applying quantum circuit transformation passes.

The PassManager maintains an ordered list of CircuitPass instances and applies them sequentially to quantum circuits.

Only CircuitPass instances are accepted — raw functions must be wrapped first, for example with the @CircuitPass decorator or by calling CircuitPass(my_func).

Examples

Build a pipeline with +=, then inspect, insert, and remove passes:

>>> from qrisp import PassManager
>>> from qrisp import convert_to_cz, fuse_adjacents, remove_barriers
>>>
>>> pm = PassManager()
>>> pm += convert_to_cz()
>>> pm += fuse_adjacents
>>> pm += remove_barriers
>>>
>>> print(pm)
PassManager(['convert_to_cz', 'fuse_adjacents', 'remove_barriers'])
>>>
>>> # Insert a pass at a specific position
>>> from qrisp import decompose
>>> pm.insert_pass(1, decompose)
>>> print(pm)
PassManager(['convert_to_cz', 'decompose', 'fuse_adjacents', 'remove_barriers'])
>>>
>>> # Remove the last pass
>>> pm.remove_pass(len(pm) - 1)
>>> print(pm)
PassManager(['convert_to_cz', 'decompose', 'fuse_adjacents'])
>>>
>>> transpiled_qc = pm.run(qc)

Methods#

PassManager.__iadd__(other)

Add a pass or extend with the passes of another PassManager in-place.

PassManager.add_pass(pass_obj)

Add a transformation pass to the manager.

PassManager.insert_pass(index, pass_obj)

Insert a pass at a specific position.

PassManager.remove_pass(index)

Remove a pass at the specified index.

PassManager.clear()

Remove all passes from the manager.

PassManager.run(qc)

Apply all passes in sequence to the quantum circuit.

PassManager.verify(qc, verification_type[, ...])

Verify every pass in the manager against qc one by one.