Commit a75c1c82 authored by Jakub Klemsa's avatar Jakub Klemsa
Browse files

First steps: Setup module.

parent b736a1c7
......@@ -3,3 +3,4 @@
Cargo.lock
*.key
*.log
*.yaml
......@@ -13,6 +13,7 @@ concrete = { git = "https://github.com/fakub/concrete", branch = "easy_noise", f
colored = "2.0.0"
chrono = "^0.4.0"
itertools = "^0.10.3"
yaml-rust = "^0.4.5"
[features]
default = ["manual"] # 'manual' feature selected by default
......
......@@ -11,6 +11,7 @@ extern crate chrono;
mod params;
mod keys;
mod constants_param_ranges;
mod setup;
mod misc;
#[cfg(feature = "numerical")]
......@@ -18,6 +19,8 @@ use params::*;
#[cfg(feature = "manual")]
use constants_param_ranges::*;
use setup::*;
// resolve mutually exclusive features
#[cfg(all(feature = "manual", feature = "numerical"))]
compile_error!("Features 'manual' and 'numerical' cannot be enabled at the same time.");
......@@ -35,6 +38,11 @@ const NOISES_FILE_EXT: &str = "dat";
fn main() -> Result<(), Box<dyn Error>> {
// load setup
let stp = Setup::new("setup.yaml")?;
//DBG
println!("(?) ==== SETUP LOAD END ====\n");
// generate all params
#[cfg(feature = "numerical")]
let all_pars = Params::gen_all();
......
use std::error::Error;
use std::path::Path;
use std::fs;
use crate::constants_param_ranges::*;
extern crate yaml_rust;
use yaml_rust::YamlLoader; // YamlEmitter
#[derive(Clone,Debug)]
pub struct Setup {
// experiment setup
pub n_repeat: usize,
//~ pub n_top_bs_times: usize,
//~ pub n_top_v_maxes: usize,
// ranges
}
impl Setup {
/// Load experiment setup (or use default values)
pub fn new(setup_filename: &str) -> Result<Setup, Box<dyn Error>> {
// create Setup struct with default values
let mut stp = SETUP_DEFAULT.clone();
if Path::new(setup_filename).is_file() {
println!("(i) Loading setup from '{}' ...", setup_filename);
let yaml_str = fs::read_to_string(setup_filename)?;
let docs = YamlLoader::load_from_str(&yaml_str)?;
let setup_map = &docs[0];
//DBG
println!("(?) setup_map:\n{:?}\n\n", setup_map);
println!("(?) setup_struct:\n{:?}\n\n", stp);
if let Some(n_repeat) = setup_map["n_repeat"].as_i64() {
stp.n_repeat = n_repeat as usize;
} else {
//DBG
}
//DBG
println!("(?) setup_struct:\n{:?}\n\n", stp);
} else {
eprintln!("(!) Setup file '{}' does not exist.", setup_filename);
}
Ok(stp)
}
}
pub const SETUP_DEFAULT: Setup = Setup {
n_repeat: N_REPEAT,
};
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