diff --git a/concrete/numpy/__init__.py b/concrete/numpy/__init__.py index 0a3d3355a..1ad2e263a 100644 --- a/concrete/numpy/__init__.py +++ b/concrete/numpy/__init__.py @@ -5,6 +5,8 @@ Export everything that users might need. from concrete.compiler import EvaluationKeys, PublicArguments, PublicResult from .compilation import ( + DEFAULT_GLOBAL_P_ERROR, + DEFAULT_P_ERROR, Circuit, Client, ClientSpecs, diff --git a/concrete/numpy/compilation/__init__.py b/concrete/numpy/compilation/__init__.py index 05b4f1770..7fa7edf3a 100644 --- a/concrete/numpy/compilation/__init__.py +++ b/concrete/numpy/compilation/__init__.py @@ -6,6 +6,6 @@ from .artifacts import DebugArtifacts from .circuit import Circuit from .client import Client from .compiler import Compiler, EncryptionStatus -from .configuration import Configuration +from .configuration import DEFAULT_GLOBAL_P_ERROR, DEFAULT_P_ERROR, Configuration from .server import Server from .specs import ClientSpecs diff --git a/concrete/numpy/compilation/configuration.py b/concrete/numpy/compilation/configuration.py index 98763b5a4..6b9fa4182 100644 --- a/concrete/numpy/compilation/configuration.py +++ b/concrete/numpy/compilation/configuration.py @@ -6,6 +6,9 @@ from copy import deepcopy from pathlib import Path from typing import Optional, Union, get_type_hints +DEFAULT_P_ERROR = None +DEFAULT_GLOBAL_P_ERROR = 1 / 100_000 + class Configuration: """ @@ -70,7 +73,7 @@ class Configuration: auto_parallelize: bool = False, jit: bool = False, p_error: Optional[float] = None, - global_p_error: Optional[float] = (1 / 100_000), + global_p_error: Optional[float] = None, auto_adjust_rounders: bool = False, ): self.verbose = verbose diff --git a/concrete/numpy/compilation/server.py b/concrete/numpy/compilation/server.py index f7c78e88b..e9313d1c8 100644 --- a/concrete/numpy/compilation/server.py +++ b/concrete/numpy/compilation/server.py @@ -23,7 +23,7 @@ from concrete.compiler import ( ) from ..internal.utils import assert_that -from .configuration import Configuration +from .configuration import DEFAULT_GLOBAL_P_ERROR, DEFAULT_P_ERROR, Configuration from .specs import ClientSpecs @@ -110,6 +110,17 @@ class Server: options.set_global_p_error(1.0) options.set_p_error(configuration.p_error) + else: # pragma: no cover + if DEFAULT_GLOBAL_P_ERROR is not None: + options.set_global_p_error(DEFAULT_GLOBAL_P_ERROR) + else: + options.set_global_p_error(1.0) + + if DEFAULT_P_ERROR is not None: + options.set_p_error(DEFAULT_P_ERROR) + else: + options.set_p_error(1.0) + show_optimizer = ( configuration.show_optimizer if configuration.show_optimizer is not None diff --git a/docs/getting-started/exactness.md b/docs/getting-started/exactness.md index d1ef5d881..18d6afe9e 100644 --- a/docs/getting-started/exactness.md +++ b/docs/getting-started/exactness.md @@ -18,7 +18,7 @@ However, if you set `global_p_error` to `0.01`, the whole circuit will have 1% p If you set both of them, both will be satisfied. Essentially, the stricter one will be used. -By default, `p_error` is set to `None` and `global_p_error` is set to `1 / 100_000`. Feel free to play with these configuration options to pick the one best suited for your needs! For example, in some machine learning use cases, off-by-one or off-by-two errors doesn't affect the result much, in such cases `p_error` could be set to increase performance without losing accuracy. +By default, both `p_error` and `global_p_error` is set to `None`, which results in `global_p_error` of `1 / 100_000` being used. Feel free to play with these configuration options to pick the one best suited for your needs! For example, in some machine learning use cases, off-by-one or off-by-two errors doesn't affect the result much, in such cases `p_error` could be set to increase performance without losing accuracy. See [How to Configure](../howto/configure.md) to learn how you can set a custom `p_error` and/or `global_p_error`. diff --git a/docs/howto/configure.md b/docs/howto/configure.md index 3e8ddc69d..2f3216f5f 100644 --- a/docs/howto/configure.md +++ b/docs/howto/configure.md @@ -74,10 +74,10 @@ Additional kwarg to `compile` function have higher precedence. So if you set an * Whether to adjust rounders automatically. * **p_error**: Optional[float] = None - * Error probability for individual table lookups. If set, all table lookups will have the probability of non-exact result smaller than the set value. + * Error probability for individual table lookups. If set, all table lookups will have the probability of non-exact result smaller than the set value. See [Exactness](../getting-started/exactness.md) to learn more. -* **global_p_error**: Optional[float] = (1 / 100_000) - * Global error probability for the whole circuit. If set, the whole circuit will have the probability of non-exact result smaller than the set value. +* **global_p_error**: Optional[float] = None + * Global error probability for the whole circuit. If set, the whole circuit will have the probability of non-exact result smaller than the set value. See [Exactness](../getting-started/exactness.md) to learn more. * **jit**: bool = False * Whether to use JIT compilation.