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 )
50 layer.add_U3( qbit, Theta, Phi, Lambda )
51 layer.add_U3( disentangle_qbit, Theta, Phi, Lambda )
57 layer.add_CH( qbit, disentangle_qbit )
60 layer.add_CNOT( qbit, disentangle_qbit )
64 Circuit_ret.add_Circuit( layer )
76 matrix_size =
int(2**qbit_num)
79 Umtx = unitary_group.rvs(matrix_size)
82 decomp = N_Qubit_Decomposition( Umtx.conj().T )
90 decomp.set_Gate_Structure( gate_structure )
93 decomp.set_Optimization_Blocks( 20 )
96 decomp.Start_Decomposition()
99 quantum_circuit = decomp.get_Qiskit_Circuit()
103 print(quantum_circuit)
105 import numpy.linalg
as LA
108 decomposed_matrix = utils.get_unitary_from_qiskit_circuit( quantum_circuit )
109 product_matrix = np.dot(Umtx,decomposed_matrix.conj().T)
110 phase = np.angle(product_matrix[0,0])
111 product_matrix = product_matrix*np.exp(-1j*phase)
113 product_matrix = np.eye(matrix_size)*2 - product_matrix - product_matrix.conj().T
115 decomposition_error = (np.real(np.trace(product_matrix)))/2
117 print(
'The error of the decomposition is ' + str(decomposition_error))
119 from qiskit
import visualization
120 visualization.circuit_drawer(quantum_circuit, output=
"latex_source", interactive=
True, filename=
"cirquit_export", fold=10)
def create_custom_gate_structure(qbit_num)