From b911945c987ff27681908e5aac123f884b112930 Mon Sep 17 00:00:00 2001 From: Benoit Chevallier-Mames Date: Thu, 25 Jul 2024 12:37:32 +0200 Subject: [PATCH] fix(frontend): fixing an issue in the string generation closes #819 --- .../levenshtein_distance/levenshtein_distance.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/frontends/concrete-python/examples/levenshtein_distance/levenshtein_distance.py b/frontends/concrete-python/examples/levenshtein_distance/levenshtein_distance.py index 04382dd3d1..cf65cf6ec8 100644 --- a/frontends/concrete-python/examples/levenshtein_distance/levenshtein_distance.py +++ b/frontends/concrete-python/examples/levenshtein_distance/levenshtein_distance.py @@ -40,6 +40,7 @@ def dna(): def __init__(self, letters: str): self.letters = letters + self.mapping_to_int = {} for i, c in enumerate(self.letters): self.mapping_to_int[c] = i @@ -75,7 +76,10 @@ def random_pick_in_values(self) -> int: def _random_string(self, length: int) -> str: """Pick a random string in the alphabet.""" - return "".join([random.choice(list(self.mapping_to_int)) for _ in range(length)]) + ans = "".join([random.choice(list(self.mapping_to_int)) for _ in range(length)]) + check = [c in self.letters for c in ans] + assert all(check), "Issue in generation" + return ans def prepare_random_patterns(self, len_min: int, len_max: int, nb_strings: int) -> list: """Prepare random patterns of different lengths.""" @@ -223,18 +227,15 @@ def _compute_in_fhe(self, list_patterns: list, show_distance: bool = False): # Module FHE @fhe.module() class LevenshsteinModule: - @staticmethod @fhe.function({"x": "encrypted", "y": "encrypted"}) def equal(x, y): """Assert equality between two chars of the alphabet.""" return x == y - @staticmethod @fhe.function({"x": "clear"}) def constant(x): return fhe.zero() + x - @staticmethod @fhe.function( { "is_equal": "encrypted",