Skip to content

Commit aed4b7c

Browse files
committed
Fix entropy tests, clean up braiding code
1 parent f349f9f commit aed4b7c

File tree

5 files changed

+27
-23
lines changed

5 files changed

+27
-23
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,11 @@
22

33
This repo contains reimplementaton of the paper
44
"[Realizing topologically ordered states on a quantum processor](https://arxiv.org/abs/2104.01180)" by Satzinger et al.
5-
in Qiskit.
5+
in Qiskit.
6+
7+
## GS preparation
8+
### Matching boundary conditions
9+
### Mixed boundary conditions
10+
## Entropy and topological entropy
11+
12+
## Braiding

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tqdm
2+
qiskit
3+
numpy

tests/test_entropy.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from qiskit import transpile
77
from tqdm import tqdm
88

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
1010
from topo_entropy import calculate_s_subsystems
1111
from topo_entropy import get_all_2x2_non_corner, get_all_2x3_non_corner, get_all_3x3_non_corner
1212
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='
3030
elif type == 'pauli':
3131
tc.measure_pauli(qubits, gates)
3232

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
3434
result = job.result()
3535
counts = result.get_counts(tc.circ)
3636
all_counts.append(counts)
3737
calculated_values = calculate_s_subsystems(all_counts, subsystems)
3838
print(expected_values, [c / np.log(2) for calc in calculated_values for c in calc])
3939
for expect, calc in zip(expected_values, calculated_values):
4040
for ve, vc in zip(expect, calc):
41-
continue
4241
np.testing.assert_allclose(vc / np.log(2), ve, rtol=rtol, atol=0.)
4342
return
4443

@@ -55,7 +54,7 @@ def test_2x2_entropy_pauli(self):
5554
backend_sim = Aer.get_backend('aer_simulator')
5655
x, y = 5, 7
5756
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)
5958

6059
def test_2x2_entropy_haar(self):
6160
expected_values = [(2., 1., 1.), (3., 3., 2.), (3.,)]
@@ -67,7 +66,7 @@ def test_2x2_entropy_haar(self):
6766
rtol=0.05)
6867

6968
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.,)]
7170

7271
backend_sim = Aer.get_backend('aer_simulator')
7372
x, y = 5, 7
@@ -84,8 +83,15 @@ def test_2x3_entropy_haar(self):
8483
for qubits in get_all_2x3_left_non_corner((x, y)):
8584
test_topo_entropy(backend_sim, (x, y), qubits, ABC_DIVISION_2x3_LEFT, expected_values, type='haar', cnt=100)
8685
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)
8995

9096

9197
if __name__ == '__main__':

topo_braiding.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,12 @@ def create_m_particles(tc, string):
2121

2222

2323
def apply_cxxxx_on_square(tc, upper_corner):
24-
cXXXX = np.kron(np.array([[1, 0], [0, 0]]), np.kron(sx, np.kron(sx, np.kron(sx, sx)))) + \
25-
np.kron(np.array([[0, 0], [0, 1]]), np.kron(s0, np.kron(s0, np.kron(s0, s0))))
26-
2724
x, y = upper_corner
2825
if x % 2 == 0:
2926
locs = [(x, y), (x + 1, y), (x + 2, y), (x + 1, y + 1)]
3027
else:
3128
locs = [(x, y), (x + 1, y - 1), (x + 2, y), (x + 1, y)]
32-
#print(locs)
3329
tc.circ.mct(control_qubits=[tc.ancillas[0]], target_qubit=[tc.regs[l[0]][l[1]] for l in locs])
34-
# tc.circ.unitary(cXXXX, [tc.regs[l[0]][l[1]] for l in locs] + [tc.ancillas[0]])
3530

3631

3732
def apply_cxxyyzz_on_square(tc, upper_corner):
@@ -54,7 +49,7 @@ def em_braiding_phase(backend, x, y):
5449
x_string = [(2, 1), (2, 2)]
5550
create_e_particles(tc, x_string)
5651

57-
z_string = [(1, 4), (0, 3), (1, 3)] # , (0,2), (1,2)]
52+
z_string = [(1, 4), (0, 3), (1, 3)]
5853
create_m_particles(tc, z_string)
5954

6055
tc.circ.h(tc.ancillas[0])

topo_entropy.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,8 @@ def purity_single_realization(counts):
2828
for s2 in counts:
2929
factor = (-2) ** (-hamming_distance(s1, s2))
3030
p2 = counts[s2] / N
31-
pur += factor * p1 * (N * p2 - 1) / (N - 1) # TODO unbias?
32-
# if q_cnt==4:
33-
# print(s1,s2,factor, p1,p2, factor * p1 * p2, pur, np.log(pur)/np.log(2))
34-
# print(len(counts), N, q_cnt, np.log(pur)/np.log(2), -q_cnt-np.log(pur)/np.log(2))
35-
# -log(pur) = -qcnt* log(2) - log(pur)
36-
return 2 ** q_cnt * pur
31+
pur += 2 ** q_cnt * factor * p1 * (N * p2 - 1) / (N - 1)
32+
return pur
3733

3834

3935
def second_renyi_entropy(all_counts):
@@ -42,7 +38,6 @@ def second_renyi_entropy(all_counts):
4238

4339

4440
def get_subsystem_counts(full_counts, sub_idx):
45-
print(sub_idx)
4641
all_subsystem_counts = []
4742
for counts in full_counts:
4843
subsystem_counts = defaultdict(lambda: 0)
@@ -60,8 +55,6 @@ def subsystem_sre(full_counts, sub_idx):
6055
def calculate_s_subsystems(full_counts, subsystems):
6156
one = [subsystem_sre(full_counts, sub_idx) for sub_idx in subsystems]
6257
two_subsystems = [subsystems[0] + subsystems[1], subsystems[0] + subsystems[2], subsystems[1] + subsystems[2]]
63-
print(subsystems)
64-
print(two_subsystems)
6558
two = [subsystem_sre(full_counts, sub_idx) for sub_idx in two_subsystems]
6659
three = [second_renyi_entropy(full_counts)]
6760
return one, two, three

0 commit comments

Comments
 (0)