def S(state, qubit):
    """
    Applies a phase gate (S) rotation to stabilizers and destabilizers

    S = \\sqrt{Z}

    This is P in CHP.

    S = S
    Z = S^2
    S^{\\dagger} = S^3
    I = S^4

    X -> iW = Y
    Z -> Z
    W -> iX
    Y -> -X
    """
    stabs = state.stabs
    stabs.signs_minus ^= stabs.signs_i & stabs.col_x[qubit]
    stabs.signs_i ^= stabs.col_x[qubit]
    for gens in state.gen_list:
        gens.col_z[qubit] ^= gens.col_x[qubit]
        for i in gens.col_x[qubit]:
            gens.row_z[i] ^= {qubit}
