def test_check_commutation():
    term1 = sX(0) * sX(1)
    term2 = sY(0) * sY(1)
    term3 = sY(0) * sZ(2)

    assert qf.paulis_commute(term2, term3)
    assert qf.paulis_commute(term2, term3)
    assert not qf.paulis_commute(term1, term3)
def test_check_commutation_rigorous():
    # more rigorous test.  Get all operators in Pauli group
    N = 3
    qubits = list(range(N))
    ps = [qf.Pauli.term(qubits, ops) for ops in product(PAULI_OPS, repeat=N)]

    commuting = []
    non_commuting = []
    for left, right in product(ps, ps):
        if left * right == right * left:
            commuting.append((left, right))
        else:
            non_commuting.append((left, right))

    # now that we have our sets let's check against our code.
    for left, right in non_commuting:
        assert not qf.paulis_commute(left, right)

    for left, right in commuting:
        assert qf.paulis_commute(left, right)