CircuitPass#

class CircuitPass(func: Callable[[QuantumCircuit], QuantumCircuit])[source]#

A decorator for quantum circuit transformation passes.

CircuitPass wraps a callable with signature QuantumCircuit -> QuantumCircuit and enforces type safety by checking that both the argument and the return value are QuantumCircuit instances.

It can be used as a bare decorator on a pass function, or instantiated explicitly with a function reference. Either way, the resulting CircuitPass object is itself callable and forwards calls to the wrapped function after performing the type checks.

Examples

Using CircuitPass as a decorator:

@CircuitPass
def my_pass(qc):
    # transform qc
    return qc

Wrapping an existing function explicitly:

from qrisp import CircuitPass, fuse_adjacents
typed_pass = CircuitPass(fuse_adjacents)
result = typed_pass(qc)

Inside factory functions that return configured passes:

def convert_to_cz(strict=False):
    @CircuitPass
    def _convert_to_cz(qc):
        ...
    return _convert_to_cz

Methods#

CircuitPass.compare_unitary(qc[, precision, ...])

Verify that this CircuitPass leaves the unitary invariant when applied to the given QuantumCircuit.

CircuitPass.compare_measurement(qc[, ...])

Verify that this CircuitPass leaves measurement statistics invariant when applied to the given QuantumCircuit.

CircuitPass.visualize(qc)

Print a before/after visualisation of this pass applied to qc.