Skip to content

identity_filter

filter_out_identities

filter_out_identities(gates: Iterable[Gate]) -> list[Gate]

Filter out identity gates from a list of gates.

Parameters:

Name Type Description Default
gates Iterable[Gate]

The list of gates to filter.

required

Returns:

Type Description
list[Gate]

A list of gates with identity gates removed.

Source code in opensquirrel/utils/identity_filter.py
def filter_out_identities(gates: Iterable[Gate]) -> list[Gate]:
    """Filter out identity gates from a list of gates.

    Args:
        gates (Iterable[Gate]): The list of gates to filter.

    Returns:
        A list of gates with identity gates removed.

    """
    return [gate for gate in gates if not gate.is_identity()]