Skip to content

Commit

Permalink
fix(frontends): add default configuration for fhe modules
Browse files Browse the repository at this point in the history
  • Loading branch information
aPere3 authored and BourgerieQuentin committed Apr 4, 2024
1 parent 2eae071 commit 14cebfc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 29 deletions.
2 changes: 2 additions & 0 deletions frontends/concrete-python/concrete/fhe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
DebugArtifacts,
EncryptionStatus,
Exactness,
FunctionDebugArtifacts,
Keys,
MinMaxStrategy,
ModuleDebugArtifacts,
MultiParameterStrategy,
MultivariateStrategy,
ParameterSelectionStrategy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,11 @@ class ModuleCompiler:
compilation_context: CompilationContext

def __init__(self, functions: List[FunctionDef]):
self.configuration = Configuration(composable=True)
self.default_configuration = Configuration(
p_error=0.00001,
composable=True,
parameter_selection_strategy="v0",
)
self.functions = {function.name: function for function in functions}
self.compilation_context = CompilationContext.new()

Expand Down Expand Up @@ -512,7 +516,7 @@ def compile(
for name, function in self.functions.items():
inputset = inputsets[name] if inputsets is not None else None
function_artifacts = module_artifacts.functions[name]
function.evaluate("Compiling", inputset, self.configuration, function_artifacts)
function.evaluate("Compiling", inputset, configuration, function_artifacts)
assert function.graph is not None
dbg.debug_computation_graph(name, function.graph)

Expand All @@ -524,7 +528,7 @@ def compile(
error = "Expected graph to be set."
raise RuntimeError(error)
graphs[name] = function.graph
mlir_module = GraphConverter(self.configuration).convert_many(graphs, mlir_context)
mlir_module = GraphConverter(configuration).convert_many(graphs, mlir_context)
mlir_str = str(mlir_module).strip()
dbg.debug_mlir(mlir_str)
module_artifacts.add_mlir_to_compile(mlir_str)
Expand All @@ -551,7 +555,7 @@ def compile(
# if the user desires so,
# we need to export all the information we have about the compilation

if self.configuration.dump_artifacts_on_unexpected_failures:
if configuration.dump_artifacts_on_unexpected_failures:
module_artifacts.export()

traceback_path = self.artifacts.output_directory.joinpath("traceback.txt")
Expand Down
29 changes: 4 additions & 25 deletions frontends/concrete-python/tests/compilation/test_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def mul(x, y):
assert Module.mul(3, 4) == 12


def test_compile(helpers):
def test_compile():
"""
Test that compiling a module works.
"""
Expand All @@ -65,19 +65,10 @@ def dec(x):
return x - 1

inputset = [np.random.randint(1, 20, size=()) for _ in range(100)]
configuration = helpers.configuration().fork(
p_error=0.1,
parameter_selection_strategy="v0",
composable=True,
verbose=True,
)
Module.compile(
{"inc": inputset, "dec": inputset},
configuration,
)
Module.compile({"inc": inputset, "dec": inputset}, verbose=True)


def test_compiled_clear_call(helpers):
def test_compiled_clear_call():
"""
Test that cleartext execution works on compiled objects.
"""
Expand All @@ -93,21 +84,15 @@ def dec(x):
return x - 1

inputset = [np.random.randint(1, 20, size=()) for _ in range(100)]
configuration = helpers.configuration().fork(
p_error=0.1,
parameter_selection_strategy="v0",
composable=True,
)
module = Module.compile(
{"inc": inputset, "dec": inputset},
configuration,
)

assert module.inc(5) == 6
assert module.dec(5) == 4


def test_encrypted_execution(helpers):
def test_encrypted_execution():
"""
Test that encrypted execution works.
"""
Expand All @@ -123,14 +108,8 @@ def dec(x):
return x - 1 % 20

inputset = [np.random.randint(1, 20, size=()) for _ in range(100)]
configuration = helpers.configuration().fork(
p_error=0.1,
parameter_selection_strategy="v0",
composable=True,
)
module = Module.compile(
{"inc": inputset, "dec": inputset},
configuration,
)

x = 5
Expand Down

0 comments on commit 14cebfc

Please sign in to comment.