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 cDecompose.Start_Decomposition()
141 cDecompose.List_Gates()
144 quantum_circuit = cDecompose.get_Qiskit_Circuit()
147 print(quantum_circuit)
149 import numpy.linalg
as LA
152 decomposed_matrix = utils.get_unitary_from_qiskit_circuit( quantum_circuit )
153 product_matrix = np.dot(Umtx,decomposed_matrix.conj().T)
154 phase = np.angle(product_matrix[0,0])
155 product_matrix = product_matrix*np.exp(-1j*phase)
157 product_matrix = np.eye(16)*2 - product_matrix - product_matrix.conj().T
159 decomposition_error = (np.real(np.trace(product_matrix)))/2
161 print(
'The error of the decomposition is ' + str(decomposition_error))
163 assert( decomposition_error < 1e-3 )
171 This method is called by pytest. 172 Test to decompose a 4-qubit unitary of the IBM chellenge 176 from squander
import N_Qubit_Decomposition_adaptive
177 from scipy.io
import loadmat
180 data = loadmat(
'data/Umtx.mat')
191 cDecompose.set_Verbose( 3 )
194 cDecompose.Start_Decomposition()
197 cDecompose.List_Gates()
200 quantum_circuit = cDecompose.get_Qiskit_Circuit()
203 print(quantum_circuit)
205 import numpy.linalg
as LA
208 decomposed_matrix = utils.get_unitary_from_qiskit_circuit( quantum_circuit )
209 decomposed_matrix = decomposed_matrix[0:14,:]
210 product_matrix = np.dot(Umtx,decomposed_matrix.conj().T)
211 phase = np.angle(product_matrix[0,0])
212 product_matrix = product_matrix*np.exp(-1j*phase)
214 print( product_matrix.shape )
216 product_matrix = np.eye(product_matrix.shape[0])*2 - product_matrix - product_matrix.conj().T
218 decomposition_error = (np.real(np.trace(product_matrix)))/2
220 print(
'The error of the decomposition is ' + str(decomposition_error))
222 assert( decomposition_error < 1e-3 )
228 This method is called by pytest. 229 Test to decompose a 4-qubit unitary of the IBM chellenge 233 from squander
import N_Qubit_Decomposition_Tree_Search
234 from scipy.io
import loadmat
237 data = loadmat(
'data/Umtx.mat')
247 cDecompose.set_Verbose( 3 )
250 cDecompose.Start_Decomposition()
253 cDecompose.List_Gates()
256 quantum_circuit = cDecompose.get_Qiskit_Circuit()
259 print(quantum_circuit)
261 import numpy.linalg
as LA
264 decomposed_matrix = utils.get_unitary_from_qiskit_circuit( quantum_circuit )
265 product_matrix = np.dot(Umtx,decomposed_matrix.conj().T)
266 phase = np.angle(product_matrix[0,0])
267 product_matrix = product_matrix*np.exp(-1j*phase)
269 product_matrix = np.eye(16)*2 - product_matrix - product_matrix.conj().T
271 decomposition_error = (np.real(np.trace(product_matrix)))/2
273 print(
'The error of the decomposition is ' + str(decomposition_error))
275 assert( decomposition_error < 1e-3 )
282 This method is called by pytest. 283 Test to decompose a 4-qubit unitary of the IBM chellenge 287 from squander
import N_Qubit_Decomposition_Tabu_Search
288 from scipy.io
import loadmat
291 data = loadmat(
'data/Umtx.mat')
301 cDecompose.set_Verbose( 3 )
304 cDecompose.Start_Decomposition()
307 cDecompose.List_Gates()
310 quantum_circuit = cDecompose.get_Qiskit_Circuit()
313 print(quantum_circuit)
315 import numpy.linalg
as LA
318 decomposed_matrix = utils.get_unitary_from_qiskit_circuit( quantum_circuit )
319 product_matrix = np.dot(Umtx,decomposed_matrix.conj().T)
320 phase = np.angle(product_matrix[0,0])
321 product_matrix = product_matrix*np.exp(-1j*phase)
323 product_matrix = np.eye(16)*2 - product_matrix - product_matrix.conj().T
325 decomposition_error = (np.real(np.trace(product_matrix)))/2
327 print(
'The error of the decomposition is ' + str(decomposition_error))
329 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...