enhance(feedback): Add p_error and global_perror to the compiler feedback

This commit is contained in:
Quentin Bourgerie
2022-11-23 11:34:48 +01:00
parent 722e4d2eba
commit 5d89ad0f84
6 changed files with 26 additions and 1 deletions

View File

@@ -22,6 +22,12 @@ using StringError = ::concretelang::error::StringError;
struct CompilationFeedback {
double complexity;
/// @brief Probability of error for every PBS.
double pError;
/// @brief Probability of error for the whole programs.
double globalPError;
/// @brief the total number of bytes of secret keys
uint64_t totalSecretKeysSize;

View File

@@ -76,6 +76,9 @@ void mlir::concretelang::python::populateCompilerAPISubmodule(
m, "CompilationFeedback")
.def_readonly("complexity",
&mlir::concretelang::CompilationFeedback::complexity)
.def_readonly("p_error", &mlir::concretelang::CompilationFeedback::pError)
.def_readonly("global_p_error",
&mlir::concretelang::CompilationFeedback::globalPError)
.def_readonly(
"total_secret_keys_size",
&mlir::concretelang::CompilationFeedback::totalSecretKeysSize)

View File

@@ -31,6 +31,8 @@ class CompilationFeedback(WrapperCpp):
)
self.complexity = compilation_feedback.complexity
self.p_error = compilation_feedback.p_error
self.global_p_error = compilation_feedback.global_p_error
self.total_secret_keys_size = compilation_feedback.total_secret_keys_size
self.total_bootstrap_keys_size = compilation_feedback.total_bootstrap_keys_size
self.total_keyswitch_keys_size = compilation_feedback.total_keyswitch_keys_size

View File

@@ -84,6 +84,8 @@ CompilationFeedback::load(std::string jsonPath) {
llvm::json::Value toJSON(const mlir::concretelang::CompilationFeedback &v) {
llvm::json::Object object{
{"complexity", v.complexity},
{"pError", v.pError},
{"globalPError", v.globalPError},
{"totalSecretKeysSize", v.totalSecretKeysSize},
{"totalBootstrapKeysSize", v.totalBootstrapKeysSize},
{"totalKeyswitchKeysSize", v.totalKeyswitchKeysSize},
@@ -97,7 +99,8 @@ llvm::json::Value toJSON(const mlir::concretelang::CompilationFeedback &v) {
bool fromJSON(const llvm::json::Value j,
mlir::concretelang::CompilationFeedback &v, llvm::json::Path p) {
llvm::json::ObjectMapper O(j, p);
return O && O.map("complexity", v.complexity) &&
return O && O.map("complexity", v.complexity) && O.map("pError", v.pError) &&
O.map("globalPError", v.globalPError) &&
O.map("totalSecretKeysSize", v.totalSecretKeysSize) &&
O.map("totalBootstrapKeysSize", v.totalBootstrapKeysSize) &&
O.map("totalKeyswitchKeysSize", v.totalKeyswitchKeysSize) &&

View File

@@ -241,6 +241,9 @@ llvm::Expected<V0Parameter> getParameter(optimizer::Description &descr,
}
feedback.complexity = sol.complexity;
feedback.pError = sol.p_error;
feedback.globalPError =
std::isnan(sol.global_p_error) ? 0 : sol.global_p_error;
return params;
}

View File

@@ -30,6 +30,14 @@ def run(engine, args, compilation_result, keyset_cache):
# Dev
compilation_feedback = engine.load_compilation_feedback(compilation_result)
assert isinstance(compilation_feedback, CompilationFeedback)
assert isinstance(compilation_feedback.complexity, float)
assert isinstance(compilation_feedback.p_error, float)
assert isinstance(compilation_feedback.global_p_error, float)
assert isinstance(compilation_feedback.total_secret_keys_size, int)
assert isinstance(compilation_feedback.total_bootstrap_keys_size, int)
assert isinstance(compilation_feedback.total_inputs_size, int)
assert isinstance(compilation_feedback.total_output_size, int)
# Client
client_parameters = engine.load_client_parameters(compilation_result)
key_set = ClientSupport.key_set(client_parameters, keyset_cache)