コード例 #1
0
def decompose_single_qiskit(unitary_matrix):
    (theta, phi, lamb) = twoq.euler_angles_1q(unitary_matrix)
    qc = QuantumCircuit(1)
    qc.u3(theta, phi, lamb, 0)
    new = what_is_the_matrix(qc)
    alpha = get_global_phase(unitary_matrix, new)
    print('theta= {}, phi= {}, lambda= {}, phase={}'.format(
        format_rotation(theta), format_rotation(phi), format_rotation(lamb),
        format_rotation(alpha)))
コード例 #2
0
def decompose_single(unitary_matrix):
    (theta, phi, lamb) = twoq.euler_angles_1q(unitary_matrix)
    qr = QuantumRegister(1)
    qc = QuantumCircuit(qr)
    qc.append(rrz_gate(lamb), [qr[0]])
    qc.ry(theta, qr[0])
    qc.append(rrz_gate(phi), [qr[0]])
    new = what_is_the_matrix(qc)
    alpha = get_global_phase(unitary_matrix, new)
    print('alpha= {}, beta= {}, gamma= {}, delta={}'.format(
        format_rotation(alpha), format_rotation(phi), format_rotation(theta),
        format_rotation(lamb)))
コード例 #3
0
 def check_one_qubit_euler_angles(self, operator, tolerance=1e-14):
     """Check euler_angles_1q works for the given unitary"""
     with self.subTest(operator=operator):
         target_unitary = operator.data
         angles = euler_angles_1q(target_unitary)
         decomp_unitary = U3Gate(*angles).to_matrix()
         target_unitary *= la.det(target_unitary)**(-0.5)
         decomp_unitary *= la.det(decomp_unitary)**(-0.5)
         maxdist = np.max(np.abs(target_unitary - decomp_unitary))
         if maxdist > 0.1:
             maxdist = np.max(np.abs(target_unitary + decomp_unitary))
         self.assertTrue(np.abs(maxdist) < tolerance, "Worst distance {}".format(maxdist))
コード例 #4
0
def decompose_single_qiskit_raw(unitary_matrix):
    alpha = phase(np.linalg.det(unitary_matrix)**(-1.0 / 2.0))

    (theta, lamb, phi) = twoq.euler_angles_1q(unitary_matrix)
    return alpha, theta, lamb, phi