Exemplo n.º 1
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)
Exemplo n.º 2
0
def test_sub() -> None:
    x = sX(1)
    y = sY(2, 2.0)
    s = x - y
    assert s == qf.Pauli(([1], "X", 1), ([2], "Y", -2))

    s = 2 - y
    assert str(s) == "+(2+0j) +(-2+0j) sY(2)"
Exemplo n.º 3
0
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
Exemplo n.º 4
0
def test_add() -> None:
    x = sX(1)
    y = sY(2, 2.0)
    s = y + x
    assert s == qf.Pauli(([1], "X", 1), ([2], "Y", 2))