Skip to content

Commit

Permalink
docs(frontend): adding perfs
Browse files Browse the repository at this point in the history
  • Loading branch information
bcm-at-zama committed Jun 28, 2024
1 parent e2dceee commit e1f791a
Showing 1 changed file with 39 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ def manage_args():
action="store_true",
help="Run random tests",
)
parser.add_argument(
"--autoperf",
dest="autoperf",
action="store_true",
help="Run benchmarks",
)
parser.add_argument(
"--alphabet",
dest="alphabet",
Expand Down Expand Up @@ -189,7 +195,7 @@ def compile_module(mapping_to_int, args):
return my_module


def prepare_alphabet_mapping(alphabet):
def prepare_alphabet_mapping(alphabet, verbose=True):
if alphabet == "string":
letters = "".join([chr(97 + i) for i in range(26)])
elif alphabet == "STRING":
Expand All @@ -201,8 +207,9 @@ def prepare_alphabet_mapping(alphabet):
else:
raise ValueError(f"Unknown alphabet {alphabet}")

print(f"Making random tests with alphabet {alphabet}")
print(f"Letters are {letters}\n")
if verbose:
print(f"Making random tests with alphabet {alphabet}")
print(f"Letters are {letters}\n")

mapping_to_int = {}

Expand All @@ -212,18 +219,19 @@ def prepare_alphabet_mapping(alphabet):
return mapping_to_int


def prepare_random_patterns(mapping_to_int, args):
def prepare_random_patterns(mapping_to_int, len_min, len_max, nb_strings):
# Random patterns of different lengths
list_patterns = []
for length_1 in range(args.max_string_length + 1):
for length_2 in range(args.max_string_length + 1):
list_patterns += [
(
random_string(mapping_to_int, length_1),
random_string(mapping_to_int, length_2),
)
for _ in range(1)
]
for _ in range(nb_strings):
for length_1 in range(len_min, len_max + 1):
for length_2 in range(len_min, len_max + 1):
list_patterns += [
(
random_string(mapping_to_int, length_1),
random_string(mapping_to_int, length_2),
)
for _ in range(1)
]

return list_patterns

Expand All @@ -247,12 +255,13 @@ def compute_in_simulation(my_module, list_patterns, mapping_to_int):
print(" - OK")


def compute_in_fhe(my_module, list_patterns, mapping_to_int):
def compute_in_fhe(my_module, list_patterns, mapping_to_int, verbose=False):
# Key generation
my_module.keygen()

# Checks in FHE
print("\nComputations in FHE\n")
if verbose:
print("\nComputations in FHE\n")

for a, b in list_patterns:

Expand Down Expand Up @@ -286,11 +295,23 @@ def main():
if args.autotest:
mapping_to_int = prepare_alphabet_mapping(args.alphabet)
my_module = compile_module(mapping_to_int, args)
list_patterns = prepare_random_patterns(mapping_to_int, args)
list_patterns = prepare_random_patterns(mapping_to_int, 0, args.max_string_length, 1)
compute_in_simulation(my_module, list_patterns, mapping_to_int)
compute_in_fhe(my_module, list_patterns, mapping_to_int)

print("\nSuccessful end\n")
print("")

if args.autoperf:
for alphabet in ["ACTG", "string", "STRING", "StRiNg"]:
print(f"Typical performances for alphabet {alphabet}, with string of maximal length:\n")
mapping_to_int = prepare_alphabet_mapping(alphabet, verbose=False)
my_module = compile_module(mapping_to_int, args)
list_patterns = prepare_random_patterns(
mapping_to_int, args.max_string_length, args.max_string_length, 3
)
compute_in_fhe(my_module, list_patterns, mapping_to_int, verbose=False)
print("")

print("Successful end\n")


if __name__ == "__main__":
Expand Down

0 comments on commit e1f791a

Please sign in to comment.