-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresult_one_point_local.py
More file actions
121 lines (96 loc) · 2.98 KB
/
result_one_point_local.py
File metadata and controls
121 lines (96 loc) · 2.98 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
"""
Simple simulation to test the surface code simulation is working
without looking at plots.
Run this code using mpi4py:
mpiexec python result_one_point_local.py topology=toric distance=10 iterations=50 cycles=10 protocol=LOCAL p=0.006
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"]
p = "p=" + params["p"]
param_names = [protocol, topology, distance, iterations, cycles, p]
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()
# Get the arguments
pythonfile = sys.argv[0]
args = dict(arg.split('=') for arg in sys.argv[1:])
# Set random seed
# np.random.seed(45678 + rank)
# Parameters for noisy measurement
eta = 0.0
a0 = 0.0
a1 = 0.0
theta = 0.0
# Set parameters
distance = int(args["distance"])
topology = args["topology"]
iterations = int(args["iterations"])
p = float(args["p"])
cycles = int(args["cycles"])
protocol = args["protocol"]
p_not_complete = float(args["ignore"])
method = args["method"]
# Initialize fail rate
fail_rate = 0
# Paramters
ps = p
pm = p
pg = p
# 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(0.0, 0.0, method, p_not_complete)
# 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)
# print(rank, fail_rate)
# 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 rank == 0:
total = total / float(size)
# total = total / float(cycles)
print(size, method, distance, "p=", p, "incomplete=",p_not_complete, roud(total[0], 7), ":", round(total[0], 7)/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)
# np.save(file_name, total)
# print("TOTAL FAIL RATE: ", total)