Sequential Quantum Gate Decomposer  v1.9.3
Powerful decomposition of general unitarias into one- and two-qubit gates gates
test_get_nn_chanels.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 """
3 Created on Fri Jun 26 14:42:56 2020
4 Copyright 2020 Peter Rakyta, Ph.D.
5 
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
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
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.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see http://www.gnu.org/licenses/.
20 
21 @author: Peter Rakyta, Ph.D.
22 """
23 
25 
26 
27 
28 # cerate unitary q-bit matrix
29 from scipy.stats import unitary_group
30 import numpy as np
31 import random
32 
33 try:
34  from mpi4py import MPI
35  MPI_imported = True
36 except ModuleNotFoundError:
37  MPI_imported = False
38 
39 
40 
43 def create_randomized_parameters( num_of_parameters, qbit_num, levels ):
44 
45 
46  parameters = np.zeros(num_of_parameters)
47 
48 
49  # the number of adaptive layers in one level
50  num_of_adaptive_layers = int(qbit_num*(qbit_num-1)/2 * levels)
51 
52  parameters[0:qbit_num*3] = np.random.rand(qbit_num*3)*2*np.pi
53  #parameters[2*qbit_num:3*qbit_num] = np.random.rand(qbit_num)*2*np.pi/4
54  #parameters[qbit_num:2*qbit_num] = np.random.rand(qbit_num)*2*np.pi/4
55  #parameters[3*qbit_num-1] = 0
56  #parameters[3*qbit_num-2] = 0
57 
58  nontrivial_adaptive_layers = np.zeros( (num_of_adaptive_layers ))
59 
60  for layer_idx in range(num_of_adaptive_layers) :
61 
62  nontrivial_adaptive_layer = random.randint(0,1)
63  nontrivial_adaptive_layers[layer_idx] = nontrivial_adaptive_layer
64 
65  if (nontrivial_adaptive_layer) :
66 
67  # set the radom parameters of the chosen adaptive layer
68  start_idx = qbit_num*3 + layer_idx*7
69 
70  end_idx = start_idx + 7
71  parameters[start_idx:end_idx] = np.random.rand(7)*2*np.pi
72 
73 
74 
75 
76  return parameters, nontrivial_adaptive_layers
77 
78 
80  """This is a test class of the python iterface to the decompsition classes of the QGD package"""
81 
83  r"""
84  This method is called by pytest.
85  Test to create an instance of class N_Qubit_Decomposition.
86 
87  """
88 
89  from squander.nn.qgd_nn import qgd_nn
90  from squander.decomposition.qgd_N_Qubit_Decomposition_adaptive import qgd_N_Qubit_Decomposition_adaptive
91 
92  # number of qubits
93  qbit_num = 3
94 
95  # matrix size of the unitary
96  matrix_size = pow(2, qbit_num )
97 
98  # number of adaptive levels
99  levels = 1
100 
101  # retrieve the chanels
102  nn_class = qgd_nn()
103  #nn_class.get_NN_Chanels( unitary )
104  #nn_class.get_NN_Chanels( qbit_num=qbit_num, levels=levels )
105  chanels, nontrivial_adaptive_layers = nn_class.get_NN_Chanels( qbit_num=qbit_num, levels=levels, samples_num=4 )
106 
107  #print( chanels.shape )
108  #print( chanels )
109  #print( nontrivial_adaptive_layers )
110 
111 
def create_randomized_parameters(num_of_parameters, qbit_num, levels)
Call to construct random parameter, with limited number of non-trivial adaptive layers.