-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresult_full_test.py
More file actions
138 lines (110 loc) · 3.51 KB
/
result_full_test.py
File metadata and controls
138 lines (110 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"""
Simple simulation to test the surface code simulation is working
without looking at plots.
created-on: 09/12/17
@author: eduardo
"""
import numpy as np
import matplotlib.pyplot as plt
import surface_code
import layers
import matching
"""
Test the planar code.
Perfect syndrome extraction.
"""
# Define the parameters
distance = 10
topology = "planar"
weights = [1, 1]
iterations = 5
p = 0.05
fail_rate_planar = 0
# Initialize objects
sc = surface_code.SurfaceCode(distance, topology)
lc = layers.Layers(sc)
# Perform measurements
for i in range(iterations):
# Errors and measurements
sc.apply_qubit_error(p, p)
sc.measure_all_stabilizers()
lc.add()
# Get anyons
anyons_star, anyons_plaq = lc.find_anyons_all()
# Decode
match_star = matching.match(distance, anyons_star, topology,
"star", time=0, weights=weights)
match_plaq = matching.match(distance, anyons_plaq, topology,
"plaq", time=0, weights=weights)
# Apply corrections
sc.correct_error("star", match_star)
sc.correct_error("plaq", match_plaq)
# Check for errors in decoding and correcting
sc.measure_stabilizer_type("star")
sc.measure_stabilizer_type("plaq")
if (sc.qubits[:, sc.tags != "Q"] == -1).any():
print("FAILURE CORRECTING")
logical = sc.measure_logical()
if -1 in logical[0] or -1 in logical[1]:
fail_rate_planar += 1
lc.reset()
sc.reset()
"""
Test the toric code.
Imperfect syndrome extraction.
"""
# Define the parameters
distance = 10
topology = "toric"
weights = [1, 1]
iterations = 5
p = 0.005
q = 0.005
cycles = 50
fail_rate_toric = 0
# Initialize objects
sc = surface_code.SurfaceCode(distance, topology)
lc = layers.Layers(sc)
# Perform measurements
for i in range(iterations):
# Errors and measurements
for s in range(cycles):
sc.apply_qubit_error(p, p)
sc.measure_all_stablizers()
sc.apply_measurement_error(q)
lc.add()
# Get anyons
anyons_star, anyons_plaq = lc.find_anyons_all()
# Decode
match_star = matching.match(distance, anyons_star, topology,
"star", time=cycles, weights=weights)
match_plaq = matching.match(distance, anyons_plaq, topology,
"plaq", time=cycles, weights=weights)
# Apply corrections
sc.correct_error("star", match_star, cycles)
sc.correct_error("plaq", match_plaq, cycles)
# Round of perfect detection to eliminate stray errors
lc.reset()
sc.measure_all_stablizers()
lc.add()
anyons_star, anyons_plaq = lc.find_anyons_all()
match_star = matching.match(distance, anyons_star, topology,
"star", time=0, weights=weights)
match_plaq = matching.match(distance, anyons_plaq, topology,
"plaq", time=0, weights=weights)
sc.correct_error("star", match_star, cycles)
sc.correct_error("plaq", match_plaq, cycles)
# Check for errors in decoding and correcting
sc.measure_stabilizer_type("star")
sc.measure_stabilizer_type("plaq")
if (sc.qubits[:, sc.tags != "Q"] == -1).any():
print("FAILURE CORRECTING")
logical = sc.measure_logical()
if -1 in logical[0] or -1 in logical[1]:
fail_rate_toric += 1
lc.reset()
sc.reset()
fail_rate_toric = fail_rate_toric/float(iterations)
fail_rate_planar = fail_rate_planar/float(iterations)
print("SUCCESS RATE TORIC: ", 1 - fail_rate_toric)
print("SUCCESS RATE PLANAR: ", 1 - fail_rate_planar)