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_adaptive
27 """This is a test the calculation of Renyi entropy""" 35 Add layers to disentangle the 3rd qubit from the others 36 linear chain with IBM native operations 40 from squander
import Circuit
44 Circuit_ret = Circuit( qbit_num )
47 Layer = Circuit( qbit_num )
48 for target_qbit
in range(qbit_num):
49 Layer.add_U3(target_qbit)
51 Circuit_ret.add_Circuit( Layer )
55 for idx
in range(0,level_num):
57 for target_qbit
in range(1, qbit_num-1, 2):
60 Layer = Circuit( qbit_num )
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 )
66 Circuit_ret.add_Circuit( Layer )
69 for target_qbit
in range(0, qbit_num-1, 2):
72 Layer = Circuit( qbit_num )
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 )
78 Circuit_ret.add_Circuit( Layer )
101 num_of_parameters = gate_structure.get_Parameter_Num()
105 parameters = np.random.uniform( 0.0, 2*np.pi, (num_of_parameters,) )
112 entropy = gate_structure.get_Second_Renyi_Entropy( parameters=parameters, qubit_list=qubit_list )
113 print(
'The second Renyi entropy is:', entropy)
116 page_entropy = len(qubit_list) * np.log(2.0) - 1.0/( pow(2, qbit_num-2*len(qubit_list)+1) )
118 print(
'The page entropy: ', page_entropy)
121 assert( np.abs( page_entropy-entropy) < 1e-1 )
def create_custom_gate_structure(self, qbit_num, level_num=2)
def test_Renyi_entropy(self)