-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresult_one_point_model.py
More file actions
127 lines (101 loc) · 3.37 KB
/
result_one_point_model.py
File metadata and controls
127 lines (101 loc) · 3.37 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
"""
Simple simulation to test the surface code simulation is working
without looking at plots.
Run this code using mpi4py:
mpiexec python result_one_point_model.py topology=toric distance=10 iterations=100 cycles=10 protocol=thres_pg_paired a0=5.0 a1=0 eta=0.01 time=0.0555 pg=0.0035 measurement=single
mpiexec python result_one_point_model.py topology=toric distance=10 iterations=500 cycles=10 protocol=thres_eta a0=5.0 eta=0.0100 pg=0.0030 time=0.07928850 measurement=single_rounds
created-on: 09/12/17
@author: eduardo
"""
import sys
import numpy as np
from os.path import dirname, realpath
from mpi4py import MPI
import surface_code
import layers
import matching
def get_file_name(params):
protocol = "protocol=" + params["protocol"]
topology = "topology=" + params["topology"]
distance = "distance=" + params["distance"]
iterations = "iterations=" + params["iterations"]
cycles = "cycles=" + params["cycles"]
eta = "eta=" + params["eta"]
a0 = "a0=" + params["a0"]
a1 = "a1=" + params["a1"]
time = "time=" + params["time"]
param_names = [protocol, topology, distance, iterations, cycles,
eta, a0, a1, time]
file_name = "_".join(param_names)
return file_name
# Start the comm for mpi4py
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
#Set random seed
np.random.seed(rank)
# Get the arguments
pythonfile = sys.argv[0]
args = dict(arg.split('=') for arg in sys.argv[1:])
# Set parameters
distance = int(args["distance"])
topology = args["topology"]
iterations = int(args["iterations"])
a0 = float(args["a0"])
cycles = int(args["cycles"])
eta = float(args["eta"])
pg = float(args["pg"])
protocol = args["protocol"]
t = float(args["time"])
measurement = args["measurement"]
# Improved parameters
# Threshold over a0
ps = pg
pm = pg
a1 = 1/30.
theta = .63
# Other parameters
ignore = 0.05
# Initialize fail rate
fail_rate = 0
# Initialize objects
sc = surface_code.SurfaceCode(distance, topology)
lc = layers.Layers(sc)
sc.init_error_obj(topology, ps, pm, pg, eta, a0, a1, theta, protocol)
# Choose a measurement protocol
sc.select_measurement_protocol(t, a1, measurement, ignore)
# Perform measurements
for i in range(iterations):
# Noisy measurements
for t in range(cycles):
sc.noisy_measurement_cycle()
lc.add()
sc.measure_all_stabilizers()
lc.add()
# Decode and apply corrections
lc.decode()
# Measure logical qubit
logical = sc.measure_logical()
if -1 in logical[0] or -1 in logical[1]:
fail_rate += 1
lc.reset()
sc.reset()
fail_rate = fail_rate / float(iterations)
# Initializing variables. mpi4py requires that we pass numpy objects.
f_rate = np.zeros(1)
total = np.zeros(1)
f_rate[0] = fail_rate
# Communication: root node receives results with a collective "reduce"
comm.Reduce(f_rate, total, op=MPI.SUM, root=0)
# Root process saves the results
if comm.rank == 0:
total = total/float(size)
# total = total/float(cycles)
# print("size: ", size)
# print("id: ", rank)
# args_str = get_file_name(args)
# script_path = dirname(realpath(__file__))
# file_name = (script_path + "/results/" + args_str)
print(size, distance, protocol, measurement, a0, eta, pg, round(total[0],7), ":", round(total[0] / cycles, 7))
# print("rate :", round(total[0], 7) * cycles)
# np.save(file_name, total)