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. 23 from squander
import N_Qubit_Decomposition
24 from squander
import Circuit
27 from scipy.stats
import unitary_group
28 from squander
import utils
36 Circuit_ret = Circuit( qbit_num )
38 disentangle_qbit = qbit_num - 1
40 for qbit
in range(0, disentangle_qbit ):
43 layer = Circuit( qbit_num )
48 layer.add_U3( disentangle_qbit )
54 layer.add_CH( qbit, disentangle_qbit )
57 layer.add_CNOT( qbit, disentangle_qbit )
61 Circuit_ret.add_Circuit( layer )
73 matrix_size =
int(2**qbit_num)
76 Umtx = unitary_group.rvs(matrix_size)
79 decomp = N_Qubit_Decomposition( Umtx.conj().T )
87 decomp.set_Gate_Structure( gate_structure )
90 decomp.set_Optimization_Blocks( 20 )
93 decomp.Start_Decomposition()
96 quantum_circuit = decomp.get_Qiskit_Circuit()
100 print(quantum_circuit)
102 import numpy.linalg
as LA
105 decomposed_matrix = utils.get_unitary_from_qiskit_circuit( quantum_circuit )
106 product_matrix = np.dot(Umtx,decomposed_matrix.conj().T)
107 phase = np.angle(product_matrix[0,0])
108 product_matrix = product_matrix*np.exp(-1j*phase)
110 product_matrix = np.eye(matrix_size)*2 - product_matrix - product_matrix.conj().T
112 decomposition_error = (np.real(np.trace(product_matrix)))/2
114 print(
'The error of the decomposition is ' + str(decomposition_error))
116 from qiskit
import visualization
117 visualization.circuit_drawer(quantum_circuit, output=
"latex_source", interactive=
True, filename=
"cirquit_export", fold=10)
def create_custom_gate_structure(qbit_num)