Exemplo n.º 1
0
def test_qasm1():
    c = Circuit()
    c.h[0, 1].cx[0, 1].rz(1.23)[2].x[2].y[2].cz[2, 1].z[1].ry(4.56)[0]
    c.u1(1.32)[1].u2(1.23, 4.56)[2].u3(1.0, 2.0, 3.0)[0]
    c.cu1(1.0)[0, 1].cu2(2.0, 1.0)[1, 2].cu3(2.0, 3.0, 1.0)[2, 0]
    qasm = c.m[:].to_qasm()
    assert QASM == qasm
Exemplo n.º 2
0
def test_cu1_realvalue():
    E = eye(2)
    UPPER = Matrix([[1, 0], [0, 0]])
    LOWER = Matrix([[0, 0], [0, 1]])
    lambd = pi * 8 / 17
    U = Circuit().rz(lambd)[0].run_with_sympy_unitary()
    U /= U[0, 0]

    actual_1 = Circuit().cu1(lambd)[0, 1].run(backend="sympy_unitary")
    actual_1 /= actual_1[0, 0] # Ignore global phase
    expected_1 = reduce(TensorProduct, [E, UPPER]) + reduce(TensorProduct, [U, LOWER])
    assert actual_1 == expected_1

    for i in range(4):
        c = Circuit()
        if i % 2 == 1:
            c.x[0]
        if (i // 2) % 2 == 1:
            c.x[1]
        actual_2i = c.cu1(lambd.evalf())[0, 1].run_with_numpy()
        expected_2i = np.array(expected_1.col(i)).astype(complex).reshape(-1)
        assert 0.99999 < np.abs(np.dot(actual_2i.conj(), expected_2i)) < 1.00001