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

Default setup via lazy_static. V0 corrections load fine.

parent daac01b7
......@@ -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"
lazy_static = "^1.4.0"
yaml-rust = "^0.4.5"
[features]
......
......@@ -7,6 +7,8 @@ use std::io::Write;
use colored::Colorize;
extern crate chrono;
#[macro_use]
extern crate lazy_static;
mod params;
mod keys;
......
......@@ -15,8 +15,8 @@ impl Params {
let mut all_params = Vec::new();
// loop input parameters
for &lambda_s_lambda in stp.lambda_s_lambdas {
for &pi_2_delta in stp.pi_pow_2deltas {
for &lambda_s_lambda in &stp.lambda_s_lambdas {
for &pi_2_delta in &stp.pi_pow_2deltas {
println!("{}", format!("\n(i) Generating {}-bit params for π = {}, 2^2∆ = {}.",
lambda_s_lambda.0, pi_2_delta.0, pi_2_delta.1,
......@@ -36,7 +36,7 @@ impl Params {
let Delta2 = (pow_2Delta as f64).log2();
// loop v0_corr
for &v0_corr in stp.v0_corr {
for &v0_corr in &stp.v0_corr {
let mut par_v0_corr_subgrp = Vec::new();
......
......@@ -6,17 +6,18 @@ extern crate yaml_rust;
use yaml_rust::YamlLoader; // YamlEmitter
#[derive(Clone,Debug)]
pub struct Setup<'a> {
pub struct Setup {
// experiment setup
pub v0_corr: &'a [f64],
pub lambda_s_lambdas: &'a [(usize, f64)],
pub pi_pow_2deltas: &'a [(usize, usize)],
pub v0_corr: Vec<f64>,
pub lambda_s_lambdas: Vec<(usize, f64)>,
pub pi_pow_2deltas: Vec<(usize, usize)>,
// experiment parameters
pub n_repeat: usize,
pub n_top_bs_times: usize,
pub n_top_v_maxes: usize,
pub n_repeat: usize,
pub n_top_bs_times: usize,
pub n_top_v_maxes: usize,
// ranges
//TODO
}
......@@ -24,78 +25,82 @@ pub struct Setup<'a> {
//
// Default Setup
//
pub const SETUP_DEF: Setup = Setup {
// -------------------------------------------------------------------------
// Experiment Setup
//
/// V_0 correction (numerical mode only)
/// When this is set 1.0, it has no effect
/// [1.0, 1.1, 1.2, 1.3, 1.5, 1.75, 2.0, 2.3, 2.7, 3.2, 3.8, 4.5];
/// [0.826, 0.909, 1.0, 1.1, 1.210, 1.331, 1.464, 1.611, 1.772, 1.949]; //
/// [0.621, 0.683, 0.751, 0.826]; // used for 126|5|2
/// [1.0, 1.2, 1.44, 1.73, 2.07, 2.49];
/// [1.0];
v0_corr: &[1.0],
/// Security Parameter(s) (numerical mode only)
///
/// - ( 90, 0.0335) (new; was 0.0328)
/// - (112, 0.0275) (new; was 0.0271)
/// - ( 80, 0.0380)
/// - (128, 0.0235)
///
/// [(128, 0.0235)];
/// [(112, 0.0274)];
/// [( 80, 0.0380)];
/// [( 80, 0.0380), (127, 0.0238), (128, 0.0235)];
/// alternative s_lambda's
/// [(125, 0.0241)];
/// [(129, 0.0231)];
/// [(126, 0.0239)];
lambda_s_lambdas: &[( 80, 0.0380)],
/// Plaintext Precision(s), Quadratic Weight(s) (numerical mode only)
/// [(2, 2)];
/// [(2, 3)];
/// [(5, 2)]; // Demo Z/8Z by Zama
/// [(6, 2)]; // Demo Z/16Z by Zama
/// [(5, 20)];
/// [(2, 3), (5, 20)];
/// [(2, 2), (5, 20)];
/// [(2, 2), (5, 20), (5, 2), (6, 2)];
/// [(5, 20), (6, 2)];
/// [(2, 2)];
/// [(5, 2)];
pi_pow_2deltas: &[(5, 2)],
// -------------------------------------------------------------------------
// Experiment Parameters
//
/// Number of Benchmark Repetitions
n_repeat: 500,
/// Number of top BS times to be considered in single V_0 corrections search (numerical mode only)
n_top_bs_times: 2,
/// Number of top V_max'es to be considered per BS time (numerical mode only)
n_top_v_maxes: 3,
};
lazy_static! {
pub static ref SETUP_DEF: Setup = Setup {
// -------------------------------------------------------------------------
// Experiment Setup
//
/// V_0 correction (numerical mode only)
/// When this is set 1.0, it has no effect
/// [1.0, 1.1, 1.2, 1.3, 1.5, 1.75, 2.0, 2.3, 2.7, 3.2, 3.8, 4.5];
/// [0.826, 0.909, 1.0, 1.1, 1.210, 1.331, 1.464, 1.611, 1.772, 1.949]; //
/// [0.621, 0.683, 0.751, 0.826]; // used for 126|5|2
/// [1.0, 1.2, 1.44, 1.73, 2.07, 2.49];
/// [1.0];
v0_corr: vec![1.0],
/// Security Parameter(s) (numerical mode only)
///
/// - ( 90, 0.0335) (new; was 0.0328)
/// - (112, 0.0275) (new; was 0.0271)
/// - ( 80, 0.0380)
/// - (128, 0.0235)
///
/// [(128, 0.0235)];
/// [(112, 0.0274)];
/// [( 80, 0.0380)];
/// [( 80, 0.0380), (127, 0.0238), (128, 0.0235)];
/// alternative s_lambda's
/// [(125, 0.0241)];
/// [(129, 0.0231)];
/// [(126, 0.0239)];
lambda_s_lambdas: vec![( 80, 0.0380)],
/// Plaintext Precision(s), Quadratic Weight(s) (numerical mode only)
/// [(2, 2)];
/// [(2, 3)];
/// [(5, 2)]; // Demo Z/8Z by Zama
/// [(6, 2)]; // Demo Z/16Z by Zama
/// [(5, 20)];
/// [(2, 3), (5, 20)];
/// [(2, 2), (5, 20)];
/// [(2, 2), (5, 20), (5, 2), (6, 2)];
/// [(5, 20), (6, 2)];
/// [(2, 2)];
/// [(5, 2)];
pi_pow_2deltas: vec![(5, 2)],
// -------------------------------------------------------------------------
// Experiment Parameters
//
/// Number of Benchmark Repetitions
n_repeat: 500,
/// Number of top BS times to be considered in single V_0 corrections search (numerical mode only)
n_top_bs_times: 2,
/// Number of top V_max'es to be considered per BS time (numerical mode only)
n_top_v_maxes: 3,
};
}
// =============================================================================
//
// Load Setup from YAML file
//
impl Setup<'_> {
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_DEF.clone();
// check if setup file exists
if Path::new(setup_filename).is_file() {
println!("(i) Loading setup from '{}' ...", setup_filename);
// load YAML struct
let yaml_str = fs::read_to_string(setup_filename)?;
let docs = YamlLoader::load_from_str(&yaml_str)?;
let setup_map = &docs[0];
......@@ -104,6 +109,11 @@ impl Setup<'_> {
println!("(?) setup_map:\n{:?}\n\n", setup_map);
println!("(?) setup_struct:\n{:?}\n\n", stp);
// update setup fields, if they exist in YAML
//WISH it was like this:
// stp.n_repeat = setup_map["n_repeat"].as_i64().unwrap() as usize;
// but it panics if the output is None
if let Some(n_repeat) = setup_map["n_repeat"].as_i64() {
stp.n_repeat = n_repeat as usize;
}
......@@ -113,6 +123,15 @@ impl Setup<'_> {
if let Some(n_top_v_maxes) = setup_map["n_top_v_maxes"].as_i64() {
stp.n_top_v_maxes = n_top_v_maxes as usize;
}
if let Some(v0_corr_yaml) = setup_map["v0_corr"].as_vec() {
let mut v0_corr = vec![];
for v0c_y in v0_corr_yaml {
if let Some(v0c) = v0c_y.as_f64() {
v0_corr.push(v0c);
}
}
stp.v0_corr = v0_corr;
}
//DBG
println!("(?) setup_struct:\n{:?}\n\n", stp);
......
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