Skip to content

Commit

Permalink
docs(frontend): Proposal with constant
Browse files Browse the repository at this point in the history
  • Loading branch information
BourgerieQuentin committed Jul 5, 2024
1 parent 46f1cd5 commit 380a523
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def mix(is_equal, if_equal, case_1, case_2, case_3):

return fhe.if_then_else(is_equal, if_equal, 1 + min_123)

@fhe.function({"x": "clear"})
def constant(x):
return fhe.zero() + x

# There is a single output in mix: it can go to
# - input 1 of mix
# - input 2 of mix
Expand All @@ -71,6 +75,10 @@ def mix(is_equal, if_equal, case_1, case_2, case_3):
fhe.Wire(fhe.AllOutputs(mix), fhe.Input(mix, 2)),
fhe.Wire(fhe.AllOutputs(mix), fhe.Input(mix, 3)),
fhe.Wire(fhe.AllOutputs(mix), fhe.Input(mix, 4)),
fhe.Wire(fhe.AllOutputs(constant), fhe.Input(mix, 1)),
fhe.Wire(fhe.AllOutputs(constant), fhe.Input(mix, 2)),
fhe.Wire(fhe.AllOutputs(constant), fhe.Input(mix, 3)),
fhe.Wire(fhe.AllOutputs(constant), fhe.Input(mix, 4)),
]
)

Expand Down Expand Up @@ -116,9 +124,9 @@ def levenshtein_simulate(my_module, x, y):
def levenshtein_fhe(my_module, x, y):
"""Compute the distance in FHE."""
if len(x) == 0:
return my_module.mix.encrypt(None, len(y), None, None, None)[1]
return my_module.constant.run(my_module.constant.encrypt(len(y)))
if len(y) == 0:
return my_module.mix.encrypt(None, len(x), None, None, None)[1]
return my_module.constant.run(my_module.constant.encrypt(len(x)))

if_equal = levenshtein_fhe(my_module, x[1:], y[1:])
case_1 = levenshtein_fhe(my_module, x[1:], y)
Expand Down Expand Up @@ -208,7 +216,7 @@ def compile_module(mapping_to_int, args):
]

my_module = LevenshsteinModule.compile(
{"equal": inputset_equal, "mix": inputset_mix},
{"equal": inputset_equal, "mix": inputset_mix, "constant": [i for i in range(len(mapping_to_int))]},
show_mlir=args.show_mlir,
p_error=10**-20,
show_optimizer=args.show_optimizer,
Expand Down

0 comments on commit 380a523

Please sign in to comment.