Sequential Quantum Gate Decomposer  v1.9.3
Powerful decomposition of general unitarias into one- and two-qubit gates gates
Renyi_entropy.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 @author: Peter Rakyta, Ph.D.
19 """
20 
22 
23 from squander import N_Qubit_Decomposition_adaptive
24 
25 
26 
27 
28 def create_custom_gate_structure(qbit_num, level_num=2):
29  """
30  Create gate structure
31  """
32 
33  from squander import Circuit
34 
35 
36  # creating an instance of the wrapper class Circuit
37  Circuit_ret = Circuit( qbit_num )
38 
39 
40  Layer = Circuit( qbit_num )
41  for target_qbit in range(qbit_num):
42  Layer.add_U3(target_qbit, True, True, True )
43 
44  Circuit_ret.add_Circuit( Layer )
45 
46 
47 
48  for idx in range(0,level_num):
49 
50  for target_qbit in range(1, qbit_num-1, 2):
51 
52  # creating an instance of the wrapper class Circuit
53  Layer = Circuit( qbit_num )
54 
55  Layer.add_CNOT( target_qbit=target_qbit, control_qbit=target_qbit+1 )
56  Layer.add_U3( target_qbit, True, True, True )
57  Layer.add_U3( target_qbit+1, True, True, True )
58 
59  Circuit_ret.add_Circuit( Layer )
60 
61 
62  for target_qbit in range(0, qbit_num-1, 2):
63 
64  # creating an instance of the wrapper class Circuit
65  Layer = Circuit( qbit_num )
66 
67  Layer.add_CNOT( target_qbit=target_qbit, control_qbit=target_qbit+1 )
68  Layer.add_U3( target_qbit, True, True, True )
69  Layer.add_U3( target_qbit+1, True, True, True )
70 
71  Circuit_ret.add_Circuit( Layer )
72 
73 
74 
75 
76  return Circuit_ret
77 
78 
79 
80 import numpy as np
81 
82 
83 # the number of qubits spanning the unitary
84 qbit_num = 22
85 level_num = 15
86 
87 gate_structure = create_custom_gate_structure( qbit_num, level_num )
88 
89 
90 # get the number of parameters
91 num_of_parameters = gate_structure.get_Parameter_Num()
92 
93 
94 # create random parameter set
95 parameters = np.random.uniform( 0.0, 2*np.pi, (num_of_parameters,) )
96 
97 # calculate the second Rényi entropy
98 
99 qubit_list = [0,1]
100 ()
101 
102 entropy = gate_structure.get_Second_Renyi_Entropy( parameters=parameters, qubit_list=qubit_list )
103 print( 'The second Renyi entropy is:', entropy)
104 
105 
106 page_entropy = len(qubit_list) * np.log(2.0) - 1.0/( pow(2, qbit_num-2*len(qubit_list)+1) )
107 
108 print( 'The page entropy: ', page_entropy)
109 
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
def create_custom_gate_structure(qbit_num, level_num=2)