Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
dwuggh
surfcode-rs
Commits
cdb12ebe
Unverified
Commit
cdb12ebe
authored
Jul 30, 2021
by
dwuggh
Browse files
add useful scripts
parent
e02e7962
Changes
2
Hide whitespace changes
Inline
Side-by-side
scripts/plot.py
0 → 100644
View file @
cdb12ebe
import
matplotlib.pyplot
as
plt
import
numpy
as
np
def
calc_average_time_to_fail
(
p
,
measure_rounds
):
return
-
measure_rounds
/
np
.
log2
(
p
)
def
attf_plot
(
times
,
p_locals
,
measure_rounds
=
30
,
name
=
None
):
fig
=
plt
.
figure
()
for
scale
,
ps
in
times
.
items
():
ps
=
np
.
array
(
ps
)
ps
=
calc_average_time_to_fail
(
ps
,
measure_rounds
)
plt
.
plot
(
p_locals
[
0
:],
ps
[
0
:],
"-+"
)
# plt.legend(str(scale))
plt
.
legend
(
list
(
map
(
str
,
times
.
keys
())))
plt
.
xlabel
(
r
"error rate $p/\%$"
)
plt
.
ylabel
(
r
"average rounds to failure"
)
# plt.show()
if
name
is
not
None
:
fig
.
savefig
(
name
)
def
plot2
():
fig
=
plt
.
figure
()
p3
=
np
.
arange
(
0.4
,
0.85
,
0.05
)
data_2
=
{
#p 0.004 0.005 0.006 0.007 0.008 0.009 1.000
8
:
[
0.9362
,
0.9060
,
0.8605
,
0.8180
,
0.7735
,
0.7272
,
0.6883
],
12
:
[
0.9553
,
0.9212
,
0.8674
,
0.8166
,
0.7481
,
0.7000
,
0.6519
],
16
:
[
0.9612
,
0.9296
,
0.8778
,
0.8144
,
0.7472
,
0.6760
,
0.6046
],
20
:
[
0.9785
,
0.9460
,
0.8940
,
0.7965
,
0.7395
,
0.6340
,
0.5995
],
}
# original
data_1
=
{
#p1 0.002 0.003 0.004 0.0045 0.005 0.0055
8
:
[
0.9755
,
0.9258
,
0.8533
,
0.811
,
0.7644
,
0.7057
],
12
:
[
0.9900
,
0.9558
,
0.8811
,
0.83
,
0.7559
,
0.6936
],
16
:
[
0.9948
,
0.977
,
0.8966
,
0.8392
,
0.7602
,
0.6742
],
20
:
[
0.9975
,
0.978
,
0.907
,
0.828
,
0.757
,
0.6445
]
}
# 以下 p 均为光子与qubit相互作用(e^{iπ \hat{n}}, decode)的error rate
# 直接利用光子测量
data_2
=
{
#p 0.004 0.005 0.006 0.007 0.008 0.009 1.000
8
:
[
0.9362
,
0.9060
,
0.8605
,
0.8180
,
0.7735
,
0.7272
,
0.6883
],
12
:
[
0.9553
,
0.9212
,
0.8674
,
0.8166
,
0.7481
,
0.7000
,
0.6519
],
16
:
[
0.9612
,
0.9296
,
0.8778
,
0.8144
,
0.7472
,
0.6760
,
0.6046
],
20
:
[
0.9785
,
0.9460
,
0.8940
,
0.7965
,
0.7395
,
0.6340
,
0.5995
],
}
data_2
=
{
#p 0.000 0.0005 0.001 0.0015 0.002 0.0025 0.003 0.0035
8
:
[
0.9996
,
0.9846
,
0.9606
,
0.9156
,
0.8678
,
0.7932
,
0.7104
,
0.6534
],
12
:
[
1
,
0.9938
,
0.9792
,
0.9434
,
0.868
,
0.7776
,
0.6948
,
0.6152
],
16
:
[
1
,
0.997
,
0.982
,
0.958
,
0.878
,
0.763
,
0.632
,
0.562
],
# 20: [0.9785, 0.9460, 0.8940, 0.7965, 0.7395, 0.6340, 0.5995],
}
# 利用bosonic code建立纠缠, 取p_local = 0, 0.003, 0.006三种情况
data_0000
=
{
8
:
[
0.9986
,
0.9992
,
0.9986
,
0.9987
,
0.9983
,
0.9991
,
0.9988
,
0.9990
,
0.9989
],
12
:
[
0.9996
,
0.9997
,
0.9998
,
0.9994
,
1
,
0.9999
,
0.9999
,
0.9998
,
0.9998
],
16
:
[
1
,
1
,
1
,
1
,
1
,
1
,
1
,
0.9998
,
1
],
20
:
[
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
]
}
data_0003
=
{
#p 0.004 0.0045 0.005 0.0055 0.006 0.0065 0.007 0.0075 0.008
8
:
[
0.9574
,
0.9594
,
0.9569
,
0.9562
,
0.9578
,
0.9603
,
0.9552
,
0.9553
,
0.9564
],
12
:
[
0.9743
,
0.9743
,
0.9743
,
0.9754
,
0.9755
,
0.9754
,
0.9753
,
0.9701
,
0.9708
],
16
:
[
0.9832
,
0.9794
,
0.9852
,
0.9808
,
0.9820
,
0.9820
,
0.9838
,
0.9832
,
0.9816
],
20
:
[
0.9887
,
0.9910
,
0.9900
,
0.9880
,
0.9887
,
0.9923
,
0.9873
,
0.9887
,
0.9917
]
}
data_0003
=
{
#p 0.000 0.001 0.002
8
:
[
0.962
,
0.9618
,
0.9598
],
12
:
[
0.9778
,
0.9762
,
0.9714
],
16
:
[
0.983
,
0.978
,
0.985
],
}
data_00045
=
{
#p 0.000 0.001 0.002
8
:
[
0.887
,
0.914
,
0.8954
],
12
:
[
0.9064
,
0.9074
,
0.8988
],
16
:
[
0.913
,
0.8902
,
0.905
],
}
data_0006
=
{
#p 0.004 0.0045 0.005 0.0055 0.006 0.0065 0.007 0.0075 0.008
8
:
[
0.7956
,
0.7975
,
0.7927
,
0.7962
,
0.8003
,
0.7967
,
0.7950
,
0.7885
,
0.7957
],
12
:
[
0.7854
,
0.7758
,
0.7788
,
0.7859
,
0.7881
,
0.7694
,
0.7767
,
0.7694
,
0.7712
],
16
:
[
0.7624
,
0.7734
,
0.7636
,
0.7728
,
0.7782
,
0.7550
,
0.7592
,
0.7648
,
0.7614
],
20
:
[
0.7617
,
0.7567
,
0.7613
,
0.7633
,
0.7543
,
0.7613
,
0.7633
,
0.7436
,
0.7450
]
}
p1
=
[
0.002
,
0.003
,
0.004
,
0.0045
,
0.005
,
0.0055
]
p2
=
np
.
arange
(
0.4
,
1.1
,
0.1
)
p2
=
np
.
arange
(
0.0
,
0.4
,
0.05
)
p3
=
np
.
arange
(
0.4
,
0.85
,
0.05
)
p3
=
[
0.
,
0.1
,
0.2
]
# p3 = np.arange(0.4, 0.75, 0.05)
if
__name__
==
'__main__'
:
print
(
p3
)
# attf_plot(data_1, p1, 30)
# attf_plot(data_2, p2, 30, "photon_measurement.png")
# attf_plot(data_2, p2, 30, "photon_measurement2.png")
attf_plot
(
data_0003
,
p3
,
30
,
"bosonic_code_puri_0.003_2.png"
)
attf_plot
(
data_00045
,
p3
,
30
,
"bosonic_code_puri_0.0045_2.png"
)
# attf_plot(data_0006, p3, 30, "bosonic_code_puri_0.006.png")
scripts/write_channel.py
0 → 100644
View file @
cdb12ebe
import
sys
import
numpy
as
np
# pm = 0.989939
# p1 = 0.0
# p2 = 0.0
def
pn
(
p
,
n
):
if
n
==
0
:
return
1
-
3
*
p
else
:
return
p
def
gen_coeff
(
p
):
coeff
=
[]
for
i
in
range
(
4
):
for
j
in
range
(
4
):
for
k
in
range
(
4
):
for
l
in
range
(
4
):
coeff
.
append
(
pn
(
p
,
i
)
*
pn
(
p
,
j
)
*
pn
(
p
,
k
)
*
pn
(
p
,
l
))
return
np
.
array
(
coeff
)
if
__name__
==
'__main__'
:
np
.
set_printoptions
(
suppress
=
True
)
argv
=
sys
.
argv
pm
=
float
(
argv
[
1
])
p1
=
float
(
argv
[
2
])
p2
=
float
(
argv
[
3
])
with
open
(
"{:4f}-{:4f}-{:4f}-channel.txt"
.
format
(
pm
,
p1
,
p2
),
'w'
)
as
f
:
correct
=
(
1
-
pm
)
*
gen_coeff
(
p1
)
# print(correct)
for
coeff
in
correct
:
f
.
write
(
str
(
coeff
))
f
.
write
(
' '
)
f
.
write
(
'
\n
'
)
error
=
pm
*
gen_coeff
(
p2
)
# print(error)
for
coeff
in
error
:
f
.
write
(
str
(
coeff
))
f
.
write
(
' '
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment