From a9517896ed00796ce14910e5d0c75b54e0d810e2 Mon Sep 17 00:00:00 2001 From: youben11 Date: Fri, 30 Aug 2024 10:12:29 +0100 Subject: [PATCH] refactor(frontend): rename tfhers.Context to tfhers.Bridge --- .../concrete/fhe/tfhers/__init__.py | 2 +- .../concrete/fhe/tfhers/context.py | 16 ++++++++-------- .../tests/execution/test_tfhers.py | 18 +++++++++--------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/frontends/concrete-python/concrete/fhe/tfhers/__init__.py b/frontends/concrete-python/concrete/fhe/tfhers/__init__.py index 033c645af3..82b54e4273 100644 --- a/frontends/concrete-python/concrete/fhe/tfhers/__init__.py +++ b/frontends/concrete-python/concrete/fhe/tfhers/__init__.py @@ -2,7 +2,7 @@ tfhers module to represent, and compute on tfhers integer values. """ -from .context import new_context +from .context import new_bridge from .dtypes import ( CryptoParams, EncryptionKeyChoice, diff --git a/frontends/concrete-python/concrete/fhe/tfhers/context.py b/frontends/concrete-python/concrete/fhe/tfhers/context.py index 0f0c3c34e6..a5e2c7da2b 100644 --- a/frontends/concrete-python/concrete/fhe/tfhers/context.py +++ b/frontends/concrete-python/concrete/fhe/tfhers/context.py @@ -1,5 +1,5 @@ """ -Declaration of `tfhers.Context` class. +Declaration of `tfhers.Bridge` class. """ from typing import List, Optional, Union @@ -11,8 +11,8 @@ from .dtypes import EncryptionKeyChoice, TFHERSIntegerType -class Context: - """TFHErs Context extend a Circuit with TFHErs functionalities.""" +class Bridge: + """TFHErs Bridge extend a Circuit with TFHErs functionalities.""" circuit: "fhe.Circuit" input_types: Union[List[Optional[TFHERSIntegerType]], Optional[TFHERSIntegerType]] @@ -183,13 +183,13 @@ def serialize_input_secret_key(self, input_idx: int) -> bytes: # pylint: enable=protected-access -def new_context( +def new_bridge( circuit: "fhe.Circuit", input_types: Union[List[Optional[TFHERSIntegerType]], Optional[TFHERSIntegerType]], output_types: Union[List[Optional[TFHERSIntegerType]], Optional[TFHERSIntegerType]], func_name: str = "main", -) -> Context: - """Create a TFHErs context from a circuit. +) -> Bridge: + """Create a TFHErs bridge from a circuit. Args: circuit (Circuit): compiled circuit @@ -202,6 +202,6 @@ def new_context( func_name (str, optional): name of the function to use. Defaults to "main". Returns: - Context: TFHErs context + Bridge: TFHErs bridge """ - return Context(circuit, input_types, output_types, func_name) + return Bridge(circuit, input_types, output_types, func_name) diff --git a/frontends/concrete-python/tests/execution/test_tfhers.py b/frontends/concrete-python/tests/execution/test_tfhers.py index 11d4bc7a20..b222c5835b 100644 --- a/frontends/concrete-python/tests/execution/test_tfhers.py +++ b/frontends/concrete-python/tests/execution/test_tfhers.py @@ -382,11 +382,11 @@ def test_tfhers_binary_encrypted_complete_circuit_concrete_keygen( assert (dtype.decode(concrete_encoded_result) == function(*sample)).all() ###### TFHErs Encryption ###################################################### - tfhers_context = tfhers.new_context(circuit, dtype, dtype, func_name="main") + tfhers_bridge = tfhers.new_bridge(circuit, dtype, dtype, func_name="main") # serialize key _, key_path = tempfile.mkstemp() - serialized_key = tfhers_context.serialize_input_secret_key(input_idx=0) + serialized_key = tfhers_bridge.serialize_input_secret_key(input_idx=0) with open(key_path, "wb") as f: f.write(serialized_key) @@ -409,10 +409,10 @@ def test_tfhers_binary_encrypted_complete_circuit_concrete_keygen( cts = [] with open(ct1_path, "rb") as f: buff = f.read() - cts.append(tfhers_context.import_value(buff, 0)) + cts.append(tfhers_bridge.import_value(buff, 0)) with open(ct2_path, "rb") as f: buff = f.read() - cts.append(tfhers_context.import_value(buff, 1)) + cts.append(tfhers_bridge.import_value(buff, 1)) os.remove(ct1_path) os.remove(ct2_path) @@ -423,7 +423,7 @@ def test_tfhers_binary_encrypted_complete_circuit_concrete_keygen( assert (dtype.decode(decrypted) == function(*sample)).all() # type: ignore # tfhers decryption - buff = tfhers_context.export_value(tfhers_encrypted_result, output_idx=0) # type: ignore + buff = tfhers_bridge.export_value(tfhers_encrypted_result, output_idx=0) # type: ignore _, ct_out_path = tempfile.mkstemp() _, pt_path = tempfile.mkstemp() with open(ct_out_path, "wb") as f: @@ -577,11 +577,11 @@ def test_tfhers_one_tfhers_one_native_complete_circuit_concrete_keygen( assert (dtype.decode(concrete_encoded_result) == function(*sample)).all() ###### TFHErs Encryption ###################################################### - tfhers_context = tfhers.new_context(circuit, dtype, dtype, func_name="main") + tfhers_bridge = tfhers.new_bridge(circuit, dtype, dtype, func_name="main") # serialize key _, key_path = tempfile.mkstemp() - serialized_key = tfhers_context.serialize_input_secret_key(input_idx=0) + serialized_key = tfhers_bridge.serialize_input_secret_key(input_idx=0) with open(key_path, "wb") as f: f.write(serialized_key) @@ -599,7 +599,7 @@ def test_tfhers_one_tfhers_one_native_complete_circuit_concrete_keygen( # import first ciphertexts and encrypt second with concrete with open(ct1_path, "rb") as f: buff = f.read() - tfhers_ct = tfhers_context.import_value(buff, 0) + tfhers_ct = tfhers_bridge.import_value(buff, 0) os.remove(ct1_path) _, native_ct = circuit.encrypt(None, sample[1]) # type: ignore @@ -611,7 +611,7 @@ def test_tfhers_one_tfhers_one_native_complete_circuit_concrete_keygen( assert (dtype.decode(decrypted) == function(*sample)).all() # type: ignore # tfhers decryption - buff = tfhers_context.export_value(tfhers_encrypted_result, output_idx=0) # type: ignore + buff = tfhers_bridge.export_value(tfhers_encrypted_result, output_idx=0) # type: ignore _, ct_out_path = tempfile.mkstemp() _, pt_path = tempfile.mkstemp() with open(ct_out_path, "wb") as f: