Commit 2f138b89 authored by Jakub Klemsa's avatar Jakub Klemsa
Browse files

All setup moved. Constants -> Manual Params.

parent c5ac6dcf
---
# 1) copy into <my-setup-filename>.yaml
# 2) edit/delete values
# - deleted values will be replaced by default ones
# - defined in SETUP_DEF in src/setup.rs
#
#
# Experiment Setup
#
lambda_s_lambdas:
- - 80
- 0.0380
- - 128
- 0.0235
pi_pow_2deltas:
- - 5
- 2
- - 6
- 2
v0_corr:
- 1.0
- 1.2
- 1.44
- 1.73
- 2.07
- 2.49
#
#
# Experiment Parameters
#
n_repeat: 500
n_top_bs_times: 2
n_top_v_maxes: 3
#
#
# Param Ranges
#
nu_min: 8
nu_max: 11
t_max: 10
l_max: 6
......@@ -9,17 +9,19 @@ use colored::Colorize;
extern crate chrono;
#[macro_use]
extern crate lazy_static;
extern crate yaml_rust;
mod params;
mod keys;
mod constants_param_ranges;
#[cfg(feature = "manual")]
mod manual_params;
mod setup;
mod misc;
#[cfg(feature = "numerical")]
use params::*;
#[cfg(feature = "manual")]
use constants_param_ranges::*;
use manual_params::*;
use setup::*;
// resolve mutually exclusive features
......
#[cfg(feature = "manual")]
use concrete::*;
#[cfg(feature = "manual")]
use crate::params::*;
// Ranges
#[cfg(feature = "numerical")]
pub const NU_MIN: usize = 8; // N_min = 256
#[cfg(feature = "numerical")]
//~ pub const NU_MAX: usize = 13; // N_max = 8192
pub const NU_MAX: usize = 11;
#[cfg(feature = "numerical")]
pub const T_MAX: usize = 10;
#[cfg(feature = "numerical")]
pub const L_MAX: usize = 6;
#[cfg(feature = "numerical")]
pub const THREE: f64 = 3.0; // to call log2() on
/// Noise Growth in BlindRotate
#[cfg(not(feature = "brot_im"))]
pub const BROT_NOISE_FACTOR: usize = 1;
#[cfg(feature = "brot_im")]
pub const BROT_NOISE_FACTOR: usize = 3;
// Imported Constants
/// Torus Precision in Concrete
//~ #[cfg(feature = "numerical")]
//~ pub const TORUS_PREC: f64 = 64.0; // https://github.com/zama-ai/concrete/blob/concrete-0.1.11/concrete/src/lib.rs#L21
// =============================================================================
//
// Manual Params
//
#[cfg(feature = "manual")]
pub const MAN_PARAMS: [[Params; 3]; 4] = [
// -----------------------------------------------------------------------------
......
use std::iter::Sum;
// conversion constants
// =============================================================================
//
// Constants
//
#[allow(dead_code)]
pub const S_TO_MS: usize = 1000;
#[allow(dead_code)]
......@@ -8,6 +12,24 @@ pub const MS_TO_US: usize = S_TO_MS;
#[allow(dead_code)]
pub const S_TO_US: usize = S_TO_MS * MS_TO_US;
/// Noise growth factor in Blind Rotate. Differs for improved variant (3x higher noise).
#[cfg(not(feature = "brot_im"))]
pub const BROT_NOISE_FACTOR: usize = 1;
#[cfg(feature = "brot_im")]
pub const BROT_NOISE_FACTOR: usize = 3;
#[cfg(feature = "numerical")]
pub const THREE: f64 = 3.0; // to call log2() on
//~ /// Torus Precision in Concrete
//~ #[cfg(feature = "numerical")]
//~ pub const TORUS_PREC: f64 = 64.0; // https://github.com/zama-ai/concrete/blob/concrete-0.1.11/concrete/src/lib.rs#L21
// =============================================================================
//
// Statistical Calculations
//
/// Mean
#[allow(dead_code)]
pub fn mean<'a, T: 'a + Into<f64>>(v: &'a Vec<T>) -> f64 where f64: Sum<&'a T> {
......@@ -57,6 +79,12 @@ pub fn max_abs(v: &Vec<f64>) -> f64 {
v.iter().map(|e| e.abs() ).fold(f64::NEG_INFINITY, |a, b| a.max(b))
}
// =============================================================================
//
// Macros
//
// Credit: Demo Z/8Z by Zama (https://github.com/zama-ai/demo_z8z ; improved)
// This macro allows to compute the duration of the execution of the expressions enclosed.
// Note that the variables are not captured.
......
......@@ -5,7 +5,6 @@ use concrete::*;
use crate::params::*;
use crate::keys::*;
use crate::misc::*;
use crate::*;
impl Params {
......
......@@ -3,7 +3,7 @@ use colored::Colorize;
use crate::params::*;
#[cfg(feature = "manual")]
use crate::constants_param_ranges::*;
use crate::manual_params::*;
use crate::setup::*;
impl Params {
......@@ -45,7 +45,7 @@ impl Params {
//
// loop N
for nu in NU_MIN..=NU_MAX {
for nu in stp.nu_min..=stp.nu_max {
// calc N
#[allow(non_snake_case)]
......@@ -79,7 +79,7 @@ impl Params {
// check if round and (♣) leave some error budget with actual t
// n.b.! (♠) must not be considered, otherwise t might not start to grow
while Params::club_round_max_err_budget(pi, pow_2Delta, nu, kappa, t, s_lambda, n_min, n_max, v0_corr) > 0.0 && t <= T_MAX {
while Params::club_round_max_err_budget(pi, pow_2Delta, nu, kappa, t, s_lambda, n_min, n_max, v0_corr) > 0.0 && t <= stp.t_max {
// loop n s.t. log(alpha_KS) is an integer (n.b., this is just a limitation of Concrete v0.1.11, it can be smoother)
#[allow(non_snake_case)]
......@@ -117,7 +117,7 @@ impl Params {
// check if round, (♠), (♣) and (♥) leave some error budget with actual l
// n.b.! (♦) must not be considered, otherwise l might not start to grow
while Params::heart_spade_club_round_max_err_budget(pi, pow_2Delta, nu, kappa, t, s_lambda, n, gamma, l, v0_corr) > 0.0 && l <= L_MAX {
while Params::heart_spade_club_round_max_err_budget(pi, pow_2Delta, nu, kappa, t, s_lambda, n, gamma, l, v0_corr) > 0.0 && l <= stp.l_max {
#[cfg(feature = "verb")]
println!("{}", format!(" l = {}", l).purple());
......@@ -173,7 +173,7 @@ impl Params {
}
#[cfg(feature = "verb")]
println!("{}", format!("---- No other t feasible due to (♣) or t exceeded T_MAX = {}", T_MAX).blue());
println!("{}", format!("---- No other t feasible due to (♣) or t exceeded T_MAX = {}", stp.t_max).blue());
// increase kappa
kappa += 1;
......
use std::fmt;
use colored::Colorize;
use concrete::*;
use crate::constants_param_ranges::*;
use crate::misc::*;
#[cfg(feature = "numerical")]
mod gen;
//~ #[cfg(feature = "numerical")]
mod num;
mod bench;
......
......@@ -2,22 +2,25 @@ use std::error::Error;
use std::path::Path;
use std::fs;
extern crate yaml_rust;
use yaml_rust::YamlLoader; // YamlEmitter
#[derive(Clone,Debug)]
pub struct Setup {
// experiment setup
pub v0_corr: Vec<f64>,
pub lambda_s_lambdas: Vec<(usize, f64)>,
pub pi_pow_2deltas: Vec<(usize, usize)>,
pub v0_corr: Vec<f64>,
// experiment parameters
pub n_repeat: usize,
pub n_top_bs_times: usize,
pub n_top_v_maxes: usize,
// ranges
//TODO
// param ranges
pub nu_min: usize,
pub nu_max: usize,
pub t_max: usize,
pub l_max: usize,
}
......@@ -31,15 +34,6 @@ lazy_static! {
// -------------------------------------------------------------------------
// 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)
......@@ -58,19 +52,23 @@ lazy_static! {
lambda_s_lambdas: vec![( 80, 0.0380)],
/// Plaintext Precision(s), Quadratic Weight(s) (numerical mode only)
/// [(2, 2)];
/// [(2, 3)];
/// [(2, 2)]; // TFHE Lib addition
/// [(2, 3)]; // Binary addition with ternary gates
/// [(5, 2)]; // Demo Z/8Z by Zama
/// [(6, 2)]; // Demo Z/16Z by Zama
/// [(5, 20)];
/// [(2, 3), (5, 20)];
/// [(2, 2), (5, 20)];
/// [(5, 20)]; // Parmesan
/// [(2, 2), (5, 20), (5, 2), (6, 2)];
/// [(5, 20), (6, 2)];
/// [(2, 2)];
/// [(5, 2)];
pi_pow_2deltas: vec![(5, 2)],
/// 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],
// -------------------------------------------------------------------------
// Experiment Parameters
......@@ -81,6 +79,15 @@ lazy_static! {
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,
// -------------------------------------------------------------------------
// Param Ranges (numerical mode only)
//
nu_min: 8,
nu_max: 11,
t_max: 10,
l_max: 6,
};
}
......@@ -107,28 +114,9 @@ impl Setup {
// update setup fields, if they exist in YAML
// 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;
}
if let Some(n_top_bs_times) = setup_map["n_top_bs_times"].as_i64() {
stp.n_top_bs_times = n_top_bs_times as usize;
}
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(v0c_vec_yaml) = setup_map["v0_corr"].as_vec() {
let mut v0_corr = vec![];
for v0c_yaml in v0c_vec_yaml {
if let Some(v0c) = v0c_yaml.as_f64() {
v0_corr.push(v0c);
}
}
stp.v0_corr = v0_corr;
}
// -------------------------------------------------------------------------
// Experiment Setup
//
if let Some(lsl_vec_yaml) = setup_map["lambda_s_lambdas"].as_vec() {
let mut lambda_s_lambdas = vec![];
for lsl_ary_yaml in lsl_vec_yaml {
......@@ -165,6 +153,47 @@ impl Setup {
}
stp.pi_pow_2deltas = pi_pow_2deltas;
}
if let Some(v0c_vec_yaml) = setup_map["v0_corr"].as_vec() {
let mut v0_corr = vec![];
for v0c_yaml in v0c_vec_yaml {
if let Some(v0c) = v0c_yaml.as_f64() {
v0_corr.push(v0c);
}
}
stp.v0_corr = v0_corr;
}
// -------------------------------------------------------------------------
// Experiment Parameters
//
// 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;
}
if let Some(n_top_bs_times) = setup_map["n_top_bs_times"].as_i64() {
stp.n_top_bs_times = n_top_bs_times as usize;
}
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;
}
// -------------------------------------------------------------------------
// Param Ranges (numerical mode only)
//
if let Some(nu_min) = setup_map["nu_min"].as_i64() {
stp.nu_min = nu_min as usize;
}
if let Some(nu_max) = setup_map["nu_max"].as_i64() {
stp.nu_max = nu_max as usize;
}
if let Some(t_max) = setup_map["t_max"].as_i64() {
stp.t_max = t_max as usize;
}
if let Some(l_max) = setup_map["l_max"].as_i64() {
stp.l_max = l_max as usize;
}
println!(" {:?}", 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