3 Created on Fri Jun 26 14:42:56 2020 4 Copyright (C) 2020 Peter Rakyta, Ph.D. 6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 16 You should have received a copy of the GNU General Public License 17 along with this program. If not, see http://www.gnu.org/licenses/. 19 @author: Peter Rakyta, Ph.D. 30 print(
'******************** Decomposing general 3-qubit matrix *******************************')
33 from scipy.stats
import unitary_group
41 matrix_size = int(2**qbit_num)
44 Umtx = unitary_group.rvs(matrix_size)
50 cDecompose.start_decomposition()
53 cDecompose.list_operations()
58 print(
'**********************************************************************************')
59 print(
'**********************************************************************************')
60 print(
'******************** Solving the 4th IBM chellenge *******************************')
68 from scipy.io
import loadmat
71 data = loadmat(
'Umtx.mat')
83 cDecompose.set_identical_blocks( {4: 2, 3: 1} )
86 cDecompose.set_max_layer_num( {4: 9, 3:4})
89 cDecompose.set_iteration_loops({4: 3, 3: 3, 2: 3})
92 cDecompose.set_verbose(
True )
97 cDecompose.start_decomposition()
100 cDecompose.list_operations()
106 print(
'Constructing quantum circuit:')
109 quantum_circuit = cDecompose.get_quantum_circuit()
111 print(quantum_circuit)
113 from qiskit
import execute
114 from qiskit
import Aer
115 import numpy.linalg
as LA
119 backend = Aer.get_backend(
'unitary_simulator')
122 job = execute(quantum_circuit, backend)
124 result = job.result()
127 decomposed_matrix = result.get_unitary(quantum_circuit)
131 product_matrix = np.dot(Umtx, decomposed_matrix.conj().T)
133 decomposition_error = LA.norm(product_matrix - np.identity(16)*product_matrix[0,0], 2)
135 print(
'The error of the decomposition is ' + str(decomposition_error))
A QGD Python interface class for the decomposition of N-qubit unitaries into U3 and CNOT gates.