5.3 KiB
module torus.fhe.tfhers.bridge
Declaration of tfhers.Bridge class.
function new_bridge
new_bridge(
circuit_or_module_or_client: Union[ForwardRef('Circuit'), ForwardRef('Module'), ForwardRef('Client')]
) → Bridge
Create a TFHErs bridge from a circuit or module or client.
Args: client (Union["fhe.Circuit", "fhe.Module", "fhe.Client"]): The client|circuit|module instance to be used by the Bridge.
Returns:
Bridge: A new Bridge instance attached to the provided client.
class Bridge
TFHErs Bridge extend a Client with TFHErs functionalities.
client (fhe.Client): the client instance to be attached by the Bridge tfhers_specs (fhe.tfhers.TFHERSClientSpecs): the TFHE-rs specs of the client
method __init__
__init__(client: 'Client')
property input_shapes_per_func
Return the input shapes per function map.
property input_types_per_func
Return the input types per function map.
property output_shapes_per_func
Return the output shapes per function map.
property output_types_per_func
Return the output types per function map.
method export_value
export_value(
value: Value,
output_idx: int,
func_name: Optional[str] = None
) → bytes
Export a value as a serialized TFHErs integer.
Args:
value(TransportValue): value to exportoutput_idx(int): the index corresponding to this outputfunc_name(Optional[str]): name of the function the value belongs to. Doesn't need to be provided if there is a single function.
Returns:
bytes: serialized fheuint8
method import_value
import_value(
buffer: bytes,
input_idx: int,
func_name: Optional[str] = None
) → Value
Import a serialized TFHErs integer as a Value.
Args:
buffer(bytes): serialized integerinput_idx(int): the index of the input expecting this valuefunc_name(Optional[str]): name of the function the value belongs to. Doesn't need to be provided if there is a single function.
Returns:
fhe.TransportValue: imported value
method keygen_with_initial_keys
keygen_with_initial_keys(
input_idx_to_key_buffer: dict[Union[tuple[str, int], int], bytes],
force: bool = False,
seed: Optional[int] = None,
encryption_seed: Optional[int] = None
)
Generate keys using an initial set of secret keys.
Args: force (bool, default = False): whether to generate new keys even if keys are already generated
seed (Optional[int], default = None): seed for private keys randomness
encryption_seed (Optional[int], default = None): seed for encryption randomness
input_idx_to_key_buffer (Dict[Union[Tuple[str, int], int], bytes]):
initial keys to set before keygen. Two possible formats: the first is when you have a single function. Here you can just provide the position of the input as index. The second is when you have multiple functions. You will need to provide both the name of the function and the input's position as index.
Raises:
RuntimeError: if failed to deserialize the key
method serialize_input_secret_key
serialize_input_secret_key(
input_idx: int,
func_name: Optional[str] = None
) → bytes
Serialize secret key used for a specific input.
Args:
input_idx(int): input index corresponding to the key to serializefunc_name(Optional[str]): name of the function the key belongs to. Doesn't need to be provided if there is a single function.
Returns:
bytes: serialized key