diff --git a/docs/dev/api/README.md b/docs/dev/api/README.md index 11a36aaab..8880aa37b 100644 --- a/docs/dev/api/README.md +++ b/docs/dev/api/README.md @@ -158,7 +158,7 @@ - [`graph.MultiGraphProcessor`](./concrete.fhe.representation.graph.md): MultiGraphProcessor base class, to define the API for a multiple graph processing pipeline. - [`node.Node`](./concrete.fhe.representation.node.md): Node class, to represent computation in a computation graph. - [`operation.Operation`](./concrete.fhe.representation.operation.md): Operation enum, to distinguish nodes within a computation graph. -- [`bridge.Bridge`](./concrete.fhe.tfhers.bridge.md): TFHErs Bridge extend a Circuit with TFHErs functionalities. +- [`bridge.Bridge`](./concrete.fhe.tfhers.bridge.md): TFHErs Bridge extend an Module with TFHErs functionalities. - [`dtypes.CryptoParams`](./concrete.fhe.tfhers.dtypes.md): Crypto parameters used for a tfhers integer. - [`dtypes.EncryptionKeyChoice`](./concrete.fhe.tfhers.dtypes.md): TFHErs key choice: big or small. - [`dtypes.TFHERSIntegerType`](./concrete.fhe.tfhers.dtypes.md) to represent tfhers integer types. @@ -355,7 +355,7 @@ - [`utils.format_constant`](./concrete.fhe.representation.utils.md): Get the textual representation of a constant. - [`utils.format_indexing_element`](./concrete.fhe.representation.utils.md): Format an indexing element. - [`tfhers.get_type_from_params`](./concrete.fhe.tfhers.md): Get a TFHE-rs integer type from TFHE-rs parameters in JSON format. -- [`bridge.new_bridge`](./concrete.fhe.tfhers.bridge.md): Create a TFHErs bridge from a circuit. +- [`bridge.new_bridge`](./concrete.fhe.tfhers.bridge.md): Create a TFHErs bridge from a circuit or module. - [`tracing.from_native`](./concrete.fhe.tfhers.tracing.md): Convert a Concrete integer to the tfhers representation. - [`tracing.to_native`](./concrete.fhe.tfhers.tracing.md): Convert a tfhers integer to the Concrete representation. - [`scalar.clear_scalar_builder`](./concrete.fhe.values.scalar.md): Build a clear scalar value. diff --git a/docs/dev/api/concrete.fhe.compilation.circuit.md b/docs/dev/api/concrete.fhe.compilation.circuit.md index d54af5f51..2de8e2913 100644 --- a/docs/dev/api/concrete.fhe.compilation.circuit.md +++ b/docs/dev/api/concrete.fhe.compilation.circuit.md @@ -149,12 +149,6 @@ Get the number of encrypted negations per tag per parameter in the circuit. --- -#### property function_name - -Return the name of the circuit. - ---- - #### property global_p_error Get the probability of having at least one simple TLU error during the entire execution. @@ -325,7 +319,7 @@ Get all statistics of the circuit. --- - + ### method `cleanup` @@ -337,7 +331,7 @@ Cleanup the temporary library output directory. --- - + ### method `decrypt` @@ -361,7 +355,7 @@ Decrypt result(s) of evaluation. --- - + ### method `draw` @@ -395,7 +389,7 @@ That this function requires the python `pygraphviz` package which itself require --- - + ### method `enable_fhe_execution` @@ -407,7 +401,7 @@ Enable FHE execution. --- - + ### method `enable_fhe_simulation` @@ -419,7 +413,7 @@ Enable FHE simulation. --- - + ### method `encrypt` @@ -443,7 +437,7 @@ Encrypt argument(s) to for evaluation. --- - + ### method `encrypt_run_decrypt` @@ -465,7 +459,7 @@ Encrypt inputs, run the circuit, and decrypt the outputs in one go. --- - + ### method `keygen` @@ -493,7 +487,7 @@ Generate keys required for homomorphic evaluation. --- - + ### method `run` @@ -517,7 +511,7 @@ Evaluate the circuit. --- - + ### method `simulate` diff --git a/docs/dev/api/concrete.fhe.compilation.keys.md b/docs/dev/api/concrete.fhe.compilation.keys.md index 432ee67be..e6ee91891 100644 --- a/docs/dev/api/concrete.fhe.compilation.keys.md +++ b/docs/dev/api/concrete.fhe.compilation.keys.md @@ -54,7 +54,7 @@ Return the associated client specs if any. --- - + ### method `deserialize` @@ -174,11 +174,31 @@ serialize() → bytes Serialize keys into bytes. -Serialized keys are not encrypted, so be careful how you store/transfer them! +Serialized keys are not encrypted, so be careful how you store/transfer them! `serialize_to_file` is supposed to be more performant as it avoid copying the buffer between the Compiler and the Frontend. **Returns:** bytes: serialized keys +--- + + + +### method `serialize_to_file` + +```python +serialize_to_file(path: Path) +``` + +Serialize keys into a file. + +Serialized keys are not encrypted, so be careful how you store/transfer them! This is supposed to be more performant than `serialize` as it avoid copying the buffer between the Compiler and the Frontend. + + + +**Args:** + + - `path` (Path): where to save serialized keys + diff --git a/docs/dev/api/concrete.fhe.compilation.module.md b/docs/dev/api/concrete.fhe.compilation.module.md index 7539111d5..5b21904ca 100644 --- a/docs/dev/api/concrete.fhe.compilation.module.md +++ b/docs/dev/api/concrete.fhe.compilation.module.md @@ -9,18 +9,30 @@ Declaration of `FheModule` classes. --- - + ## class `ExecutionRt` Runtime object class for execution. + + +### method `__init__` + +```python +__init__(client, server, auto_schedule_run) +``` + + + + + --- - + ## class `SimulationRt` Runtime object class for simulation. @@ -31,12 +43,12 @@ Runtime object class for simulation. --- - + ## class `FheFunction` Fhe function class, allowing to run or simulate one function of an fhe module. - + ### method `__init__` @@ -245,13 +257,13 @@ Get all statistics of the function. --- - + ### method `decrypt` ```python decrypt( - *results: Union[Value, Tuple[Value, ]] + *results: Union[Value, Tuple[Value, ], Awaitable[Union[Value, Tuple[Value, ]]]] ) → Union[int, ndarray, Tuple[Union[int, ndarray, NoneType], ], NoneType] ``` @@ -269,7 +281,7 @@ Decrypt result(s) of evaluation. --- - + ### method `draw` @@ -303,7 +315,7 @@ That this function requires the python `pygraphviz` package which itself require --- - + ### method `encrypt` @@ -327,7 +339,7 @@ Encrypt argument(s) to for evaluation. --- - + ### method `encrypt_run_decrypt` @@ -349,20 +361,66 @@ Encrypt inputs, run the function, and decrypt the outputs in one go. --- - + ### method `run` ```python run( *args: Optional[Value, Tuple[Union[Value], ], NoneType] -) → Union[Value, Tuple[Value, ]] +) → Union[Value, Tuple[Value, ], Awaitable[Union[Value, Tuple[Value, ]]]] ``` Evaluate the function. +**Args:** + *args (Value): argument(s) for evaluation + + + +**Returns:** + Union[Value, Tuple[Value, ...], Awaitable[Union[Value, Tuple[Value, ...]]]]: result(s) of evaluation or future of result(s) of evaluation if configured with async_run=True + +--- + + + +### method `run_async` + +```python +run_async( + *args: Optional[Value, Tuple[Union[Value], ], NoneType] +) → Union[Value, Tuple[Value, ], Awaitable[Union[Value, Tuple[Value, ]]]] +``` + +Evaluate the function asynchronuously. + + + +**Args:** + *args (Value): argument(s) for evaluation + + + +**Returns:** + Union[Awaitable[Value], Awaitable[Tuple[Value, ...]]]: result(s) a future of the evaluation + +--- + + + +### method `run_sync` + +```python +run_sync(*args: Optional[Value, Tuple[Union[Value], ], NoneType]) → Any +``` + +Evaluate the function synchronuously. + + + **Args:** *args (Value): argument(s) for evaluation @@ -373,7 +431,7 @@ Evaluate the function. --- - + ### method `simulate` @@ -396,12 +454,12 @@ Simulate execution of the function. --- - + ## class `FheModule` Fhe module class, to combine computation graphs, mlir, runtime objects into a single object. - + ### method `__init__` @@ -508,7 +566,7 @@ Get all statistics of the module. --- - + ### method `cleanup` @@ -520,7 +578,7 @@ Cleanup the temporary library output directory. --- - + ### method `functions` @@ -532,7 +590,7 @@ Return a dictionnary containing all the functions of the module. --- - + ### method `keygen` diff --git a/docs/dev/api/concrete.fhe.compilation.server.md b/docs/dev/api/concrete.fhe.compilation.server.md index 06e7c3883..56f558a54 100644 --- a/docs/dev/api/concrete.fhe.compilation.server.md +++ b/docs/dev/api/concrete.fhe.compilation.server.md @@ -87,7 +87,7 @@ Get size of the secret keys of the compiled program. --- - + ### method `cleanup` @@ -99,7 +99,7 @@ Cleanup the temporary library output directory. --- - + ### method `clear_addition_count` @@ -111,7 +111,7 @@ Get the number of clear additions in the compiled program. --- - + ### method `clear_addition_count_per_parameter` @@ -125,7 +125,7 @@ Get the number of clear additions per parameter in the compiled program. --- - + ### method `clear_addition_count_per_tag` @@ -137,7 +137,7 @@ Get the number of clear additions per tag in the compiled program. --- - + ### method `clear_addition_count_per_tag_per_parameter` @@ -151,7 +151,7 @@ Get the number of clear additions per tag per parameter in the compiled program. --- - + ### method `clear_multiplication_count` @@ -163,7 +163,7 @@ Get the number of clear multiplications in the compiled program. --- - + ### method `clear_multiplication_count_per_parameter` @@ -177,7 +177,7 @@ Get the number of clear multiplications per parameter in the compiled program. --- - + ### method `clear_multiplication_count_per_tag` @@ -189,7 +189,7 @@ Get the number of clear multiplications per tag in the compiled program. --- - + ### method `clear_multiplication_count_per_tag_per_parameter` @@ -234,7 +234,7 @@ Create a server using MLIR and output sign information. --- - + ### method `encrypted_addition_count` @@ -246,7 +246,7 @@ Get the number of encrypted additions in the compiled program. --- - + ### method `encrypted_addition_count_per_parameter` @@ -260,7 +260,7 @@ Get the number of encrypted additions per parameter in the compiled program. --- - + ### method `encrypted_addition_count_per_tag` @@ -272,7 +272,7 @@ Get the number of encrypted additions per tag in the compiled program. --- - + ### method `encrypted_addition_count_per_tag_per_parameter` @@ -286,7 +286,7 @@ Get the number of encrypted additions per tag per parameter in the compiled prog --- - + ### method `encrypted_negation_count` @@ -298,7 +298,7 @@ Get the number of encrypted negations in the compiled program. --- - + ### method `encrypted_negation_count_per_parameter` @@ -312,7 +312,7 @@ Get the number of encrypted negations per parameter in the compiled program. --- - + ### method `encrypted_negation_count_per_tag` @@ -324,7 +324,7 @@ Get the number of encrypted negations per tag in the compiled program. --- - + ### method `encrypted_negation_count_per_tag_per_parameter` @@ -338,7 +338,7 @@ Get the number of encrypted negations per tag per parameter in the compiled prog --- - + ### method `key_switch_count` @@ -350,7 +350,7 @@ Get the number of key switches in the compiled program. --- - + ### method `key_switch_count_per_parameter` @@ -364,7 +364,7 @@ Get the number of key switches per parameter in the compiled program. --- - + ### method `key_switch_count_per_tag` @@ -376,7 +376,7 @@ Get the number of key switches per tag in the compiled program. --- - + ### method `key_switch_count_per_tag_per_parameter` @@ -390,7 +390,7 @@ Get the number of key switches per tag per parameter in the compiled program. --- - + ### method `load` @@ -414,7 +414,7 @@ Load the server from the given path in zip format. --- - + ### method `memory_usage_per_location` @@ -426,7 +426,7 @@ Get the memory usage of operations per location. --- - + ### method `packing_key_switch_count` @@ -438,7 +438,7 @@ Get the number of packing key switches in the compiled program. --- - + ### method `packing_key_switch_count_per_parameter` @@ -452,7 +452,7 @@ Get the number of packing key switches per parameter in the compiled program. --- - + ### method `packing_key_switch_count_per_tag` @@ -464,7 +464,7 @@ Get the number of packing key switches per tag in the compiled program. --- - + ### method `packing_key_switch_count_per_tag_per_parameter` @@ -478,7 +478,7 @@ Get the number of packing key switches per tag per parameter in the compiled pro --- - + ### method `programmable_bootstrap_count` @@ -490,7 +490,7 @@ Get the number of programmable bootstraps in the compiled program. --- - + ### method `programmable_bootstrap_count_per_parameter` @@ -504,7 +504,7 @@ Get the number of programmable bootstraps per parameter in the compiled program. --- - + ### method `programmable_bootstrap_count_per_tag` @@ -516,7 +516,7 @@ Get the number of programmable bootstraps per tag in the compiled program. --- - + ### method `programmable_bootstrap_count_per_tag_per_parameter` @@ -530,7 +530,7 @@ Get the number of programmable bootstraps per tag per parameter in the compiled --- - + ### method `run` @@ -560,7 +560,7 @@ Evaluate. --- - + ### method `save` @@ -579,7 +579,7 @@ Save the server into the given path in zip format. --- - + ### method `size_of_inputs` @@ -591,7 +591,7 @@ Get size of the inputs of the compiled program. --- - + ### method `size_of_outputs` diff --git a/docs/dev/api/concrete.fhe.tfhers.bridge.md b/docs/dev/api/concrete.fhe.tfhers.bridge.md index 29d6ba643..597bc4726 100644 --- a/docs/dev/api/concrete.fhe.tfhers.bridge.md +++ b/docs/dev/api/concrete.fhe.tfhers.bridge.md @@ -8,21 +8,23 @@ Declaration of `tfhers.Bridge` class. --- - + ## function `new_bridge` ```python -new_bridge(circuit: 'Circuit') → Bridge +new_bridge( + circuit_or_module: Union[ForwardRef('Circuit'), ForwardRef('Module')] +) → Bridge ``` -Create a TFHErs bridge from a circuit. +Create a TFHErs bridge from a circuit or module. **Args:** - - `circuit` (Circuit): compiled circuit + - `circuit` (Union[Circuit, Module]): compiled circuit or module @@ -36,21 +38,21 @@ Create a TFHErs bridge from a circuit. ## class `Bridge` -TFHErs Bridge extend a Circuit with TFHErs functionalities. +TFHErs Bridge extend an Module with TFHErs functionalities. -input_types (List[Optional[TFHERSIntegerType]]): maps every input to a type. None means a non-tfhers type output_types (List[Optional[TFHERSIntegerType]]): maps every output to a type. None means a non-tfhers type input_shapes (List[Optional[Tuple[int, ...]]]): maps every input to a shape. None means a non-tfhers type output_shapes (List[Optional[Tuple[int, ...]]]): maps every output to a shape. None means a non-tfhers type +input_types_per_func (Dict[str, List[Optional[TFHERSIntegerType]]]): maps every input to a type for every function in the module. None means a non-tfhers type output_types_per_func (Dict[str, List[Optional[TFHERSIntegerType]]]): maps every output to a type for every function in the module. None means a non-tfhers type input_shapes_per_func (Dict[str, List[Optional[Tuple[int, ...]]]]): maps every input to a shape for every function in the module. None means a non-tfhers type output_shapes_per_func (Dict[str, List[Optional[Tuple[int, ...]]]]): maps every output to a shape for every function in the module. None means a non-tfhers type - + ### method `__init__` ```python __init__( - circuit: 'Circuit', - input_types: List[Optional[TFHERSIntegerType]], - output_types: List[Optional[TFHERSIntegerType]], - input_shapes: List[Optional[Tuple[int, ]]], - output_shapes: List[Optional[Tuple[int, ]]] + module: 'Module', + input_types_per_func: Dict[str, List[Optional[TFHERSIntegerType]]], + output_types_per_func: Dict[str, List[Optional[TFHERSIntegerType]]], + input_shapes_per_func: Dict[str, List[Optional[Tuple[int, ]]]], + output_shapes_per_func: Dict[str, List[Optional[Tuple[int, ]]]] ) ``` @@ -63,12 +65,16 @@ __init__( --- - + ### method `export_value` ```python -export_value(value: Value, output_idx: int) → bytes +export_value( + value: Value, + output_idx: int, + func_name: Optional[str] = None +) → bytes ``` Export a value as a serialized TFHErs integer. @@ -79,6 +85,7 @@ Export a value as a serialized TFHErs integer. - `value` (TransportValue): value to export - `output_idx` (int): the index corresponding to this output + - `func_name` (Optional[str]): name of the function the value belongs to. Doesn't need to be provided if there is a single function. @@ -88,12 +95,16 @@ Export a value as a serialized TFHErs integer. --- - + ### method `import_value` ```python -import_value(buffer: bytes, input_idx: int) → Value +import_value( + buffer: bytes, + input_idx: int, + func_name: Optional[str] = None +) → Value ``` Import a serialized TFHErs integer as a Value. @@ -104,6 +115,7 @@ Import a serialized TFHErs integer as a Value. - `buffer` (bytes): serialized integer - `input_idx` (int): the index of the input expecting this value + - `func_name` (Optional[str]): name of the function the value belongs to. Doesn't need to be provided if there is a single function. @@ -113,13 +125,13 @@ Import a serialized TFHErs integer as a Value. --- - + ### method `keygen_with_initial_keys` ```python keygen_with_initial_keys( - input_idx_to_key_buffer: Dict[int, bytes], + input_idx_to_key_buffer: Dict[Union[Tuple[str, int], int], bytes], force: bool = False, seed: Optional[int] = None, encryption_seed: Optional[int] = None @@ -137,8 +149,8 @@ Generate keys using an initial set of secret keys. encryption_seed (Optional[int], default = None): seed for encryption randomness - - - `input_idx_to_key_buffer` (Dict[int, bytes]): initial keys to set before keygen + 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. @@ -148,12 +160,15 @@ Generate keys using an initial set of secret keys. --- - + ### method `serialize_input_secret_key` ```python -serialize_input_secret_key(input_idx: int) → bytes +serialize_input_secret_key( + input_idx: int, + func_name: Optional[str] = None +) → bytes ``` Serialize secret key used for a specific input. @@ -163,6 +178,7 @@ Serialize secret key used for a specific input. **Args:** - `input_idx` (int): input index corresponding to the key to serialize + - `func_name` (Optional[str]): name of the function the key belongs to. Doesn't need to be provided if there is a single function.