6
6
from qiskit import transpile
7
7
from tqdm import tqdm
8
8
9
- from topo_entropy import ABC_DIVISION_2x2 , ABC_DIVISION_2x3_LEFT , ABC_DIVISION_2x3_RIGHT
9
+ from topo_entropy import ABC_DIVISION_2x2 , ABC_DIVISION_2x3_LEFT , ABC_DIVISION_2x3_RIGHT , ABC_DIVISION_3x3
10
10
from topo_entropy import calculate_s_subsystems
11
11
from topo_entropy import get_all_2x2_non_corner , get_all_2x3_non_corner , get_all_3x3_non_corner
12
12
from topo_entropy import get_all_2x3_left_non_corner , get_all_2x3_right_non_corner
@@ -30,15 +30,14 @@ def test_topo_entropy(backend, size, qubits, subsystems, expected_values, type='
30
30
elif type == 'pauli' :
31
31
tc .measure_pauli (qubits , gates )
32
32
33
- job = backend .run (transpile (tc .circ , backend ), shots = 1024 )
33
+ job = backend .run (transpile (tc .circ , backend ), shots = 15000 ) # note: number of shots is important
34
34
result = job .result ()
35
35
counts = result .get_counts (tc .circ )
36
36
all_counts .append (counts )
37
37
calculated_values = calculate_s_subsystems (all_counts , subsystems )
38
38
print (expected_values , [c / np .log (2 ) for calc in calculated_values for c in calc ])
39
39
for expect , calc in zip (expected_values , calculated_values ):
40
40
for ve , vc in zip (expect , calc ):
41
- continue
42
41
np .testing .assert_allclose (vc / np .log (2 ), ve , rtol = rtol , atol = 0. )
43
42
return
44
43
@@ -55,7 +54,7 @@ def test_2x2_entropy_pauli(self):
55
54
backend_sim = Aer .get_backend ('aer_simulator' )
56
55
x , y = 5 , 7
57
56
for qubits in get_all_2x2_non_corner ((x , y )):
58
- test_topo_entropy (backend_sim , (x , y ), qubits , ABC_DIVISION_2x2 , expected_values , type = 'pauli' , rtol = 0.06 )
57
+ test_topo_entropy (backend_sim , (x , y ), qubits , ABC_DIVISION_2x2 , expected_values , type = 'pauli' , rtol = 0.01 )
59
58
60
59
def test_2x2_entropy_haar (self ):
61
60
expected_values = [(2. , 1. , 1. ), (3. , 3. , 2. ), (3. ,)]
@@ -67,7 +66,7 @@ def test_2x2_entropy_haar(self):
67
66
rtol = 0.05 )
68
67
69
68
def test_2x3_entropy_pauli (self ):
70
- expected_values = [(2. , 2. , 2. ), (4. , 4 . , 3 . ), (4. ,)]
69
+ expected_values = [(2. , 2. , 2. ), (4. , 3 . , 4 . ), (4. ,)]
71
70
72
71
backend_sim = Aer .get_backend ('aer_simulator' )
73
72
x , y = 5 , 7
@@ -84,8 +83,15 @@ def test_2x3_entropy_haar(self):
84
83
for qubits in get_all_2x3_left_non_corner ((x , y )):
85
84
test_topo_entropy (backend_sim , (x , y ), qubits , ABC_DIVISION_2x3_LEFT , expected_values , type = 'haar' , cnt = 100 )
86
85
for qubits in get_all_2x3_right_non_corner ((x , y )):
87
- test_topo_entropy (backend_sim , (x , y ), qubits , ABC_DIVISION_2x3_RIGHT , expected_values , type = 'haar' ,
88
- cnt = 100 )
86
+ test_topo_entropy (backend_sim , (x , y ), qubits , ABC_DIVISION_2x3_RIGHT , expected_values , type = 'haar' , cnt = 100 )
87
+
88
+ def test_3x3_entropy_haar (self ):
89
+ expected_values = [(3. , 3. , 3. ), (6. , 5. , 4. ), (5. ,)]
90
+
91
+ backend_sim = Aer .get_backend ('aer_simulator' )
92
+ x , y = 5 , 7
93
+ for qubits in get_all_3x3_non_corner ((x , y )):
94
+ test_topo_entropy (backend_sim , (x , y ), qubits , ABC_DIVISION_3x3 , expected_values , type = 'haar' , cnt = 1000 )
89
95
90
96
91
97
if __name__ == '__main__' :
0 commit comments