mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-08 19:44:57 -05:00
fix: Return the crt_decomposition from the optimizer
This commit is contained in:
committed by
rudy-6-4
parent
af8296e6d2
commit
efc3a85c66
@@ -131,7 +131,7 @@ impl From<DagSolution> for ffi::DagSolution {
|
||||
use_wop_pbs: true,
|
||||
cb_decomposition_level_count: sol.cb_decomposition_level_count,
|
||||
cb_decomposition_base_log: sol.cb_decomposition_base_log,
|
||||
crt_decomposition: vec![],
|
||||
crt_decomposition: sol.crt_decomposition,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,13 +66,12 @@ pub fn optimize<W: UnsignedInteger>(
|
||||
} else if max_precision > MAXIMAL_WOP_PRECISION {
|
||||
None
|
||||
} else {
|
||||
let fallback_16b_precision = 16;
|
||||
let default_log_norm = default_log_norm2_woppbs;
|
||||
let worst_log_norm = analyze::worst_log_norm(dag);
|
||||
let nb_luts = analyze::lut_count_from_dag(dag);
|
||||
let log_norm = default_log_norm.min(worst_log_norm);
|
||||
let opt_sol = wop_optimize::<W>(
|
||||
fallback_16b_precision,
|
||||
max_precision as u64,
|
||||
security_level,
|
||||
log_norm,
|
||||
maximum_acceptable_error_probability,
|
||||
|
||||
@@ -44,7 +44,7 @@ pub struct OptimizationState {
|
||||
pub count_domain: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Solution {
|
||||
pub input_lwe_dimension: u64,
|
||||
//n_big
|
||||
@@ -69,6 +69,7 @@ pub struct Solution {
|
||||
// error probability
|
||||
pub cb_decomposition_level_count: u64,
|
||||
pub cb_decomposition_base_log: u64,
|
||||
pub crt_decomposition: Vec<u64>,
|
||||
}
|
||||
|
||||
impl Solution {
|
||||
@@ -88,6 +89,7 @@ impl Solution {
|
||||
global_p_error: 0.0,
|
||||
cb_decomposition_level_count: 0,
|
||||
cb_decomposition_base_log: 0,
|
||||
crt_decomposition: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -241,8 +243,14 @@ fn update_state_with_best_decompositions<W: UnsignedInteger>(
|
||||
return;
|
||||
}
|
||||
|
||||
let mut best_complexity = state.best_solution.map_or(f64::INFINITY, |s| s.complexity);
|
||||
let mut best_variance = state.best_solution.map_or(f64::INFINITY, |s| s.noise_max);
|
||||
let mut best_complexity = state
|
||||
.best_solution
|
||||
.as_ref()
|
||||
.map_or(f64::INFINITY, |s| s.complexity);
|
||||
let mut best_variance = state
|
||||
.best_solution
|
||||
.as_ref()
|
||||
.map_or(f64::INFINITY, |s| s.noise_max);
|
||||
|
||||
let variance_cost_opt = compute_noise_cost_by_micro_param::<W>(
|
||||
consts,
|
||||
@@ -437,6 +445,7 @@ fn update_state_with_best_decompositions<W: UnsignedInteger>(
|
||||
global_p_error: f64::NAN,
|
||||
cb_decomposition_level_count: circuit_pbs_decomposition_parameter.level,
|
||||
cb_decomposition_base_log: circuit_pbs_decomposition_parameter.log2_base,
|
||||
crt_decomposition: vec![],
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -535,7 +544,7 @@ pub fn optimize_one<W: UnsignedInteger>(
|
||||
let nb_words = partitionning.len() as u64;
|
||||
let max_word_precision = *partitionning.iter().max().unwrap() as u64;
|
||||
let n_functions = 1;
|
||||
optimize_raw::<W>(
|
||||
let mut state = optimize_raw::<W>(
|
||||
max_word_precision,
|
||||
log_norm,
|
||||
security_level,
|
||||
@@ -545,7 +554,12 @@ pub fn optimize_one<W: UnsignedInteger>(
|
||||
internal_lwe_dimensions,
|
||||
n_functions,
|
||||
nb_words, // Tau
|
||||
)
|
||||
);
|
||||
state.best_solution = state.best_solution.map(|mut sol| -> Solution {
|
||||
sol.crt_decomposition = coprimes;
|
||||
sol
|
||||
});
|
||||
state
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
|
||||
Reference in New Issue
Block a user