Unverified Commit 4191dc1c authored by dwuggh's avatar dwuggh
Browse files

fix bug

parent a6f336b0
......@@ -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 => {
......
......@@ -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 m1 == -m2 - 1 {
if m2 == - m1 - 1 {
let m = m1 as usize;
let t = m / measure_num;
let d = m % measure_num;
......
......@@ -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 {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment