def test_compute_action_X():
    """
    Action of Pauli operators on state
    """
    comp_basis_state = [0, 0, 0, 0]
    for ii in range(4):
        pauli_term = sX(ii)
        new_basis_state, coeff = compute_action(comp_basis_state, pauli_term,
                                                len(comp_basis_state))
        # abuse of comparisons in python
        true_basis_state = comp_basis_state.copy()
        true_basis_state[ii] = 1
        assert new_basis_state == true_basis_state
        assert np.isclose(coeff, 1)

    comp_basis_state = [1, 1, 1, 1]
    for ii in range(4):
        pauli_term = sX(ii)
        new_basis_state, coeff = compute_action(comp_basis_state, pauli_term,
                                                len(comp_basis_state))
        # abuse of comparisons in python
        true_basis_state = comp_basis_state.copy()
        true_basis_state[ii] = true_basis_state[ii] ^ 1
        assert new_basis_state == true_basis_state
        assert np.isclose(coeff, 1)
def test_compute_action_type_checks():
    """
    Make sure type checks are consistent and working
    """
    with pytest.raises(TypeError):
        compute_action([0, 0, 0, 0, 0], PauliSum([sX(0)]), 5)

    with pytest.raises(TypeError):
        compute_action([0, 0, 0, 0, 0], sX(0), 4)

    with pytest.raises(TypeError):
        compute_action(3, 'a', 4)

    with pytest.raises(TypeError):
        compute_action(-3, sX(0), 4)

    with pytest.raises(TypeError):
        compute_action('0001', sX(0), 4)
def test_compute_action_identity():
    """
    Action of Pauli operators on state
    """
    comp_basis_state = [0, 0, 0, 0]
    for ii in range(4):
        pauli_term = sI(ii)
        new_basis_state, coeff = compute_action(comp_basis_state, pauli_term,
                                                len(comp_basis_state))
        # abuse of comparisons in python
        assert new_basis_state == comp_basis_state
        assert np.isclose(coeff, 1)