Sequential Quantum Gate Decomposer  v1.9.3
Powerful decomposition of general unitarias into one- and two-qubit gates gates
example_tabu_search_decomposition.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 """
3 Created on Fri Jun 26 14:42:56 2020
4 Copyright 2020 Peter Rakyta, Ph.D.
5 
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
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
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.
17 
18 @author: Peter Rakyta, Ph.D.
19 """
20 
22 
23 
24 
25 from squander import N_Qubit_Decomposition_Tabu_Search
26 
27 from squander import Qiskit_IO
28 print(' ')
29 print(' ')
30 print(' ')
31 print('**********************************************************************************')
32 print('**********************************************************************************')
33 print('******************** Solving the 4th IBM chellenge *******************************')
34 print(' ')
35 print(' ')
36 print(' ')
37 
38 
39 #******************************
40 
41 from scipy.io import loadmat
42 import numpy as np
43 
44 
45 from squander import utils
46 
47 
48 data = loadmat('Umtx.mat')
49 
50 Umtx = data['Umtx']
51 
52 
53 
54 # determine the size of the unitary to be decomposed
55 matrix_size = len(Umtx)
56 
57 
59 cDecompose = N_Qubit_Decomposition_Tabu_Search( Umtx.conj().T)
60 
61 
62 
63 cDecompose.set_Optimizer("BFGS")
64 cDecompose.set_Cost_Function_Variant(3)
65 cDecompose.set_Verbose(3)
66 
68 cDecompose.Start_Decomposition()
69 
70 # list the decomposing operations
71 cDecompose.List_Gates()
72 
73 
74 
75 
76 print(' ')
77 print('Constructing quantum circuit:')
78 print(' ')
79 
80 quantum_circuit = cDecompose.get_Qiskit_Circuit()
81 print(quantum_circuit)
82 
83 import numpy.linalg as LA
84 
85 
86 
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)
91 
92 product_matrix = np.eye(matrix_size)*2 - product_matrix - product_matrix.conj().T
93 # the error of the decomposition
94 decomposition_error = (np.real(np.trace(product_matrix)))/2
95 
96 print('The error of the decomposition is ' + str(decomposition_error))
97 
98 
99 
100 
101 
102 
103 
104 
105 
106