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. 26 from scipy.stats
import unitary_group
27 from squander
import utils
34 This method is called to create custom gate structure for the decomposition on IBM QX2 38 from squander
import Circuit
41 Circuit_ret = Circuit( qbit_num )
43 disentangle_qubit = qbit_num - 1
47 for qbit
in range(0, disentangle_qubit ):
50 Layer = Circuit( qbit_num )
59 Layer.add_U3( 0, Theta, Phi, Lambda )
60 Layer.add_U3( disentangle_qubit, Theta, Phi, Lambda )
63 Layer.add_CNOT( 0, disentangle_qubit)
71 Layer.add_U3( 0, Theta, Phi, Lambda )
72 Layer.add_U3( 1, Theta, Phi, Lambda )
85 Layer.add_U3( 2, Theta, Phi, Lambda )
86 Layer.add_U3( disentangle_qubit, Theta, Phi, Lambda )
89 Layer.add_CNOT( disentangle_qubit, 2 )
93 Circuit_ret.add_Circuit( Layer )
103 This method is called to create custom gate structure for the decomposition on IBM QX2 107 from squander
import Circuit
110 Circuit_ret = Circuit( qbit_num )
112 disentangle_qubit = qbit_num - 1
116 for qbit
in range(0, disentangle_qubit ):
119 Layer = Circuit( qbit_num )
128 Layer.add_U3( 0, Theta, Phi, Lambda )
129 Layer.add_U3( disentangle_qubit, Theta, Phi, Lambda )
132 Layer.add_CNOT( 0, disentangle_qubit)
140 Layer.add_U3( 0, Theta, Phi, Lambda )
141 Layer.add_U3( 1, Theta, Phi, Lambda )
144 Layer.add_CNOT( 0, 1)
154 Layer.add_U3( 2, Theta, Phi, Lambda )
155 Layer.add_U3( 0, Theta, Phi, Lambda )
158 Layer.add_CNOT( 0, 2)
162 Circuit_ret.add_Circuit( Layer )
168 from squander
import N_Qubit_Decomposition
174 matrix_size =
int(2**qbit_num)
177 Umtx = unitary_group.rvs(matrix_size)
180 decomp = N_Qubit_Decomposition( Umtx.conj().T )
188 decomp.set_Gate_Structure( gate_structure )
192 decomp.set_Max_Layer_Num( {4: 60, 3:16} )
195 decomp.set_Optimization_Blocks( 20 )
198 decomp.Start_Decomposition()
205 quantum_circuit = decomp.get_Qiskit_Circuit()
208 import numpy.linalg
as LA
211 decomposed_matrix = utils.get_unitary_from_qiskit_circuit( quantum_circuit )
212 product_matrix = np.dot(Umtx,decomposed_matrix.conj().T)
213 phase = np.angle(product_matrix[0,0])
214 product_matrix = product_matrix*np.exp(-1j*phase)
216 product_matrix = np.eye(matrix_size)*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))
def create_custom_gate_structure_heavy_hex_3(qbit_num)
def create_custom_gate_structure_heavy_hex_4(qbit_num)