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

update

parent 9791d53c
No preview for this file type
[0.92326034 0.00141864 0.00065553 0.00065553 0.00141863 0.00011699
0.00000201 0.00000201 0.00065553 0.00000201 0.00000088 0.00000088
0.00065553 0.00000201 0.00000088 0.00000088 0.00141852 0.00001552
0.0000019 0.0000019 0.00000625 0.00076413 0.00000102 0.00000102
0.00000189 0.00000103 0. 0. 0.00000189 0.00000103
0. 0. 0.00065553 0.0000019 0.00000088 0.00000088
0.00000189 0.00000114 0. 0. 0.00000088 0.
0. 0. 0.00000088 0. 0. 0.
0.00065553 0.0000019 0.00000088 0.00000088 0.00000189 0.00000114
0. 0. 0.00000088 0. 0. 0.
0.00000088 0. 0. 0. 0.00065452 0.00000189
0.00000088 0.00000088 0.00000189 0.00000013 0. 0.
0.00000088 0. 0. 0. 0.00000088 0.
0. 0. 0.00000189 0.00000002 0. 0.
0.00000001 0.00000101 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.00000088 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0.00000088 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0.00065452 0.00000189 0.00000088 0.00000088
0.00000189 0.00000013 0. 0. 0.00000088 0.
0. 0. 0.00000088 0. 0. 0.
0.00000189 0.00000002 0. 0. 0.00000001 0.00000101
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0.00000088 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0.00000088 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.00065452 0.00000189 0.00000088 0.00000088 0.00000189 0.00000013
0. 0. 0.00000088 0. 0. 0.
0.00000088 0. 0. 0. 0.00000189 0.00000002
0. 0. 0.00000001 0.00000101 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0.00000088 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.00000088 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. ]
[0.94672286 0.0008531 0.00039599 0.00039599 0.00085309 0.00007313
0.00000072 0.00000072 0.00039599 0.00000072 0.00000032 0.00000032
0.00039599 0.00000072 0.00000032 0.00000032 0.00085305 0.00000802
0.00000068 0.00000068 0.00000223 0.00045747 0.00000036 0.00000036
0.00000068 0.00000037 0. 0. 0.00000068 0.00000037
0. 0. 0.00039599 0.00000068 0.00000032 0.00000032
0.00000068 0.00000041 0. 0. 0.00000032 0.
0. 0. 0.00000032 0. 0. 0.
0.00039599 0.00000068 0.00000032 0.00000032 0.00000068 0.00000041
0. 0. 0.00000032 0. 0. 0.
0.00000032 0. 0. 0. 0.00039563 0.00000068
0.00000032 0.00000032 0.00000068 0.00000004 0. 0.
0.00000032 0. 0. 0. 0.00000032 0.
0. 0. 0.00000068 0.00000001 0. 0.
0. 0.00000036 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.00000032 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0.00000032 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0.00039563 0.00000068 0.00000032 0.00000032
0.00000068 0.00000004 0. 0. 0.00000032 0.
0. 0. 0.00000032 0. 0. 0.
0.00000068 0.00000001 0. 0. 0. 0.00000036
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0.00000032 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0.00000032 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.00039563 0.00000068 0.00000032 0.00000032 0.00000068 0.00000004
0. 0. 0.00000032 0. 0. 0.
0.00000032 0. 0. 0. 0.00000068 0.00000001
0. 0. 0. 0.00000036 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0.00000032 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.00000032 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. ]
[0.05458592 0.0014035 0.00065553 0.00065553 0.00140349 0.00007227
0.00000201 0.00000201 0.00065553 0.00000201 0.00000088 0.00000088
0.00065553 0.00000201 0.00000088 0.00000088 0.00140338 0.0000104
0.0000019 0.0000019 0.00000625 0.00074899 0.00000102 0.00000102
0.00000189 0.00000103 0. 0. 0.00000189 0.00000103
0. 0. 0.00065553 0.0000019 0.00000088 0.00000088
0.00000189 0.00000114 0. 0. 0.00000088 0.
0. 0. 0.00000088 0. 0. 0.
0.00065553 0.0000019 0.00000088 0.00000088 0.00000189 0.00000114
0. 0. 0.00000088 0. 0. 0.
0.00000088 0. 0. 0. 0.00065452 0.00000189
0.00000088 0.00000088 0.00000189 0.00000013 0. 0.
0.00000088 0. 0. 0. 0.00000088 0.
0. 0. 0.00000189 0.00000002 0. 0.
0.00000001 0.00000101 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.00000088 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0.00000088 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0.00065452 0.00000189 0.00000088 0.00000088
0.00000189 0.00000013 0. 0. 0.00000088 0.
0. 0. 0.00000088 0. 0. 0.
0.00000189 0.00000002 0. 0. 0.00000001 0.00000101
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0.00000088 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0.00000088 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.00065452 0.00000189 0.00000088 0.00000088 0.00000189 0.00000013
0. 0. 0.00000088 0. 0. 0.
0.00000088 0. 0. 0. 0.00000189 0.00000002
0. 0. 0.00000001 0.00000101 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0.00000088 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.00000088 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. ]
[0.0399827 0.00084165 0.00039599 0.00039599 0.00084165 0.00003586
0.00000072 0.00000072 0.00039599 0.00000072 0.00000032 0.00000032
0.00039599 0.00000072 0.00000032 0.00000032 0.00084161 0.00000451
0.00000068 0.00000068 0.00000223 0.00044602 0.00000036 0.00000036
0.00000068 0.00000037 0. 0. 0.00000068 0.00000037
0. 0. 0.00039599 0.00000068 0.00000032 0.00000032
0.00000068 0.00000041 0. 0. 0.00000032 0.
0. 0. 0.00000032 0. 0. 0.
0.00039599 0.00000068 0.00000032 0.00000032 0.00000068 0.00000041
0. 0. 0.00000032 0. 0. 0.
0.00000032 0. 0. 0. 0.00039563 0.00000068
0.00000032 0.00000032 0.00000068 0.00000004 0. 0.
0.00000032 0. 0. 0. 0.00000032 0.
0. 0. 0.00000068 0.00000001 0. 0.
0. 0.00000036 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.00000032 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0.00000032 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0.00039563 0.00000068 0.00000032 0.00000032
0.00000068 0.00000004 0. 0. 0.00000032 0.
0. 0. 0.00000032 0. 0. 0.
0.00000068 0.00000001 0. 0. 0. 0.00000036
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0.00000032 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0.00000032 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.00039563 0.00000068 0.00000032 0.00000032 0.00000068 0.00000004
0. 0. 0.00000032 0. 0. 0.
0.00000032 0. 0. 0. 0.00000068 0.00000001
0. 0. 0. 0.00000036 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0.00000032 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.00000032 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. ]
[0.9175735 0.00168388 0.00078415 0.00078415 0.00168387 0.00005306
0.00000278 0.00000278 0.00078415 0.00000278 0.00000126 0.00000126
0.00078415 0.00000278 0.00000126 0.00000126 0.00168381 0.00002045
0.00000273 0.00000273 0.00000891 0.00090119 0.00000146 0.00000146
0.00000271 0.00000147 0.00000001 0.00000001 0.00000271 0.00000147
0.00000001 0.00000001 0.00078415 0.00000273 0.00000126 0.00000126
0.00000271 0.00000152 0.00000001 0.00000001 0.00000126 0.00000001
0. 0. 0.00000126 0.00000001 0. 0.
0.00078415 0.00000273 0.00000126 0.00000126 0.00000271 0.00000152
0.00000001 0.00000001 0.00000126 0.00000001 0. 0.
0.00000126 0.00000001 0. 0. 0.00078271 0.0000027
0.00000126 0.00000126 0.0000027 0.00000008 0. 0.
0.00000126 0. 0. 0. 0.00000126 0.
0. 0. 0.0000027 0.00000003 0. 0.
0.00000001 0.00000144 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.00000126 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0.00000126 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0.00078271 0.0000027 0.00000126 0.00000126
0.0000027 0.00000008 0. 0. 0.00000126 0.
0. 0. 0.00000126 0. 0. 0.
0.0000027 0.00000003 0. 0. 0.00000001 0.00000144
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0.00000126 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0.00000126 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.00078271 0.0000027 0.00000126 0.00000126 0.0000027 0.00000008
0. 0. 0.00000126 0. 0. 0.
0.00000126 0. 0. 0. 0.0000027 0.00000003
0. 0. 0.00000001 0.00000144 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0.00000126 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.00000126 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. ]
[0.05611403 0.0016786 0.00078415 0.00078415 0.00167858 0.00004854
0.00000278 0.00000278 0.00078415 0.00000278 0.00000126 0.00000126
0.00078415 0.00000278 0.00000126 0.00000126 0.00167853 0.00001427
0.00000273 0.00000273 0.00000891 0.0008959 0.00000146 0.00000146
0.00000271 0.00000147 0.00000001 0.00000001 0.00000271 0.00000147
0.00000001 0.00000001 0.00078415 0.00000273 0.00000126 0.00000126
0.00000271 0.00000152 0.00000001 0.00000001 0.00000126 0.00000001
0. 0. 0.00000126 0.00000001 0. 0.
0.00078415 0.00000273 0.00000126 0.00000126 0.00000271 0.00000152
0.00000001 0.00000001 0.00000126 0.00000001 0. 0.
0.00000126 0.00000001 0. 0. 0.00078271 0.0000027
0.00000126 0.00000126 0.0000027 0.00000008 0. 0.
0.00000126 0. 0. 0. 0.00000126 0.
0. 0. 0.0000027 0.00000003 0. 0.
0.00000001 0.00000144 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.00000126 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0.00000126 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0.00078271 0.0000027 0.00000126 0.00000126
0.0000027 0.00000008 0. 0. 0.00000126 0.
0. 0. 0.00000126 0. 0. 0.
0.0000027 0.00000003 0. 0. 0.00000001 0.00000144
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0.00000126 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0.00000126 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.00078271 0.0000027 0.00000126 0.00000126 0.0000027 0.00000008
0. 0. 0.00000126 0. 0. 0.
0.00000126 0. 0. 0. 0.0000027 0.00000003
0. 0. 0.00000001 0.00000144 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0.00000126 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.00000126 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0. 0. ]
mod interface;
pub mod mwpm;
pub use mwpm::minimum_weight_perfect_match;
pub use interface::mwpm_petgraph;
......@@ -8,21 +8,22 @@ extern "C" {
node_num: i32,
edge_num_max: i32,
edges: *const i32,
weights: *const f64,
);
}
pub fn mwpm_raw(node_num: i32, edge_num_max: i32, edges: &[i32]) -> Vec<i32> {
pub fn mwpm_raw(node_num: i32, edge_num_max: i32, edges: &[i32], weights: &[f64]) -> Vec<i32> {
unsafe {
let mut matching: Vec<i32> = Vec::with_capacity(node_num as usize);
let p = matching.as_mut_ptr();
minimum_weight_perfect_matching_t(p, node_num, edge_num_max, edges.as_ptr());
minimum_weight_perfect_matching_t(p, node_num, edge_num_max, edges.as_ptr(), weights.as_ptr());
matching.set_len(node_num as usize);
return matching;
}
}
pub fn mwpm_petgraph(graph: &Graph<i64, usize, Undirected>) -> Option<HashMap<usize, usize>> {
pub fn mwpm_petgraph(graph: &Graph<i64, f64, Undirected>) -> Option<HashMap<usize, usize>> {
let node_num = graph.node_count();
if node_num == 0 {
Some(HashMap::new())
......@@ -30,22 +31,23 @@ pub fn mwpm_petgraph(graph: &Graph<i64, usize, Undirected>) -> Option<HashMap<us
let mut edge_num_max = 0;
let edges_len = graph.edge_count() * 3;
let mut edges: Vec<i32> = vec![0; edges_len];
let mut weights: Vec<f64> = vec![0.0; edges_len];
let mut i = 0;
// log::debug!("{} {}", graph.node_count(), graph.edge_count());
for v1 in graph.node_indices() {
for v2 in graph.node_indices() {
if v1 < v2 {
if let Some(edge) = graph.find_edge(v1, v2) {
edges[i] = v1.index() as i32;
edges[i + 1] = v2.index() as i32;
edges[i + 2] = *graph.edge_weight(edge).unwrap() as i32;
edges[2 * i] = v1.index() as i32;
edges[2 * i + 1] = v2.index() as i32;
weights[i] = *graph.edge_weight(edge).unwrap();
edge_num_max = edge_num_max + 1;
i = i + 3;
i = i + 1;
}
}
}
}
let matching = mwpm_raw(node_num as i32, edge_num_max as i32, &edges);
let matching = mwpm_raw(node_num as i32, edge_num_max as i32, &edges, &weights);
let mut result: HashMap<usize, usize> = HashMap::new();
for m1 in 0..matching.len() {
let m2 = matching[m1] as usize;
......@@ -74,9 +76,18 @@ mod tests {
let node_num = 6;
let edge_num = 9;
let edges = vec![
0, 1, 3, 0, 3, 10, 0, 4, 7, 1, 2, -1, 1, 4, 5, 1, 5, 4, 2, 5, -7, 3, 4, 0, 4, 5, 4,
0, 1,
0, 3,
0, 4,
1, 2,
1, 4,
1, 5,
2, 5,
3, 4,
4, 5,
];
let result = mwpm_raw(node_num, edge_num, &edges);
let weights = vec![3.0, 10.0, 7.0, -1.0, 5.0, 4.0, -7.0, 0.0, 4.0];
let result = mwpm_raw(node_num, edge_num, &edges, &weights);
assert_eq!(result, vec![1, 0, 5, 4, 3, 2])
}
}
use std::io::Write;
use std::process::{Command, Stdio};
use std::fs;
use std::path::PathBuf;
use petgraph::{graph::NodeIndex, Graph, Undirected};
use std::collections::HashMap;
pub fn minimum_weight_perfect_match(
graph: &Graph<i64, usize, Undirected>,
) -> Option<HashMap<usize, usize>> {
if graph.node_count() == 0 {
return Some(HashMap::new());
}
let mut pathbuilder = PathBuf::from(file!());
pathbuilder.pop();
pathbuilder.push("blossom5");
let path = fs::canonicalize(pathbuilder).unwrap();
let mut child = Command::new(path.to_str().unwrap())
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.unwrap();
{
let stdin = &mut child.stdin.take().unwrap();
gen_blossom5_input(stdin, graph).unwrap();
}
let output = child.wait_with_output().unwrap();
let mut result: HashMap<usize, usize> = HashMap::new();
if output.status.success() {
let raw_output = String::from_utf8(output.stdout).unwrap();
// println!("output: {}", raw_output);
let mut iter = raw_output.split_whitespace();
iter.next();
loop {
if let Some(s1) = iter.next() {
let i1 = s1.parse::<usize>().unwrap();
let i2 = iter.next().unwrap().parse::<usize>().unwrap();
let w1 = *graph.node_weight(NodeIndex::new(i1)).unwrap();
let w2 = *graph.node_weight(NodeIndex::new(i2)).unwrap();
if w1 == -w2 - 1 {
let w = w1.abs() as usize;
result.insert(w, w);
} else if w1 >= 0 && w2 >= 0 {
result.insert(w1 as usize, w2 as usize);
}
} else {
break;
}
}
return Some(result);
}
None
}
fn gen_blossom5_input(
handle: &mut std::process::ChildStdin,
graph: &Graph<i64, usize, Undirected>,
) -> std::io::Result<()> {
let v = graph.node_count();
let e = graph.edge_count();
// let stdout = io::stdout();
// let mut handle = stdout.lock();
let s1 = format!("{} {}\n", v, e);
// print!("{}", s1);
handle.write_all(s1.as_bytes())?;
for v1 in graph.node_indices() {
for v2 in graph.node_indices() {
if v1 < v2 {
if let Some(edge) = graph.find_edge(v1, v2) {
let s = format!(
"{} {} {}\n",
v1.index(),
v2.index(),
graph.edge_weight(edge).unwrap()
);
// print!("{}", s);
handle.write_all(s.as_bytes())?;
}
}
}
}
Ok(())
}
#[allow(dead_code)]
struct BlossomVSolver {}
#[cfg(test)]
mod tests {
use super::*;
use petgraph::{Graph, Undirected};
use super::super::interface::mwpm_petgraph;
fn gen_test_graph() -> Graph<i64, usize, Undirected> {
let mut graph: Graph<i64, usize, Undirected> = Graph::new_undirected();
fn gen_test_graph() -> Graph<i64, f64, Undirected> {
let mut graph: Graph<i64, f64, Undirected> = Graph::new_undirected();
let v0 = graph.add_node(6);
let v1 = graph.add_node(7);
let v2 = graph.add_node(8);
let v3 = graph.add_node(9);
let v4 = graph.add_node(10);
let v5 = graph.add_node(11);
graph.add_edge(v0, v1, 3);
graph.add_edge(v0, v3, 10);
graph.add_edge(v0, v4, 7);
graph.add_edge(v1, v2, 0);
graph.add_edge(v1, v4, 5);
graph.add_edge(v1, v5, 4);
graph.add_edge(v2, v5, 0);
graph.add_edge(v3, v4, 0);
graph.add_edge(v4, v5, 4);
graph.add_edge(v0, v1, 3.0);
graph.add_edge(v0, v3, 10.0);
graph.add_edge(v0, v4, 7.0);
graph.add_edge(v1, v2, 0.0);
graph.add_edge(v1, v4, 5.0);
graph.add_edge(v1, v5, 4.0);
graph.add_edge(v2, v5, 0.0);
graph.add_edge(v3, v4, 0.0);
graph.add_edge(v4, v5, 4.0);
graph
}
......@@ -121,26 +30,9 @@ mod tests {
#[test]
fn blossom5_test() {
let graph = gen_test_graph();
let result = minimum_weight_perfect_match(&graph).unwrap();
let result = mwpm_petgraph(&graph).unwrap();
assert_eq!(*result.get(&6).unwrap(), 7);
assert_eq!(*result.get(&8).unwrap(), 11);
assert_eq!(*result.get(&9).unwrap(), 10);
}
#[test]
fn test_stdio() -> std::io::Result<()> {
let mut child = Command::new("head")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.unwrap();
{
let stdin = &mut child.stdin.take().unwrap();
let s = String::from("asdf");
stdin.write_all(s.as_bytes())?;
}
let output = child.wait_with_output()?;
assert_eq!(String::from_utf8(output.stdout).unwrap(), "asdf");
Ok(())
}
}
use crate::model::{SurfaceCodeModel, SurfModelClass};
use crate::error::{NoiseChannel, ErrorModel, MeasureNoiseModel};
use crate::utils::epoch;
use crate::error::{ErrorModel, MeasureNoiseModel, NoiseChannel};
use crate::model::{Stabilizer, SurfModelClass, SurfaceCodeModel};
use crate::utils::load_arr;
pub fn epoch(model: &mut SurfaceCodeModel, w1: f64, w2: f64) -> Option<Stabilizer> {
// model.state.gen_independent_error(model.error_model.decay);
let one_round = false;
if one_round {
model.update_measures();
model.perform_ecc();
} else {
model.perform_ecc_3d(model.gx.scale.xm, 0, w1, w2);
// model.perform_ecc_3d(100, 2, w1, w2);
}
model.has_logical_error()
}
pub fn naive_runner(xn: usize, zm: usize, p: f64) -> usize {
let mut model = SurfaceCodeModel::new(xn, zm, SurfModelClass::Surf1);
let channel = NoiseChannel::new_depolarizing_channel(p);
let error_model = ErrorModel::new(channel, None, 0.0);
let error_model = ErrorModel::new(channel, None);
let mut model = SurfaceCodeModel::new(xn, zm, &error_model, SurfModelClass::Surf1);
let mut epochs = 0;
loop {
epochs = epochs + 1;
if let Some(stablizer) = epoch(&mut model, &error_model) {
if let Some(stablizer) = epoch(&mut model, 1.0, 1.0) {
println!("{} epochs: error at {}", epochs, stablizer);
break;
}
......@@ -19,20 +31,63 @@ pub fn naive_runner(xn: usize, zm: usize, p: f64) -> usize {
epochs
}
pub fn test_runner1(xn: usize, zm: usize, p: f64) -> usize {
let mut model = SurfaceCodeModel::new(xn, zm, SurfModelClass::Surf1);
pub fn runner1(xn: usize, zm: usize, p: f64, measure_model: MeasureNoiseModel) -> usize {
let channel = NoiseChannel::new_depolarizing_channel(p);
let pm_total = 0.000;
let measure_model = MeasureNoiseModel::new(vec![1.0 - pm_total], vec![pm_total]);
let error_model = ErrorModel::new(channel, Some(measure_model), 0.0);
let mut w1 = f64::ln(p);
let mut w2 = f64::ln(measure_model.failure.prob_sum);
if w1.is_infinite() {
w1 = 0.0;
w2 = 1.0;
} else {
let wsum = w1 + w2;
w1 = w1 / wsum;
w2 = w2 / wsum;
}
w1 = 0.88;
w2 = 1.0 - w1;
log::debug!("{}, {}", w1, w2);
let error_model = ErrorModel::new(channel, Some(measure_model));
let mut model = SurfaceCodeModel::new(xn, zm, &error_model, SurfModelClass::Surf1);
let mut epochs = 0;
loop {
epochs = epochs + 1;
if let Some(stablizer) = epoch(&mut model, &error_model) {
println!("{} epochs: error at {}", epochs, stablizer);
log::trace!("running epoch {}", epochs);
if let Some(stablizer) = epoch(&mut model, w1, w2) {
log::info!("{} epochs: error at {}", epochs, stablizer);
break;
}
}
epochs
}
pub fn runner2(xn: usize, zm: usize, measure_rounds: usize, measure_model: MeasureNoiseModel) -> usize {
let p1 = 0.006;
let mut w1 = f64::ln(p1);
let mut w2 = f64::ln(measure_model.failure.prob_sum);
if w1.is_infinite() {
w1 = 0.0;
w2 = 1.0;
} else {
let wsum = w1 + w2;
w1 = 1.0 - w1 / wsum;
w2 = 1.0 - w2 / wsum;
}
w1 = 0.70;
w2 = 1.0 - w1;
log::debug!("{}, {}", w1, w2);
let channel = NoiseChannel::new_depolarizing_channel(p1);
let error_model = ErrorModel::new(channel, Some(measure_model));
let mut model = SurfaceCodeModel::new(xn, zm, &error_model, SurfModelClass::Surf1);
model.perform_ecc_3d(measure_rounds, 0, w1, w2);
let result = match model.has_logical_error() {
Some(Stabilizer::X) => 0,
Some(Stabilizer::Z) => 1,
None => 1,
};
log::info!("result: {}", result);
result
}