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. 24 from squander
import N_Qubit_Decomposition_adaptive
40 nontrivial_ratio = 0.5
46 matrix_size = pow(2, qbit_num )
58 parameters = np.zeros(num_of_parameters)
61 num_of_adaptive_layers = qbit_num*(qbit_num-1)
62 parameters[0:qbit_num*3] = (2*np.random.rand(qbit_num*3)-1)*2*np.pi
65 num_nontrivial =
int(nontrivial_ratio*num_of_adaptive_layers)
68 layer_indices = list(range(num_of_adaptive_layers))
70 for idx
in range(num_nontrivial):
73 chosen_layer = random.randint(1, len(layer_indices)-1)
74 adaptive_layer_idx = layer_indices[chosen_layer]
75 layer_indices.pop( chosen_layer )
79 start_idx = qbit_num*3 + (adaptive_layer_idx-1)*7
80 end_idx = start_idx + 7
81 parameters[start_idx:end_idx] = (2*np.random.rand(7)-1)*2*np.pi
89 cDecompose = N_Qubit_Decomposition_adaptive( np.eye(matrix_size), level_limit_max=5, level_limit_min=0 )
92 for idx
in range(level):
93 cDecompose.add_Adaptive_Layers()
95 cDecompose.add_Finalyzing_Layer_To_Gate_Structure()
99 num_of_parameters = cDecompose.get_Parameter_Num()
105 unitary = cDecompose.get_Matrix( parameters )
def create_randomized_parameters(num_of_parameters)
Call to construct random parameter, with limited number of non-trivial adaptive layers.