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
34 from mpi4py
import MPI
36 except ModuleNotFoundError:
41 """This is a test class of the python iterface to the decompsition classes of the QGD package""" 45 This method is called by pytest. 46 Test to define custom gate structure in the decomposition 50 from squander
import N_Qubit_Decomposition
56 matrix_size =
int(2**qbit_num)
59 Umtx = unitary_group.rvs(matrix_size)
70 decomp.set_Gate_Structure( gate_structure )
74 decomp.set_Max_Layer_Num( {4: 60, 3:16} )
77 decomp.set_Optimization_Blocks( 20 )
80 decomp.Start_Decomposition()
87 quantum_circuit = decomp.get_Qiskit_Circuit()
89 import numpy.linalg
as LA
93 decomposed_matrix = np.asarray( utils.get_unitary_from_qiskit_circuit( quantum_circuit ) )
94 product_matrix = np.dot(Umtx,decomposed_matrix.conj().T)
95 phase = np.angle(product_matrix[0,0])
96 product_matrix = product_matrix*np.exp(-1j*phase)
98 product_matrix = np.eye(matrix_size)*2 - product_matrix - product_matrix.conj().T
100 decomposition_error = (np.real(np.trace(product_matrix)))/2
102 print(
'The error of the decomposition is ' + str(decomposition_error))
104 assert( decomposition_error < 1e-3 )
111 This method is called to create custom gate structure for the decomposition on IBM QX2 115 from squander
import Circuit
118 Circuit_ret = Circuit( qbit_num )
120 disentangle_qubit = qbit_num - 1
124 for qbit
in range(0, disentangle_qubit ):
127 Layer = Circuit( qbit_num )
137 Layer.add_U3( disentangle_qubit )
140 Layer.add_CNOT( 0, disentangle_qubit)
152 Layer.add_CNOT( 0, 1)
163 Layer.add_U3( disentangle_qubit )
166 Layer.add_CNOT( disentangle_qubit, 2 )
170 Circuit_ret.add_Circuit( Layer )
180 This method is called to create custom gate structure for the decomposition on IBM QX2 184 from squander
import Circuit
187 Circuit_ret = Circuit( qbit_num )
189 disentangle_qubit = qbit_num - 1
193 for qbit
in range(0, disentangle_qubit ):
196 Layer = Circuit( qbit_num )
206 Layer.add_U3( disentangle_qubit )
209 Layer.add_CNOT( 0, disentangle_qubit)
221 Layer.add_CNOT( 0, 1)
235 Layer.add_CNOT( 0, 2)
239 Circuit_ret.add_Circuit( Layer )
def create_custom_gate_structure_heavy_hex_3(self, qbit_num)
def test_N_Qubit_Decomposition_Heavy_Hex(self)
def create_custom_gate_structure_heavy_hex_4(self, qbit_num)
A base class to determine the decomposition of an N-qubit unitary into a sequence of CNOT and U3 gate...