def _is_identity(action) -> bool:
    """Check if the given action is equivalent to an identity."""
    gate = action.gate if isinstance(action, ops.Operation) else action
    if isinstance(gate, (ops.XPowGate, ops.CXPowGate, ops.CCXPowGate, ops.SwapPowGate)):
        return gate.exponent % 2 == 0
    return False
Check if the given action is equivalent to an identity.
cirq-core/cirq/sim/classical_simulator.py