-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(optimizer): support external partition in virtual circuits #1187
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -647,6 +647,12 @@ void mlir::concretelang::python::populateCompilerAPISubmodule( | |
}, | ||
"Enable or disable overflow detection during simulation.", | ||
arg("enable_overflow_detection")) | ||
.def( | ||
"get_optimizer_options", | ||
[](CompilationOptions &options) -> concrete_optimizer::Options { | ||
return options_from_config(options.optimizerConfig); | ||
}, | ||
"Returns the associated optimizer configuration") | ||
.doc() = "Holds different flags and options of the compilation process."; | ||
|
||
pybind11::enum_<mlir::concretelang::PrimitiveOperation>(m, | ||
|
@@ -1069,35 +1075,57 @@ void mlir::concretelang::python::populateCompilerAPISubmodule( | |
// ------------------------------------------------------------------------------// | ||
// PARTITION DEFINITION // | ||
// ------------------------------------------------------------------------------// | ||
// | ||
pybind11::class_<concrete_optimizer::utils::PartitionDefinition>( | ||
m, "PartitionDefinition") | ||
pybind11::class_<concrete_optimizer::utils::InternalPartitionDefinition>( | ||
m, "InternalPartitionDefinition") | ||
.def(init([](uint8_t precision, double norm2) | ||
-> concrete_optimizer::utils::PartitionDefinition { | ||
return concrete_optimizer::utils::PartitionDefinition{precision, | ||
norm2}; | ||
-> concrete_optimizer::utils::InternalPartitionDefinition { | ||
return concrete_optimizer::utils::InternalPartitionDefinition{ | ||
precision, norm2}; | ||
}), | ||
arg("precision"), arg("norm2")) | ||
.doc() = "Definition of a partition (in terms of precision in bits and " | ||
"norm2 in value)."; | ||
|
||
// ------------------------------------------------------------------------------// | ||
// EXTERNAL PARTITION // | ||
// ------------------------------------------------------------------------------// | ||
pybind11::class_<concrete_optimizer::utils::ExternalPartitionDefinition>( | ||
m, "ExternalPartitionDefinition") | ||
.def(init([](std::string name, uint64_t macroLog2PolynomialSize, | ||
uint64_t macroGlweDimension, uint64_t macroInternalDim, | ||
uint64_t pbsLevel, uint64_t pbsBaseLog) | ||
-> concrete_optimizer::utils::ExternalPartitionDefinition { | ||
return concrete_optimizer::utils::ExternalPartitionDefinition{ | ||
name, | ||
macroLog2PolynomialSize, | ||
macroGlweDimension, | ||
macroInternalDim, | ||
pbsLevel, | ||
pbsBaseLog}; | ||
}), | ||
arg("name"), arg("macro_log2_polynomial_size"), | ||
arg("macro_glwe_dimension"), arg("macro_internal_dim"), | ||
arg("pbs_level"), arg("pbs_base_log")) | ||
.doc() = "Definition of an external partition."; | ||
|
||
// ------------------------------------------------------------------------------// | ||
// KEYSET INFO // | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about keygen using KeySetInfo instead of ProgramInfo? If it requires a lot of changes in the frontend, then we can think about having both. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentionned at the end of our discussion, I thought it may incorrectly nudge the user into generating keysets from the virtual keyset info, which would yield a big keygen, while just a small subset would be needed for the circuit. And thinking about it a bit more, I don't think it would work to use a superset of the necessary keyset on a circuit (nothing fancy, just that we index keys by number, and as such, we may incorrectly lookup keys). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sense yeah. I'm just thinking how can we showcase the feature then... We just need a way to construct a keyset from a program info using pregenerated keys. If we had a big keyset (with more keys than what the circuit needs), we could have a method that takes the program info and the big keyset, and extract necessary keys with their appropriate index. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @BourgerieQuentin WDYT ? |
||
// ------------------------------------------------------------------------------// | ||
typedef Message<concreteprotocol::KeysetInfo> KeysetInfo; | ||
pybind11::class_<KeysetInfo>(m, "KeysetInfo") | ||
.def_static( | ||
"generate_virtual", | ||
[](std::vector<concrete_optimizer::utils::PartitionDefinition> | ||
partitions, | ||
bool generateFks, | ||
[](std::vector<concrete_optimizer::utils::InternalPartitionDefinition> | ||
internalPartitions, | ||
std::vector<concrete_optimizer::utils::ExternalPartitionDefinition> | ||
externalPartitions, | ||
std::optional<concrete_optimizer::Options> options) -> KeysetInfo { | ||
if (partitions.size() < 2) { | ||
if (internalPartitions.size() + externalPartitions.size() < 2) { | ||
throw std::runtime_error("Need at least two partition defs to " | ||
"generate a virtual keyset info."); | ||
} | ||
return ::concretelang::keysets::keysetInfoFromVirtualCircuit( | ||
partitions, generateFks, options); | ||
internalPartitions, externalPartitions, options); | ||
}, | ||
arg("partition_defs"), arg("generate_fks"), | ||
arg("options") = std::nullopt, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if macroInternalDim have any use now or in the future !?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how this is used, but it is needed to construct the external partition structure in the optimizer ...