Skip to content

Commit

Permalink
refactor(frontend): rename tfhers.Context to tfhers.Bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
youben11 committed Sep 3, 2024
1 parent 19242e8 commit a951789
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion frontends/concrete-python/concrete/fhe/tfhers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions frontends/concrete-python/concrete/fhe/tfhers/context.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Declaration of `tfhers.Context` class.
Declaration of `tfhers.Bridge` class.
"""

from typing import List, Optional, Union
Expand All @@ -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]]
Expand Down Expand Up @@ -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
Expand All @@ -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)
18 changes: 9 additions & 9 deletions frontends/concrete-python/tests/execution/test_tfhers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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:
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit a951789

Please sign in to comment.