2 Copyright 2020 Peter Rakyta, Ph.D. 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 8 http://www.apache.org/licenses/LICENSE-2.0 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 16 You should have received a copy of the GNU General Public License 17 along with this program. If not, see http://www.gnu.org/licenses/. 30 from qiskit
import QuantumCircuit, transpile
36 from squander
import utils
37 from squander
import N_Qubit_Decomposition_custom
38 from squander
import Qiskit_IO
43 from mpi4py
import MPI
45 except ModuleNotFoundError:
54 qc_orig = QuantumCircuit(5)
102 qc_orig.rx(-np.pi/2,0)
106 qc_orig.rx(-np.pi/2,0)
110 qc_orig.rx(-np.pi/2,0)
111 qc_orig.rx(-np.pi/2,1)
126 product_matrix = np.dot(Umtx1, Umtx2.conj().T)
127 phase = np.angle(product_matrix[0,0])
128 product_matrix = product_matrix*np.exp(-1j*phase)
129 product_matrix = np.eye(len(Umtx1))*2 - product_matrix - product_matrix.conj().T
130 distance = (np.real(np.trace(product_matrix)))/2
140 filename =
'data/19CNOT.qasm' 141 qc_trial = QuantumCircuit.from_qasm_file( filename )
143 qc_trial = transpile(qc_trial, optimization_level=1, basis_gates=[
'cz',
'cx',
'u3',
'rz',
'u', 'rx'], layout_method='sabre')
150 Umtx_orig = utils.get_unitary_from_qiskit_circuit( qc_orig )
158 for jdx
in range(iteration_max):
160 cDecompose = N_Qubit_Decomposition_custom( Umtx_orig.conj().T )
163 cDecompose.set_Optimization_Tolerance( 1e-5 )
166 cDecompose.import_Qiskit_Circuit( qc_trial )
169 cDecompose.set_Optimization_Blocks( 200 )
172 cDecompose.set_Optimizer( optimizer )
175 if not ( optimized_parameters
is None ):
176 cDecompose.set_Optimized_Parameters( optimized_parameters )
179 cDecompose.set_Verbose( 4 )
182 cDecompose.set_Cost_Function_Variant( 3 )
185 cDecompose.Start_Decomposition()
188 optimized_parameters_loc = cDecompose.get_Optimized_Parameters()
190 qc_final = cDecompose.get_Qiskit_Circuit()
193 Umtx_recheck = utils.get_unitary_from_qiskit_circuit( qc_final )
197 print(
'recheck decomposition error: ', decomposition_error)
200 if decomposition_error < 1e-3:
204 if decomposition_error < 1e-3:
205 return qc_final, optimized_parameters_loc
207 assert(decomposition_error < 1e-3)
214 """This is a test class of the python iterface to the decompsition classes of the QGD package""" 225 Umtx_check = utils.get_unitary_from_qiskit_circuit( qc_trial )
228 Circuit_Squander, parameters = Qiskit_IO.convert_Qiskit_to_Squander( qc_trial )
230 cDecompose = N_Qubit_Decomposition_custom( Umtx_check.conj().T )
232 cDecompose.set_Gate_Structure(Circuit_Squander)
234 cDecompose.set_Cost_Function_Variant( 4 )
237 cost_function = cDecompose.Optimization_Problem( parameters )
239 assert(cost_function < 1e-3)
247 alpha = 1.823631161607293
253 qc, optimized_parameters_tmp =
get_optimized_circuit( alpha+0.005, optimizer=
'BFGS', optimized_parameters=optimized_parameters )
256 qc, optimized_parameters_tmp =
get_optimized_circuit( alpha+0.005, optimizer=
'GRAD_DESCEND', optimized_parameters=optimized_parameters )
259 qc, optimized_parameters_tmp =
get_optimized_circuit( alpha+0.005, optimizer=
'ADAM', optimized_parameters=optimized_parameters )
def get_unitary_distance(Umtx1, Umtx2)
Calcuates the distance between two unitaries according to Eq.
def pauli_exponent(alpha=0.6217 *np.pi)
???????????
def test_circuit_import(self)
def get_optimized_circuit(alpha, optimizer='BFGS', optimized_parameters=None)
???????????