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