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. 18 from qiskit
import QuantumCircuit, transpile
21 from pauli_exponent
import pauli_exponent
23 from qiskit
import execute
24 from qiskit
import Aer
26 from qgd_python.decomposition.qgd_N_Qubit_Decomposition_custom
import qgd_N_Qubit_Decomposition_custom
27 from qgd_python.utils
import get_unitary_from_qiskit_circuit
29 from scipy.interpolate
import interp1d
34 backend = Aer.get_backend(
'unitary_simulator')
38 optimized_parameters_mtx =
None 48 global optimized_parameters_mtx
50 optimized_parameters_mtx = np.loadtxt(filename1)
51 alpha_vec = np.loadtxt(filename2)
63 product_matrix = np.dot(Umtx1, Umtx2.conj().T)
64 phase = np.angle(product_matrix[0,0])
65 product_matrix = product_matrix*np.exp(-1j*phase)
66 product_matrix = np.eye(len(Umtx1))*2 - product_matrix - product_matrix.conj().T
67 distance = (np.real(np.trace(product_matrix)))/2
77 filename =
'19CNOT.qasm' 78 qc_trial = QuantumCircuit.from_qasm_file( filename )
79 qc_trial = transpile(qc_trial, optimization_level=3, basis_gates=[
'cz',
'cx',
'u3'], layout_method=
'sabre')
84 qc_orig = transpile(qc_orig, optimization_level=3, basis_gates=[
'cx',
'u3'], layout_method=
'sabre')
90 for jdx
in range(iteration_max):
92 cDecompose = qgd_N_Qubit_Decomposition_custom( Umtx_orig.conj().T )
95 cDecompose.set_Optimization_Tolerance( 1e-8 )
98 cDecompose.import_Qiskit_Circuit(qc_trial)
104 cDecompose.set_Optimization_Blocks( 200 )
107 cDecompose.set_Verbose(
False )
110 cDecompose.Start_Decomposition()
113 optimized_parameters_loc = cDecompose.get_Optimized_Parameters()
115 qc_final = cDecompose.get_Quantum_Circuit()
122 print(
'recheck decomposition error: ',decomposition_error)
124 if decomposition_error < 1e-6:
127 if decomposition_error < 1e-6:
128 return qc_final, optimized_parameters_loc
139 itp = interp1d(alpha_vec, optimized_parameters_mtx, axis=0, kind=
'linear')
140 initial_optimized_parameters = itp(alpha)
def load_preconstructed_data(filename1, filename2)
Call load precosntructed data for inerpolated optimization.
def get_interpolated_circuit(alpha)
???????????
def get_unitary_from_qiskit_circuit
Call to retrieve the unitary from QISKIT circuit.
def get_optimized_circuit(alpha, optimized_parameters_in=None)
???????????
def get_unitary_distance(Umtx1, Umtx2)
Calcuates the distance between two unitaries according to Eq.