Skip to content

gate_replacer

replace

replace(
    ir: IR,
    gate: type[Gate],
    replacement_gates_function: Callable[..., list[Gate]],
) -> None

Replaces all occurrences of a specific gate in the circuit IR with a given sequence of other gates.

Parameters:

Name Type Description Default
ir IR

The circuit IR to modify.

required
gate type[Gate]

Gate to replace.

required
replacement_gates_function Callable[..., list[Gate]]

Function that returns a list of replacement gates.

required
Source code in opensquirrel/passes/decomposer/gate_replacer.py
def replace(ir: IR, gate: type[Gate], replacement_gates_function: Callable[..., list[Gate]]) -> None:
    """Replaces all occurrences of a specific gate in the circuit IR with a given sequence of other
    gates.

    Args:
        ir (IR): The circuit IR to modify.
        gate (type[Gate]): Gate to replace.
        replacement_gates_function (Callable[..., list[Gate]]): Function that returns a list of replacement gates.

    """
    generic_replacer = _GenericReplacer(gate, replacement_gates_function)
    decompose(ir, generic_replacer)