def assert_implements_consistent_protocols(
    val: Any,
    *,
    exponents: Sequence[Any] = (0, 1, -1, 0.25, sympy.Symbol('s')),
    qubit_count: int | None = None,
    ignoring_global_phase: bool = False,
    setup_code: str = 'import cirq\nimport numpy as np\nimport sympy',
    global_vals: dict[str, Any] | None = None,
    local_vals: dict[str, Any] | None = None,
    ignore_decompose_to_default_gateset: bool = False,
) -> None:
    """Checks that a value is internally consistent and has a good __repr__."""
    global_vals = global_vals or {}
    local_vals = local_vals or {}

    _assert_meets_standards_helper(
        val,
        ignoring_global_phase=ignoring_global_phase,
        setup_code=setup_code,
        global_vals=global_vals,
        local_vals=local_vals,
        ignore_decompose_to_default_gateset=ignore_decompose_to_default_gateset,
    )

    for exponent in exponents:
        p = protocols.pow(val, exponent, None)
        if p is not None:
            _assert_meets_standards_helper(
                val**exponent,
                ignoring_global_phase=ignoring_global_phase,
                setup_code=setup_code,
                global_vals=global_vals,
                local_vals=local_vals,
                ignore_decompose_to_default_gateset=ignore_decompose_to_default_gateset,
            )
Checks that a value is internally consistent and has a good __repr__.
cirq-core/cirq/testing/consistent_protocols.py