def test_sum():
    x = qf.sX(1)
    y = qf.sY(2, 2.0)
    s = qf.pauli_sum(x, y)
    assert ((((1, 'X'),), (1+0j)), (((2, 'Y'),), (2+0j))) == s.terms

    s2 = qf.pauli_sum(x, x)
    assert ((((1, 'X'),), (2+0j)),) == s2.terms

    s3 = qf.pauli_sum(x, x, y)
    s4 = qf.pauli_sum(y, x, x)

    assert s3 == s4
    assert ((((1, 'X'),), (2+0j)), (((2, 'Y'),), (2+0j))) == s3.terms

    qf.pauli_sum(x, x, x)
Example #2
0
def test_sum() -> None:
    x = qf.sX(1)
    y = qf.sY(2, 2.0)
    s = qf.pauli_sum(x, y)
    assert s == qf.Pauli(([1], "X", 1.0), ([2], "Y", 2.0))

    s2 = qf.pauli_sum(x, x)
    assert s2 == qf.Pauli(([1], "X", 2))

    s3 = qf.pauli_sum(x, x, y)
    s4 = qf.pauli_sum(y, x, x)

    assert s3 == s4
    assert s3 == qf.Pauli(([1], "X", 2), ([2], "Y", 2))

    qf.pauli_sum(x, x, x)
def test_merge_sum():
    p = qf.pauli_sum(qf.Pauli(((((1, 'Y'),), (3+0j)),)),
                     qf.Pauli(((((1, 'Y'),), (2+0j)),)))
    assert len(p) == 1
    assert p.terms[0][1] == 5
Example #4
0
def test_merge_sum() -> None:
    p = qf.pauli_sum(qf.Pauli.term([1], "Y", 3), qf.Pauli.term([1], "Y", 2))

    assert len(p) == 1
    assert p.terms[0][2] == 5