Exemple #1
0
def test_one_qubit_commutators():
    """Test single qubit gate commutation relations."""
    for g1 in (IdentityGate, X, Y, Z, H, T, S):
        for g2 in (IdentityGate, X, Y, Z, H, T, S):
            e = Commutator(g1(0), g2(0))
            a = matrix_to_zero(represent(e, nqubits=1, format='sympy'))
            b = matrix_to_zero(represent(e.doit(), nqubits=1, format='sympy'))
            assert a == b
            e = Commutator(g1(0), g2(1))
            assert e.doit() == 0
Exemple #2
0
def test_one_qubit_commutators():
    """Test single qubit gate commutation relations."""
    for g1 in (IdentityGate, X, Y, Z, H, T, S):
        for g2 in (IdentityGate, X, Y, Z, H, T, S):
            e = Commutator(g1(0),g2(0))
            a = matrix_to_zero(represent(e, nqubits=1, format='sympy'))
            b = matrix_to_zero(represent(e.doit(), nqubits=1, format='sympy'))
            assert a == b
            e = Commutator(g1(0),g2(1))
            assert e.doit() == 0
Exemple #3
0
def test_commutator_identities():
    assert Comm(a * A, b * B) == a * b * Comm(A, B)
    assert Comm(A, A) == 0
    assert Comm(a, b) == 0
    assert Comm(A, B) == -Comm(B, A)
    assert Comm(A, B).doit() == A * B - B * A
    assert Comm(A, B *
                C).expand(commutator=True) == Comm(A, B) * C + B * Comm(A, C)
    assert (Comm(A * B, C * D).expand(commutator=True) == A * C * Comm(B, D) +
            A * Comm(B, C) * D + C * Comm(A, D) * B + Comm(A, C) * D * B)
    assert Comm(
        A, B**2).expand(commutator=True) == Comm(A, B) * B + B * Comm(A, B)
    assert (Comm(A**2, C**2).expand(commutator=True) ==
            Comm(A * B, C * D).expand(commutator=True).replace(B, A).replace(
                D, C) == A * C * Comm(A, C) + A * Comm(A, C) * C +
            C * Comm(A, C) * A + Comm(A, C) * C * A)
    assert Comm(A, C**-2).expand(commutator=True) == Comm(
        A, (1 / C) * (1 / D)).expand(commutator=True).replace(D, C)
    assert Comm(A + B, C + D).expand(
        commutator=True) == Comm(A, C) + Comm(A, D) + Comm(B, C) + Comm(B, D)
    assert Comm(A, B + C).expand(commutator=True) == Comm(A, B) + Comm(A, C)
    assert Comm(A**n, B).expand(commutator=True) == Comm(A**n, B)

    e = Comm(A, Comm(B, C)) + Comm(B, Comm(C, A)) + Comm(C, Comm(A, B))
    assert e.doit().expand() == 0
Exemple #4
0
def test_commutator_identities():
    assert Comm(a*A,b*B) == a*b*Comm(A,B)
    assert Comm(A, A) == 0
    assert Comm(a, b) == 0
    assert Comm(A,B) == -Comm(B,A)
    assert Comm(A,B).doit() == A*B - B*A
    assert Comm(A,B*C).expand(commutator=True) == Comm(A,B)*C + B*Comm(A,C)
    assert Comm(A*B,C).expand(commutator=True) == A*Comm(B,C) + Comm(A,C)*B
    assert Comm(A+B,C).expand(commutator=True) == Comm(A,C) + Comm(B,C)
    assert Comm(A,B+C).expand(commutator=True) == Comm(A,B) + Comm(A,C)
    e = Comm(A,Comm(B,C))+Comm(B,Comm(C,A))+Comm(C,Comm(A,B))
    assert e.doit().expand() == 0
Exemple #5
0
def test_commutator_identities():
    assert Comm(a * A, b * B) == a * b * Comm(A, B)
    assert Comm(A, A) == 0
    assert Comm(a, b) == 0
    assert Comm(A, B) == -Comm(B, A)
    assert Comm(A, B).doit() == A * B - B * A
    assert Comm(A, B *
                C).expand(commutator=True) == Comm(A, B) * C + B * Comm(A, C)
    assert Comm(A * B,
                C).expand(commutator=True) == A * Comm(B, C) + Comm(A, C) * B
    assert Comm(A + B, C).expand(commutator=True) == Comm(A, C) + Comm(B, C)
    assert Comm(A, B + C).expand(commutator=True) == Comm(A, B) + Comm(A, C)
    e = Comm(A, Comm(B, C)) + Comm(B, Comm(C, A)) + Comm(C, Comm(A, B))
    assert e.doit().expand() == 0