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

update

parent b5dff9dc
use surfcode_rs::*;
use rayon::prelude::*;
use utils::load_arr;
use utils::load_channel_coeffs_from_file;
use controller::*;
fn main() {
......@@ -17,11 +16,12 @@ fn main() {
let mut m_error = vec![0.; 256];
m_correct[0] = 1. - pm;
m_error[0] = pm;
let (m_correct, m_error) = load_channel_coeffs_from_file("channels/boson1.txt");
let measure_model = error::MeasureNoiseModel::new(m_correct, m_error);
loop {
println!("\n\n---------------------------------\n\n");
let result = runner2(xn, zm, 2, measure_model.clone());
let result = runner2(xn, zm, 2, measure_model.clone(), 0.01);
if result == 0 {
break;
}
......
......@@ -73,8 +73,8 @@ pub fn runner1(xn: usize, zm: usize, p: f64, measure_model: MeasureNoiseModel) -
epochs
}
pub fn runner2(xn: usize, zm: usize, measure_rounds: usize, measure_model: MeasureNoiseModel) -> usize {
let p1 = 0.01;
pub fn runner2(xn: usize, zm: usize, measure_rounds: usize, measure_model: MeasureNoiseModel, p1: f64) -> usize {
// let p1 = 0.01;
let probs = &measure_model.success.probs;
let p_ext = probs[1] * 4.;
log::debug!("p_ext: {}", p_ext);
......
use surfcode_rs::utils::load_channel_coeffs_from_file;
use surfcode_rs::*;
use clap::{App, Arg};
......@@ -5,8 +6,6 @@ use rayon::prelude::*;
use controller::*;
use utils::load_arr;
fn main() {
std::env::set_var("LD_LIBRARY_PATH", "bin/");
env_logger::init();
......@@ -29,7 +28,7 @@ fn main() {
.default_value("5"),
)
.arg(
Arg::new("p0")
Arg::new("p1")
.about("error probs of time evolution error")
.short('p'),
)
......@@ -62,9 +61,9 @@ fn main() {
.unwrap()
.parse::<usize>()
.unwrap();
let _p = match matches.value_of("p0") {
let p1 = match matches.value_of("p1") {
Some(p_str) => p_str.parse::<f64>().unwrap(),
None => 0.000,
None => 0.01,
};
let rounds = matches
.value_of("repeat")
......@@ -77,10 +76,7 @@ fn main() {
.parse::<usize>()
.unwrap();
let channel_str = std::fs::read_to_string(matches.value_of("channel").unwrap()).unwrap();
// let str_correct = std::fs::read_to_string("./custom_correct.txt").unwrap();
// let str_error = std::fs::read_to_string("./custom_error.txt").unwrap();
let (m_correct, m_error) = load_arr(&channel_str);
let (m_correct, m_error) = load_channel_coeffs_from_file(matches.value_of("channel").unwrap());
// let pm = 0.02;
// let mut m_correct = vec![0.; 256];
......@@ -91,7 +87,7 @@ fn main() {
let measure_model = error::MeasureNoiseModel::new(m_correct, m_error);
let result: Vec<usize> = (0..rounds)
.into_par_iter()
.map(|_| runner2(xn, zm, measure_rounds, measure_model.clone()))
.map(|_| runner2(xn, zm, measure_rounds, measure_model.clone(), p1))
// .map(|_| runner1(xn, zm, 0.006, measure_model.clone()))
.collect();
......
pub fn load_channel_coeffs_from_file(file_path: &str) -> (Vec<f64>, Vec<f64>) {
let file_str = std::fs::read_to_string(file_path).unwrap();
load_channel_coeffs_arr(&file_str)
}
pub fn load_channel_coeffs_arr(input: &str) -> (Vec<f64>, Vec<f64>) {
let result = load_arr(input);
assert_eq!(result.len(), 512);
let (correct, error) = result.split_at(256);
(correct.to_vec(), error.to_vec())
}
pub fn load_arr(input: &str) -> (Vec<f64>, Vec<f64>) {
pub fn load_arr(input: &str) -> Vec<f64> {
let mut result = Vec::<f64>::new();
let input = input.trim_matches(&['[', ']', ' '][..]);
for i in input.split(&[',', ' ', '\n', '\t'][..]) {
......@@ -12,8 +25,18 @@ pub fn load_arr(input: &str) -> (Vec<f64>, Vec<f64>) {
}
}
}
assert_eq!(result.len(), 512);
let (correct, error) = result.split_at(256);
(correct.to_vec(), error.to_vec())
result
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn can_load_numeric_array() {
let str = " [ 0.9175735 0.00168388 \n \t0.00078415 0. ] ";
let arr_expected = vec![0.9175735, 0.00168388, 0.00078415, 0.];
assert_eq!(load_arr(str), arr_expected);
}
}
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