示例#1
0
 def test_kak_decomposition(self):
     """Verify KAK decomposition for random Haar unitaries.
     """
     for _ in range(100):
         unitary = random_unitary_matrix(4)
         with self.subTest(unitary=unitary):
             try:
                 two_qubit_kak(unitary, verify_gate_sequence=True)
             except MapperError as ex:
                 self.fail(str(ex))
示例#2
0
def generate_circuit_two_qubits(unitary_matrix_4x4):
    
    gate_list = two_qubit_kak(unitary_matrix_4x4)
    # print("gate_list")
    # print_list(gate_list)
    
    for gate_dict in gate_list:
        
        if gate_dict['name'] == 'cx':
            # qc.cx(q[0], q[1])
            print("qc." + gate_dict['name'] + 
                  "(" + 
                  "q[" + str( gate_dict['args'][0] ) + "], " + 
                  "q[" + str( gate_dict['args'][1] ) + "]" + 
                  ")"
            )
            
        else:
            # qc.u3(1.5707963267948966, 3.141592653589793, -3.141592653589793, q[0])
            print("qc.u3" + # gate_dict['name'] + 
                  "(" + 
                  str( gate_dict['params'][0] ) + ", " + 
                  str( gate_dict['params'][1] ) + ", " + 
                  str( gate_dict['params'][2] ) + ", " + 
                  "q[" + str( gate_dict['args'][0] ) + "]" + 
                  ")"
            )