def state_vector_has_stabilizer(
    state_vector: np.ndarray, stabilizer: cirq.DensePauliString
) -> bool:
    """Checks that the state_vector is stabilized by the given stabilizer.

    The stabilizer should not modify the value of the state_vector, up to the
    global phase.

    Args:
        state_vector: An input state vector. Is not mutated by this function.
        stabilizer: A potential stabilizer of the above state_vector as a
          DensePauliString.

    Returns:
        Whether the stabilizer stabilizes the supplied state.
    """

    qubits = LineQubit.range(protocols.num_qubits(stabilizer))
    complex_dtype: type[np.complexfloating] = np.complex64
    if np.issubdtype(state_vector.dtype, np.complexfloating):
        complex_dtype = cast(type[np.complexfloating], state_vector.dtype)
    args = state_vector_simulation_state.StateVectorSimulationState(
        available_buffer=np.empty_like(state_vector),
        qubits=qubits,
        prng=np.random.RandomState(),
        initial_state=state_vector.copy(),
        dtype=complex_dtype,
    )
    protocols.act_on(stabilizer, args, qubits)
    return np.allclose(args.target_tensor, state_vector)
Checks that the state_vector is stabilized by the given stabilizer.

    The stabilizer should not modify the value of the state_vector, up to the
    global phase.

    Args:
        state_vector: An input state vector. Is not mutated by this function.
        stabilizer: A potential stabilizer of the above state_vector as a
          DensePauliString.

    Returns:
        Whether the stabilizer stabilizes the supplied state.
    
cirq-core/cirq/testing/consistent_act_on.py