Unverified Commit a6f336b0 authored by dwuggh's avatar dwuggh
Browse files

add print util

parent b9e13522
use crate::error::NoiseChannel;
use rand::prelude::{ThreadRng, thread_rng};
use ansi_term::{Colour, Style};
/// The Stabilizer Formalism
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
......@@ -85,3 +86,72 @@ impl CodeState {
}
}
}
impl CodeState {
pub fn print(&self, xn: usize, zm: usize) {
let mut output = String::new();
let mut data_count = 0;
let mut x_count = 0;
let mut z_count = 0;
// x data error and stabilizer Z's defect
let color_x = Colour::Red.bold();
// z data error and stabilizer X's defect
let color_z = Colour::Green.bold();
let color_measerr = Colour::Yellow;
let data_char = "⋅ ";
for i in 0..(2 * xn + 1) {
for j in 0..(2 * zm + 1) {
if (i + j) % 2 == 0 {
// data qubit
let q = self.datas[data_count];
let data_str = match q {
0 => {
data_char.to_string()
}
1 => {
color_x.paint(data_char).to_string()
}
2 => {
color_z.paint(data_char).to_string()
}
3 => {
Colour::Purple.bold().paint(data_char).to_string()
}
_ =>{
unreachable!()
}
};
data_count += 1;
output.push_str(&data_str);
} else {
let s_str = if i % 2 == 0 {
// stabilizer Z
let s = self.measures_z[z_count];
z_count += 1;
if s {
"Z ".to_string()
} else {
color_x.paint("Z ").to_string()
}
} else {
// stabilizer X
let s = self.measures_x[x_count];
x_count += 1;
if s {
"X ".to_string()
} else {
color_z.paint("X ").to_string()
}
};
output.push_str(&s_str);
}
}
output.push('\n')
}
println!("{}", output)
}
}
......@@ -196,7 +196,10 @@ impl<'a> SurfaceCodeModel<'a> {
/// Z error: check the first column
pub fn has_logical_error(&mut self) -> Option<Stabilizer> {
self.update_measures_perfect();
self.state.print(self.gx.scale.xn, self.gz.scale.zm);
self.perform_ecc();
self.update_measures_perfect();
self.state.print(self.gx.scale.xn, self.gz.scale.zm);
// log::debug!("{:?}", self.state.datas);
let x = self._has_logical_error(Stabilizer::X);
let z = self._has_logical_error(Stabilizer::Z);
......
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