3 Created on Fri Jun 26 14:42:56 2020 4 Copyright 2020 Peter Rakyta, Ph.D. 6 Licensed under the Apache License, Version 2.0 (the "License"); 7 you may not use this file except in compliance with the License. 8 You may obtain a copy of the License at 10 http://www.apache.org/licenses/LICENSE-2.0 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 See the License for the specific language governing permissions and 16 limitations under the License. 18 You should have received a copy of the GNU General Public License 19 along with this program. If not, see http://www.gnu.org/licenses/. 21 @author: Peter Rakyta, Ph.D. 29 from scipy.stats
import unitary_group
31 from squander
import utils
35 from mpi4py
import MPI
37 except ModuleNotFoundError:
43 """This is a test class of the python iterface to the decompsition classes of the QGD package""" 49 This method is called by pytest. 50 Test to decompose a 4-qubit unitary of the IBM chellenge 54 from squander
import N_Qubit_Decomposition
55 from scipy.io
import loadmat
58 data = loadmat(
'data/Umtx.mat')
64 cDecompose =
N_Qubit_Decomposition( Umtx.conj().T, optimize_layer_num=
True, initial_guess=
"CLOSE_TO_ZERO" )
68 cDecompose.set_Identical_Blocks( {4: 2, 3: 1} )
71 cDecompose.set_Max_Layer_Num( {4: 9, 3:4} )
74 cDecompose.set_Iteration_Loops({4: 3, 3: 3, 2: 3})
80 cDecompose.set_Optimization_Blocks( 20 )
83 cDecompose.Start_Decomposition()
86 cDecompose.List_Gates()
89 quantum_circuit = cDecompose.get_Qiskit_Circuit()
92 print(quantum_circuit)
95 import numpy.linalg
as LA
99 decomposed_matrix = utils.get_unitary_from_qiskit_circuit( quantum_circuit )
100 product_matrix = np.dot(Umtx,decomposed_matrix.conj().T)
101 phase = np.angle(product_matrix[0,0])
102 product_matrix = product_matrix*np.exp(-1j*phase)
104 product_matrix = np.eye(16)*2 - product_matrix - product_matrix.conj().T
106 decomposition_error = (np.real(np.trace(product_matrix)))/2
108 print(
'The error of the decomposition is ' + str(decomposition_error))
110 assert( decomposition_error < 1e-3 )
116 This method is called by pytest. 117 Test to decompose a 4-qubit unitary of the IBM chellenge 121 from squander
import N_Qubit_Decomposition_adaptive
122 from scipy.io
import loadmat
125 data = loadmat(
'data/Umtx.mat')
135 cDecompose.set_Verbose( 3 )
138 rng = np.random.default_rng( 42 )
139 num_of_parameters = cDecompose.get_Parameter_Num()
140 parameters = rng.random(num_of_parameters)*2*np.pi
142 cDecompose.set_Optimized_Parameters( parameters )
145 cDecompose.Start_Decomposition()
148 cDecompose.List_Gates()
151 quantum_circuit = cDecompose.get_Qiskit_Circuit()
154 print(quantum_circuit)
156 import numpy.linalg
as LA
159 decomposed_matrix = utils.get_unitary_from_qiskit_circuit( quantum_circuit )
160 product_matrix = np.dot(Umtx,decomposed_matrix.conj().T)
161 phase = np.angle(product_matrix[0,0])
162 product_matrix = product_matrix*np.exp(-1j*phase)
164 product_matrix = np.eye(16)*2 - product_matrix - product_matrix.conj().T
166 decomposition_error = (np.real(np.trace(product_matrix)))/2
168 print(
'The error of the decomposition is ' + str(decomposition_error))
170 assert( decomposition_error < 1e-3 )
178 This method is called by pytest. 179 Test to decompose a 4-qubit unitary of the IBM chellenge 183 from squander
import N_Qubit_Decomposition_adaptive
184 from scipy.io
import loadmat
187 data = loadmat(
'data/Umtx.mat')
198 cDecompose.set_Verbose( 3 )
201 rng = np.random.default_rng( 42 )
202 num_of_parameters = cDecompose.get_Parameter_Num()
203 parameters = rng.random(num_of_parameters)*2*np.pi
205 cDecompose.set_Optimized_Parameters( parameters )
208 cDecompose.Start_Decomposition()
211 cDecompose.List_Gates()
214 quantum_circuit = cDecompose.get_Qiskit_Circuit()
217 print(quantum_circuit)
219 import numpy.linalg
as LA
222 decomposed_matrix = utils.get_unitary_from_qiskit_circuit( quantum_circuit )
223 decomposed_matrix = decomposed_matrix[0:14,:]
224 product_matrix = np.dot(Umtx,decomposed_matrix.conj().T)
225 phase = np.angle(product_matrix[0,0])
226 product_matrix = product_matrix*np.exp(-1j*phase)
228 print( product_matrix.shape )
230 product_matrix = np.eye(product_matrix.shape[0])*2 - product_matrix - product_matrix.conj().T
232 decomposition_error = (np.real(np.trace(product_matrix)))/2
234 print(
'The error of the decomposition is ' + str(decomposition_error))
236 assert( decomposition_error < 1e-3 )
242 This method is called by pytest. 243 Test to decompose a 4-qubit unitary of the IBM chellenge 247 from squander
import N_Qubit_Decomposition_Tree_Search
248 from scipy.io
import loadmat
251 data = loadmat(
'data/Umtx.mat')
261 cDecompose.set_Verbose( 3 )
264 cDecompose.Start_Decomposition()
267 cDecompose.List_Gates()
270 quantum_circuit = cDecompose.get_Qiskit_Circuit()
273 print(quantum_circuit)
275 import numpy.linalg
as LA
278 decomposed_matrix = utils.get_unitary_from_qiskit_circuit( quantum_circuit )
279 product_matrix = np.dot(Umtx,decomposed_matrix.conj().T)
280 phase = np.angle(product_matrix[0,0])
281 product_matrix = product_matrix*np.exp(-1j*phase)
283 product_matrix = np.eye(16)*2 - product_matrix - product_matrix.conj().T
285 decomposition_error = (np.real(np.trace(product_matrix)))/2
287 print(
'The error of the decomposition is ' + str(decomposition_error))
289 assert( decomposition_error < 1e-3 )
296 This method is called by pytest. 297 Test to decompose a 4-qubit unitary of the IBM chellenge 301 from squander
import N_Qubit_Decomposition_Tabu_Search
302 from scipy.io
import loadmat
305 data = loadmat(
'data/Umtx.mat')
315 cDecompose.set_Verbose( 3 )
318 cDecompose.Start_Decomposition()
321 cDecompose.List_Gates()
324 quantum_circuit = cDecompose.get_Qiskit_Circuit()
327 print(quantum_circuit)
329 import numpy.linalg
as LA
332 decomposed_matrix = utils.get_unitary_from_qiskit_circuit( quantum_circuit )
333 product_matrix = np.dot(Umtx,decomposed_matrix.conj().T)
334 phase = np.angle(product_matrix[0,0])
335 product_matrix = product_matrix*np.exp(-1j*phase)
337 product_matrix = np.eye(16)*2 - product_matrix - product_matrix.conj().T
339 decomposition_error = (np.real(np.trace(product_matrix)))/2
341 print(
'The error of the decomposition is ' + str(decomposition_error))
343 assert( decomposition_error < 1e-3 )
A base class to determine the decomposition of an N-qubit unitary into a sequence of CNOT and U3 gate...
A base class to determine the decomposition of an N-qubit unitary into a sequence of CNOT and U3 gate...
def test_IBM_Chellenge_tree_search(self)
def test_IBM_Chellenge_adaptive(self)
def test_IBM_Chellenge_tabu_search(self)
A base class to determine the decomposition of an N-qubit unitary into a sequence of CNOT and U3 gate...
def test_IBM_Chellenge(self)
def test_IBM_Chellenge_adaptive_rectangular_input(self)
A base class to determine the decomposition of an N-qubit unitary into a sequence of CNOT and U3 gate...