From bb756a64262468c2e535f7dd70727c6d064e7b39 Mon Sep 17 00:00:00 2001 From: rudy Date: Fri, 18 Nov 2022 15:13:49 +0100 Subject: [PATCH] fix: default is global-error-probability=1/100_000 --- .../include/concretelang/Support/V0Parameters.h | 2 +- .../concrete/compiler/compilation_options.py | 16 ++++++++-------- compiler/lib/Support/V0Parameters.cpp | 13 ++++++++++--- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/compiler/include/concretelang/Support/V0Parameters.h b/compiler/include/concretelang/Support/V0Parameters.h index 5df0b78a9..3d9776849 100644 --- a/compiler/include/concretelang/Support/V0Parameters.h +++ b/compiler/include/concretelang/Support/V0Parameters.h @@ -16,7 +16,7 @@ namespace mlir { namespace concretelang { namespace optimizer { -constexpr double P_ERROR_4_SIGMA = 1.0 - 0.999936657516; +constexpr double DEFAULT_P_ERROR = 1.0 / 100000.0; constexpr double UNSPECIFIED_P_ERROR = NAN; // will use the default p error constexpr double NO_GLOBAL_P_ERROR = NAN; // will fallback on p error constexpr uint DEFAULT_SECURITY = 128; diff --git a/compiler/lib/Bindings/Python/concrete/compiler/compilation_options.py b/compiler/lib/Bindings/Python/concrete/compiler/compilation_options.py index a07d628a8..0eab40dc6 100644 --- a/compiler/lib/Bindings/Python/concrete/compiler/compilation_options.py +++ b/compiler/lib/Bindings/Python/concrete/compiler/compilation_options.py @@ -142,14 +142,14 @@ class CompilationOptions(WrapperCpp): Raises: TypeError: if the value to set is not float - ValueError: if the value to set is not in interval ]0; 1[ + ValueError: if the value to set is not in interval ]0; 1] """ if not isinstance(p_error, float): raise TypeError("can't set p_error to a non-float value") - if p_error in (0.0, 1.0): - raise ValueError("p_error cannot be 0 or 1") + if p_error == 0.0: + raise ValueError("p_error cannot be 0") if not 0.0 <= p_error <= 1.0: - raise ValueError("p_error should be a probability in ]0; 1[") + raise ValueError("p_error should be a probability in ]0; 1]") self.cpp().set_p_error(p_error) def set_display_optimizer_choice(self, display: bool): @@ -186,12 +186,12 @@ class CompilationOptions(WrapperCpp): Raises: TypeError: if the value to set is not float - ValueError: if the value to set is not in interval ]0; 1[ + ValueError: if the value to set is not in interval ]0; 1] """ if not isinstance(global_p_error, float): raise TypeError("can't set global_p_error to a non-float value") - if global_p_error in (0.0, 1.0): - raise ValueError("global_p_error cannot be 0 or 1") + if global_p_error == 0.0: + raise ValueError("global_p_error cannot be 0") if not 0.0 <= global_p_error <= 1.0: - raise ValueError("global_p_error be a probability in ]0; 1[") + raise ValueError("global_p_error be a probability in ]0; 1]") self.cpp().set_global_p_error(global_p_error) diff --git a/compiler/lib/Support/V0Parameters.cpp b/compiler/lib/Support/V0Parameters.cpp index 1ca371e12..527f4674a 100644 --- a/compiler/lib/Support/V0Parameters.cpp +++ b/compiler/lib/Support/V0Parameters.cpp @@ -172,12 +172,19 @@ llvm::Expected getParameter(optimizer::Description &descr, optimizer::Config config) { namespace chrono = std::chrono; auto start = chrono::high_resolution_clock::now(); - auto naive_user = std::isnan(config.p_error) && std::isnan(config.global_p_error); - if (std::isnan(config.p_error)) { - config.p_error = optimizer::P_ERROR_4_SIGMA; + + if (naive_user) { + config.global_p_error = optimizer::DEFAULT_P_ERROR; } + if (std::isnan(config.p_error)) { + // We always need a valid p-error + // getV0Parameter relies only on p_error + // getV1Parameter relies on p-error and if set global-p-error + config.p_error = config.global_p_error; + } + auto sol = (!descr.dag || config.strategy_v0) ? getV0Parameter(descr.constraint, config) : getV1Parameter(descr.dag.getValue(), config);