Skip to content
GitLab
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
4191dc1c
Unverified
Commit
4191dc1c
authored
Jul 13, 2021
by
dwuggh
Browse files
fix bug
parent
a6f336b0
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/model/codestate.rs
View file @
4191dc1c
...
...
@@ -79,7 +79,10 @@ impl CodeState {
}
pub
fn
flip_path
(
&
mut
self
,
stabilizer
:
Stabilizer
,
path
:
&
[
usize
])
{
let
bit
=
bit
(
stabilizer
);
let
bit
=
match
stabilizer
{
Stabilizer
::
X
=>
BIT_Z
,
Stabilizer
::
Z
=>
BIT_X
,
};
for
&
data_index
in
path
.iter
()
{
let
data_ref
=
self
.datas
.get_mut
(
data_index
)
.unwrap
();
*
data_ref
=
*
data_ref
^
bit
;
...
...
@@ -110,10 +113,10 @@ impl CodeState {
0
=>
{
data_char
.to_string
()
}
1
=>
{
BIT_X
=>
{
color_x
.paint
(
data_char
)
.to_string
()
}
2
=>
{
BIT_Z
=>
{
color_z
.paint
(
data_char
)
.to_string
()
}
3
=>
{
...
...
src/model/geometry/grid_geometry.rs
View file @
4191dc1c
...
...
@@ -129,7 +129,7 @@ impl Geometry for GridGeometry {
let
cm1
=
Coordinate
::
from_measure_index
(
self
.stabilizer
,
measure1
,
&
self
.scale
);
let
cm2
=
Coordinate
::
from_measure_index
(
self
.stabilizer
,
measure2
,
&
self
.scale
);
abs_sub
(
cm1
.x
,
cm2
.x
)
/
2
+
abs_sub
(
cm1
.y
,
cm2
.y
)
abs_sub
(
cm1
.x
,
cm2
.x
)
/
2
+
abs_sub
(
cm1
.y
,
cm2
.y
)
/
2
}
fn
get_defect_graph
(
&
self
,
defects
:
&
[
usize
])
->
Graph
<
i64
,
f64
,
Undirected
>
{
...
...
@@ -161,7 +161,7 @@ impl Geometry for GridGeometry {
}
}
}
log
::
debug!
(
"1D ecc: {:?}"
,
graph
);
//
log::debug!("1D ecc: {:?}", graph);
return
graph
;
}
...
...
@@ -203,7 +203,7 @@ impl Geometry for GridGeometry {
graph
.add_edge
(
node1
,
node2
,
weight
);
}
else
{
if
m
1
==
-
m2
-
1
{
if
m
2
==
-
m1
-
1
{
let
m
=
m1
as
usize
;
let
t
=
m
/
measure_num
;
let
d
=
m
%
measure_num
;
...
...
src/model/model.rs
View file @
4191dc1c
...
...
@@ -58,16 +58,17 @@ impl<'a> SurfaceCodeModel<'a> {
pub
fn
update_measures_perfect
(
&
mut
self
)
{
let
a
=
&
mut
self
.state.measures_x
;
let
datas_ref
=
&
mut
self
.state.datas
;
// Z error will generate X defects
for
mx
in
0
..
a
.len
()
{
let
datas
=
self
.gx
.get_measureq_datas
(
mx
);
let
result
=
datas
.into_iter
()
.rfold
(
0
,
|
x
,
y
|
x
^
datas_ref
[
y
]);
a
[
mx
]
=
result
&
BIT_
X
!=
BIT_
X
a
[
mx
]
=
result
&
BIT_
Z
!=
BIT_
Z
}
let
b
=
&
mut
self
.state.measures_z
;
for
mz
in
0
..
b
.len
()
{
let
datas
=
self
.gz
.get_measureq_datas
(
mz
);
let
result
=
datas
.into_iter
()
.rfold
(
0
,
|
x
,
y
|
x
^
datas_ref
[
y
]);
b
[
mz
]
=
result
&
BIT_
Z
!=
BIT_
Z
b
[
mz
]
=
result
&
BIT_
X
!=
BIT_
X
}
}
...
...
@@ -115,7 +116,7 @@ impl<'a> SurfaceCodeModel<'a> {
a
,
datas_ref
,
0
,
BIT_
X
,
BIT_
Z
,
&
self
.gx
,
channel
,
&
mut
self
.state.rng
,
...
...
@@ -124,7 +125,7 @@ impl<'a> SurfaceCodeModel<'a> {
a
,
datas_ref
,
1
,
BIT_
X
,
BIT_
Z
,
&
self
.gx
,
channel
,
&
mut
self
.state.rng
,
...
...
@@ -133,7 +134,7 @@ impl<'a> SurfaceCodeModel<'a> {
b
,
datas_ref
,
0
,
BIT_
Z
,
BIT_
X
,
&
self
.gz
,
channel
,
&
mut
self
.state.rng
,
...
...
@@ -142,7 +143,7 @@ impl<'a> SurfaceCodeModel<'a> {
b
,
datas_ref
,
1
,
BIT_
Z
,
BIT_
X
,
&
self
.gz
,
channel
,
&
mut
self
.state.rng
,
...
...
@@ -228,7 +229,13 @@ impl<'a> SurfaceCodeModel<'a> {
result
=
result
^
data
[
i
];
i
=
i
+
interval
;
}
result
=
result
&
bit
(
stabilizer
);
let
bit
=
match
stabilizer
{
Stabilizer
::
X
=>
BIT_Z
,
Stabilizer
::
Z
=>
BIT_X
,
};
result
=
result
&
bit
;
if
result
==
0
{
None
...
...
@@ -255,6 +262,7 @@ impl<'a> SurfaceCodeModel<'a> {
// print!("{:?}", graph);
if
let
Some
(
pairs
)
=
mwpm_petgraph
(
&
graph
)
{
for
(
&
m1
,
&
m2
)
in
pairs
.iter
()
{
log
::
debug!
(
"pair: {} {}"
,
m1
,
m2
);
let
path
=
geometry
.get_path_between_measures
(
m1
,
m2
);
self
.state
.flip_path
(
stabilizer
,
&
path
);
}
...
...
@@ -275,12 +283,13 @@ impl<'a> SurfaceCodeModel<'a> {
)
{
let
mut
mxs
:
Vec
<
Vec
<
bool
>>
=
Vec
::
new
();
let
mut
mzs
:
Vec
<
Vec
<
bool
>>
=
Vec
::
new
();
for
i
in
0
..
round
-
cutoff
{
//
log::debug!("running rounds {}...", i);
for
_
i
in
0
..
round
-
cutoff
{
//
decay error
self
.state
.gen_independent_error
(
self
.error_model.decay
);
self
.update_measures
();
mxs
.push
(
self
.state.measures_x
.clone
());
mzs
.push
(
self
.state.measures_z
.clone
());
self
.state
.print
(
self
.gx.scale.xn
,
self
.gz.scale.zm
);
}
for
_i
in
(
round
-
cutoff
)
..
round
{
...
...
@@ -362,7 +371,7 @@ impl<'a> SurfaceCodeModel<'a> {
log
::
debug!
(
"{}: path to boundary of {}: {:?}"
,
stabilizer
,
d1
,
path
);
self
.state
.flip_path
(
stabilizer
,
&
path
);
}
else
{
log
::
debug!
(
"pure measurement error of {}: {}"
,
stabilizer
,
t1
);
log
::
debug!
(
"pure measurement error of {}:
time {} at
{}"
,
stabilizer
,
t1
,
d1
);
}
}
}
else
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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