mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-17 16:11:26 -05:00
feat(optimizer): levelled circuit, no power of two constraint
This commit is contained in:
@@ -31,6 +31,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
glwe_log_polynomial_sizes,
|
||||
glwe_dimensions,
|
||||
internal_lwe_dimensions,
|
||||
levelled_only_lwe_dimensions: DEFAUT_DOMAINS.free_lwe,
|
||||
};
|
||||
|
||||
let precision = 8;
|
||||
|
||||
@@ -37,6 +37,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
glwe_log_polynomial_sizes,
|
||||
glwe_dimensions,
|
||||
internal_lwe_dimensions,
|
||||
levelled_only_lwe_dimensions: DEFAUT_DOMAINS.free_lwe,
|
||||
};
|
||||
|
||||
let config = Config {
|
||||
|
||||
@@ -57,7 +57,8 @@ void test_dag_no_lut() {
|
||||
dag->add_dot(slice(inputs), std::move(weights));
|
||||
|
||||
auto solution = dag->optimize_v0(default_options());
|
||||
assert(solution.glwe_polynomial_size == 256);
|
||||
assert(solution.glwe_polynomial_size == 1);
|
||||
assert(solution.glwe_dimension == 555);
|
||||
}
|
||||
|
||||
void test_dag_lut() {
|
||||
|
||||
@@ -17,6 +17,7 @@ pub struct ParameterDomains {
|
||||
pub free_glwe: GlweParameterRanges,
|
||||
pub br_decomposition: BrDecompositionParameterRanges,
|
||||
pub ks_decomposition: KsDecompositionParameterRanges,
|
||||
pub free_lwe: Range,
|
||||
}
|
||||
|
||||
pub const DEFAUT_DOMAINS: ParameterDomains = ParameterDomains {
|
||||
@@ -39,6 +40,10 @@ pub const DEFAUT_DOMAINS: ParameterDomains = ParameterDomains {
|
||||
log2_base: Range { start: 1, end: 65 },
|
||||
level: Range { start: 1, end: 65 },
|
||||
},
|
||||
free_lwe: Range {
|
||||
start: 512,
|
||||
end: 1 << 20,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::computing_cost::complexity_model::ComplexityModel;
|
||||
use crate::config;
|
||||
use crate::config::GpuPbsType;
|
||||
use crate::global_parameters::DEFAUT_DOMAINS;
|
||||
use crate::global_parameters::{Range, DEFAUT_DOMAINS};
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct NoiseBoundConfig {
|
||||
@@ -24,6 +24,7 @@ pub struct SearchSpace {
|
||||
pub glwe_log_polynomial_sizes: Vec<u64>,
|
||||
pub glwe_dimensions: Vec<u64>,
|
||||
pub internal_lwe_dimensions: Vec<u64>,
|
||||
pub levelled_only_lwe_dimensions: Range,
|
||||
}
|
||||
|
||||
impl SearchSpace {
|
||||
@@ -34,11 +35,12 @@ impl SearchSpace {
|
||||
.as_vec();
|
||||
let glwe_dimensions: Vec<u64> = DEFAUT_DOMAINS.glwe_pbs_constrained.glwe_dimension.as_vec();
|
||||
let internal_lwe_dimensions: Vec<u64> = DEFAUT_DOMAINS.free_glwe.glwe_dimension.as_vec();
|
||||
|
||||
let levelled_only_lwe_dimensions = DEFAUT_DOMAINS.free_lwe;
|
||||
Self {
|
||||
glwe_log_polynomial_sizes,
|
||||
glwe_dimensions,
|
||||
internal_lwe_dimensions,
|
||||
levelled_only_lwe_dimensions,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,11 +51,12 @@ impl SearchSpace {
|
||||
let glwe_dimensions: Vec<u64> = DEFAUT_DOMAINS.glwe_pbs_constrained.glwe_dimension.as_vec();
|
||||
|
||||
let internal_lwe_dimensions: Vec<u64> = DEFAUT_DOMAINS.free_glwe.glwe_dimension.as_vec();
|
||||
|
||||
let levelled_only_lwe_dimensions = DEFAUT_DOMAINS.free_lwe;
|
||||
Self {
|
||||
glwe_log_polynomial_sizes,
|
||||
glwe_dimensions,
|
||||
internal_lwe_dimensions,
|
||||
levelled_only_lwe_dimensions,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,11 +67,12 @@ impl SearchSpace {
|
||||
let glwe_dimensions: Vec<u64> = DEFAUT_DOMAINS.glwe_pbs_constrained.glwe_dimension.as_vec();
|
||||
|
||||
let internal_lwe_dimensions: Vec<u64> = DEFAUT_DOMAINS.free_glwe.glwe_dimension.as_vec();
|
||||
|
||||
let levelled_only_lwe_dimensions = DEFAUT_DOMAINS.free_lwe;
|
||||
Self {
|
||||
glwe_log_polynomial_sizes,
|
||||
glwe_dimensions,
|
||||
internal_lwe_dimensions,
|
||||
levelled_only_lwe_dimensions,
|
||||
}
|
||||
}
|
||||
pub fn default(processing_unit: config::ProcessingUnit) -> Self {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use concrete_cpu_noise_model::gaussian_noise::noise::modulus_switching::estimate_modulus_switching_noise_with_binary_key;
|
||||
use concrete_security_curves::gaussian::security::minimal_variance_lwe;
|
||||
|
||||
use super::analyze;
|
||||
use crate::dag::operator::{LevelledComplexity, Precision};
|
||||
@@ -137,14 +138,12 @@ fn update_no_luts_solution(
|
||||
state: &mut OptimizationState,
|
||||
consts: &OptimizationDecompositionsConsts,
|
||||
dag: &analyze::OperationDag,
|
||||
glwe_params: GlweParameters,
|
||||
input_lwe_dimension: u64,
|
||||
input_noise_out: f64,
|
||||
) {
|
||||
const CHECKED_IGNORED_NOISE: f64 = f64::MAX;
|
||||
const UNDEFINED_PARAM: u64 = 0;
|
||||
|
||||
let input_lwe_dimension = glwe_params.sample_extract_lwe_dimension();
|
||||
|
||||
let best_complexity = state.best_solution.map_or(f64::INFINITY, |s| s.complexity);
|
||||
let best_p_error = state.best_solution.map_or(f64::INFINITY, |s| s.p_error);
|
||||
|
||||
@@ -180,8 +179,8 @@ fn update_no_luts_solution(
|
||||
internal_ks_output_lwe_dimension: UNDEFINED_PARAM,
|
||||
ks_decomposition_level_count: UNDEFINED_PARAM,
|
||||
ks_decomposition_base_log: UNDEFINED_PARAM,
|
||||
glwe_polynomial_size: glwe_params.polynomial_size(),
|
||||
glwe_dimension: glwe_params.glwe_dimension,
|
||||
glwe_polynomial_size: 1,
|
||||
glwe_dimension: input_lwe_dimension,
|
||||
br_decomposition_level_count: UNDEFINED_PARAM,
|
||||
br_decomposition_base_log: UNDEFINED_PARAM,
|
||||
complexity,
|
||||
@@ -208,18 +207,15 @@ fn optimize_no_luts(
|
||||
search_space: &SearchSpace,
|
||||
) -> OptimizationState {
|
||||
let not_feasible = |input_noise_out| !dag.feasible(input_noise_out, 0.0, 0.0, 0.0);
|
||||
for &glwe_dim in &search_space.glwe_dimensions {
|
||||
for &glwe_log_poly_size in &search_space.glwe_log_polynomial_sizes {
|
||||
let glwe_params = GlweParameters {
|
||||
log2_polynomial_size: glwe_log_poly_size,
|
||||
glwe_dimension: glwe_dim,
|
||||
};
|
||||
let input_noise_out = minimal_variance(&consts.config, glwe_params);
|
||||
if not_feasible(input_noise_out) {
|
||||
continue;
|
||||
}
|
||||
update_no_luts_solution(&mut state, consts, dag, glwe_params, input_noise_out);
|
||||
let modulus_log = consts.config.ciphertext_modulus_log;
|
||||
let security_level = consts.config.security_level;
|
||||
for lwe in &search_space.levelled_only_lwe_dimensions {
|
||||
let input_noise_out = minimal_variance_lwe(lwe, modulus_log, security_level);
|
||||
if not_feasible(input_noise_out) {
|
||||
continue;
|
||||
}
|
||||
update_no_luts_solution(&mut state, consts, dag, lwe, input_noise_out);
|
||||
break;
|
||||
}
|
||||
state
|
||||
}
|
||||
|
||||
@@ -105,6 +105,7 @@ pub fn all_results(args: &Args) -> Vec<Vec<Option<Solution>>> {
|
||||
glwe_log_polynomial_sizes: (args.min_log_poly_size..=args.max_log_poly_size).collect(),
|
||||
glwe_dimensions: (args.min_glwe_dim..=args.max_glwe_dim).collect(),
|
||||
internal_lwe_dimensions: (args.min_intern_lwe_dim..=args.max_intern_lwe_dim).collect(),
|
||||
levelled_only_lwe_dimensions: DEFAUT_DOMAINS.free_lwe,
|
||||
};
|
||||
|
||||
let precisions = args.min_precision..=args.max_precision;
|
||||
|
||||
Reference in New Issue
Block a user