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 @author: Peter Rakyta, Ph.D. 24 from squander
import N_Qubit_Decomposition
27 from squander
import N_Qubit_Decomposition_adaptive
34 print(
'**********************************************************************************')
35 print(
'**********************************************************************************')
36 print(
'******************** Solving the 4th IBM chellenge *******************************')
44 from scipy.io
import loadmat
48 from squander
import utils
51 data = loadmat(
'Umtx.mat')
58 matrix_size = len(Umtx)
62 cDecompose = N_Qubit_Decomposition_adaptive( Umtx.conj().T, level_limit_max=5, level_limit_min=1 )
66 cDecompose.set_Optimizer(
"BFGS")
71 cDecompose.Start_Decomposition()
74 cDecompose.List_Gates()
80 print(
'Constructing quantum circuit:')
83 quantum_circuit = cDecompose.get_Qiskit_Circuit()
85 print(quantum_circuit)
87 import numpy.linalg
as LA
90 decomposed_matrix = utils.get_unitary_from_qiskit_circuit( quantum_circuit )
91 product_matrix = np.dot(Umtx,decomposed_matrix.conj().T)
92 phase = np.angle(product_matrix[0,0])
93 product_matrix = product_matrix*np.exp(-1j*phase)
95 product_matrix = np.eye(matrix_size)*2 - product_matrix - product_matrix.conj().T
97 decomposition_error = (np.real(np.trace(product_matrix)))/2
99 print(
'The error of the decomposition is ' + str(decomposition_error))