scalib.config#
SCALib runtime configuration.
The configuration is fetched from different sources, with the following priority. The highest-priority is the local configuration enabled with the Config context manager (which can be nested, and follows thread/async context). If no such local configuration is activated, the default configuration is used. This configuration has default startup values (which may depend on environment variables) that can be changed with the default_config function.
Configurable Behaviors#
Progress bars#
By default, a progress bar is shown for all SCALlib operations if the output (stderr) is a terminal. The printing of progress bars can be disabled with the show_progress argument of Config.
Thread pools#
All computationally-heavy operations of SCALib are run on a thread pool. Multiple thread pools can be used simultaneously, although using only the default thread pool should be enough for most applications.
The default thread pool can be configured through the default Config or using value of the environment variable SCALIB_NUM_THREADS, e.g.:
SCALIB_NUM_THREADS=8 python3 XXX.py
If SCALIB_NUM_THREADS is not set, reasonable default for the typical use of SCALib is taken (it is currently the one given here), but might not be optimal for your workload.
Thread pools can be used locally in place of the default thread pool by enabling a local config using Config as a context manager. When initializing a Config, a ThreadPool can be provided through the threadpool argument, or a new ThreadPool is created if the n_threads argument is provided. If neither of these arguements is provided, the currently active thread pool is used.
Example
>>> from scalib.config import default_config, Config
>>> # Set the default ThreadPool to 10 threads and do not show progress bars.
>>> default_config(n_threads=10, show_progress=False)
>>> # As an exception, the following computations run on 5 threads, with progress bars.
>>> # (NB: enabling progress is needed as Config inherits the current context by default.)
>>> with Config(n_threads=5, show_progress=False).activate():
... # Do some computations with SCALib...
... pass
>>> # One can also re-use a Config.
>>> # This is convenient and also allows sending jobs from multiple python threads to a single thread pool.
>>> config = Config(n_threads=5)
>>> with config.activate():
... pass
>>> with config.activate():
... pass
Reference#
SCALib configuration. |
|
Configure the default Config. |
|
SCALib threadpool. |