Ejemplo n.º 1
0
def test_decompose_4x4_optimal_tensor_products():
    Id = np.array([[1, 0], [0, 1]])
    X = np.array([[0, 1], [1, 0]])
    Y = np.array([[0, -1j], [1j, 0]])
    Z = np.array([[1, 0], [0, -1]])
    H = np.array([[1, 1], [1, -1]]) / np.sqrt(2)
    ops = [Id, X, Y, Z, H]

    for m1 in ops:
        for m2 in ops:
            A = np.kron(m1, m2)
            check_decomp(A, decompose_4x4_optimal(A), tol=2e-9)
Ejemplo n.º 2
0
def test_decompose_4x4_optimal_corner_cases():
    check_decomp(SWAP, decompose_4x4_optimal(SWAP))
    check_decomp(CNOT, decompose_4x4_optimal(CNOT))
    check_decomp(QFT_2, decompose_4x4_optimal(QFT_2))

    w = np.exp((2j / 3) * np.pi)
    A = w * np.array([[1, 1, 1, 0],
                      [1, w, w * w, 0],
                      [1, w * w, w, 0],
                      [0, 0, 0, np.sqrt(3)]]) / np.sqrt(3)
    check_decomp(A, decompose_4x4_optimal(A), tol=3e-8)

    Phi = np.sqrt(0.5) * np.array([[1, -1j, 0, 0],
                                   [0, 0, -1j, 1],
                                   [0, 0, -1j, -1],
                                   [1, 1j, 0, 0]])
    check_decomp(Phi, decompose_4x4_optimal(Phi))
Ejemplo n.º 3
0
def test_decompose_4x4_optimal_random_orthogonal():
    np.random.seed(100)
    for _ in range(10):
        A = ortho_group.rvs(4)
        check_decomp(A, decompose_4x4_optimal(A))
Ejemplo n.º 4
0
def test_decompose_4x4_optimal_random_unitary():
    np.random.seed(100)
    for _ in range(10):
        A = unitary_group.rvs(4)
        check_decomp(A, decompose_4x4_optimal(A))
Ejemplo n.º 5
0
 def test_matrix_to_gates_random_orthogonal(self):
     np.random.seed(100)
     for matrix_size in [2, 4, 8]:
         for _ in range(10):
             A = np.array(ortho_group.rvs(matrix_size))
             check_decomp(A, qd.matrix_to_gates(A))
Ejemplo n.º 6
0
 def test_matrix_to_gates_random_unitary(self):
     np.random.seed(100)
     for matrix_size in [2, 4, 8, 16]:
         for _ in range(10):
             A = np.array(unitary_group.rvs(matrix_size))
             check_decomp(A, qd.matrix_to_gates(A))