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. 25 from squander
import N_Qubit_Decomposition_Tabu_Search
27 from squander
import Qiskit_IO
31 print(
'**********************************************************************************')
32 print(
'**********************************************************************************')
33 print(
'******************** Solving the 4th IBM chellenge *******************************')
41 from scipy.io
import loadmat
45 from squander
import utils
48 data = loadmat(
'Umtx.mat')
55 matrix_size = len(Umtx)
59 cDecompose = N_Qubit_Decomposition_Tabu_Search( Umtx.conj().T)
63 cDecompose.set_Optimizer(
"BFGS")
64 cDecompose.set_Cost_Function_Variant(3)
65 cDecompose.set_Verbose(3)
68 cDecompose.Start_Decomposition()
71 cDecompose.List_Gates()
77 print(
'Constructing quantum circuit:')
80 quantum_circuit = cDecompose.get_Qiskit_Circuit()
81 print(quantum_circuit)
83 import numpy.linalg
as LA
87 decomposed_matrix = utils.get_unitary_from_qiskit_circuit( quantum_circuit )
88 product_matrix = np.dot(Umtx,decomposed_matrix.conj().T)
89 phase = np.angle(product_matrix[0,0])
90 product_matrix = product_matrix*np.exp(-1j*phase)
92 product_matrix = np.eye(matrix_size)*2 - product_matrix - product_matrix.conj().T
94 decomposition_error = (np.real(np.trace(product_matrix)))/2
96 print(
'The error of the decomposition is ' + str(decomposition_error))