Exemplo n.º 1
0
def two_qubit_kak(unitary_matrix, verify_gate_sequence=False):
    """Deprecated after 0.8
    """
    warnings.warn(
        "two_qubit_kak function is now accessible under "
        "qiskit.quantum_info.synthesis", DeprecationWarning)
    return synthesis.two_qubit_kak(unitary_matrix)
Exemplo n.º 2
0
 def _define(self):
     """Calculate a subcircuit that implements this unitary."""
     if self.num_qubits == 1:
         q = QuantumRegister(1, "q")
         angles = euler_angles_1q(self.to_matrix())
         self.definition = [(U3Gate(*angles), [q[0]], [])]
     if self.num_qubits == 2:
         self.definition = two_qubit_kak(self.to_matrix())
Exemplo n.º 3
0
 def test_two_qubit_kak_from_paulis(self):
     """Verify decomposing Paulis with KAK
     """
     pauli_xz = Pauli(label='XZ')
     unitary = Unitary(Operator(pauli_xz).data)
     decomp_circuit = two_qubit_kak(unitary)
     result = execute(decomp_circuit, UnitarySimulatorPy()).result()
     decomp_unitary = Unitary(result.get_unitary())
     self.assertAlmostEqual(decomp_unitary, unitary)
Exemplo n.º 4
0
 def test_two_qubit_kak(self):
     """Verify KAK decomposition for random Haar 4x4 unitaries.
     """
     for _ in range(100):
         unitary = random_unitary(4)
         with self.subTest(unitary=unitary):
             decomp_circuit = two_qubit_kak(unitary)
             result = execute(decomp_circuit, UnitarySimulatorPy()).result()
             decomp_unitary = Unitary(result.get_unitary())
             self.assertAlmostEqual(process_fidelity(
                 unitary.representation, decomp_unitary.representation),
                                    1.0,
                                    places=7)
Exemplo n.º 5
0
 def test_two_qubit_kak_from_paulis(self):
     """Verify decomposing Paulis with KAK
     """
     pauli_xz = Pauli(label='XZ')
     unitary = Operator(pauli_xz)
     decomp_circuit = two_qubit_kak(unitary)
     result = execute(decomp_circuit, UnitarySimulatorPy()).result()
     decomp_unitary = Operator(result.get_unitary())
     equal_up_to_phase = matrix_equal(unitary.data,
                                      decomp_unitary.data,
                                      ignore_phase=True,
                                      atol=1e-7)
     self.assertTrue(equal_up_to_phase)
Exemplo n.º 6
0
 def test_two_qubit_kak(self):
     """Verify KAK decomposition for random Haar 4x4 unitaries.
     """
     for _ in range(100):
         unitary = random_unitary(4)
         with self.subTest(unitary=unitary):
             decomp_circuit = two_qubit_kak(unitary)
             result = execute(decomp_circuit, UnitarySimulatorPy()).result()
             decomp_unitary = Operator(result.get_unitary())
             equal_up_to_phase = matrix_equal(unitary.data,
                                              decomp_unitary.data,
                                              ignore_phase=True,
                                              atol=1e-7)
             self.assertTrue(equal_up_to_phase)