Skip to content
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ wheels/
tests/resources/*/output_reports
tests/resources/*/output_kdic
tests/resources/dictionary/copy_output_kdic
tests/resources/scenario_generation/system_settings/output
tests/resources/scenario_generation/api/*/output
tests/resources/scenario_generation/data_path_deprecation/*/output
tests/resources/scenario_generation/general_options/output
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@

## Unreleased

### Added
- (`core`) The `set_default_max_cores`, `set_default_memory_limit_mb` and
`set_default_temp_dir` functions, and their `get_default_*` counterparts, to
set process-wide defaults for the maximum number of CPU cores, the memory
limit and the temporary directory of Khiops Core API calls.

### Fixed
- (`core`) The `max_cores` parameter (and `n_cores` in the `sklearn` estimators)
now applies to the call it is passed to only: it no longer replaces the
current runner for the rest of the process.
- (General) Detection of non-activated Windows Conda installations using the
conda-forge Python 3.15 package layout.

Expand Down
65 changes: 59 additions & 6 deletions doc/site/notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,20 @@ The functions in the [khiops.core.api][] have the following common parameters.
no file.

`max_cores` : int, optional
: Maximum number of cores for Khiops executions. If not set, then Khiops uses all available CPU
cores in the system.
: Maximum number of cores for Khiops executions. If not set, then the value set via
[set_default_max_cores][khiops.core.api.set_default_max_cores] applies;
otherwise, Khiops uses all available CPU cores in the system.

`memory_limit_mb` : int, optional
: Maximum amount of memory (in MB) for Khiops executions. If not set, then Khiops uses all
available system memory.
: Maximum amount of memory (in MB) for Khiops executions. If not set, then the
value set via
[set_default_memory_limit_mb][khiops.core.api.set_default_memory_limit_mb]
applies; otherwise, Khiops uses all available system memory.

`temp_dir` : str, default `""`
: Temporary directory for Khiops executions. If set to `""`, then Khiops uses the system's
temporary directory.
: Temporary directory for Khiops executions. If set to `""`, then the value set via
[set_default_temp_dir][khiops.core.api.set_default_temp_dir] applies;
otherwise, Khiops uses the system's temporary directory.

`scenario_prologue` : str, default `""`
: Prologue to prepend to all Khiops execution scenarios.
Expand All @@ -61,6 +65,55 @@ The functions in the [khiops.core.api][] have the following common parameters.
: If `True` the internal scenario generated by Khiops will force characters such as accentuated
ones to be decoded with the UTF8->ANSI khiops transformation.

#### Process-wide System-parameter Defaults { #core-api-global-system-params }

The maximum number of CPU cores, the memory limit and the temporary directory of Khiops
executions can be set once for the remainder of the Python process, instead of in each call:

- [set_default_max_cores][khiops.core.api.set_default_max_cores] and
[get_default_max_cores][khiops.core.api.get_default_max_cores] configure and query
the maximum number of CPU cores.
- [set_default_memory_limit_mb][khiops.core.api.set_default_memory_limit_mb] and
[get_default_memory_limit_mb][khiops.core.api.get_default_memory_limit_mb]
configure and query the maximum amount of memory in megabytes.
- [set_default_temp_dir][khiops.core.api.set_default_temp_dir] and
[get_default_temp_dir][khiops.core.api.get_default_temp_dir] configure and query
the Khiops temporary directory.

The effective value of each parameter is, by decreasing priority:

1. The argument of the Core API call (`max_cores`, `memory_limit_mb`,
`temp_dir`), or the `n_cores` argument of the `khiops.sklearn` estimators. It
applies to that call only: the defaults are neither modified nor lost.
2. The default set with the `set_default_*` function.
3. Khiops' own defaults: all available CPU cores and memory on the host system,
and the system's temporary directory. Once a default has been set, it applies
again only after the relevant `set_default_*` function is called without
argument (or with `None`).

The numeric setters accept an optional positive `int`, the temporary-directory
setter an optional non-empty `str`; otherwise `TypeError` or `ValueError` is
raised and nothing changes. A call without argument (or with `None`) disables
only that default: the parameter gets back the value it had before the Python
process was launched, that is, Khiops' own default. The getters return an `int`
or a `str`, or `None` if no default is set.

!!! note
- These functions do not modify `os.environ`. They install a new local
runner that runs in a copy of the process environment taken when
`khiops.core` was imported: later changes to `os.environ` are not seen by
that runner. The runner keeps the `samples_dir` and `root_temp_dir` of the
runner it replaces.
- If the current runner is not local (e.g. Docker), the value is only stored
(it applies to the next local runner built by a setter) and a warning is
emitted. Install such a runner with `set_runner` before calling these
functions.
- Installing a runner with `set_runner` discards the defaults applied so far
(the getters keep reporting them). The next call of any setter applies all
of them again.
- The temporary-directory default applies to the temporary files of Khiops,
not to those that the library itself creates (see `root_temp_dir`).

### Input Types { #core-api-input-types }

The types accepted in most methods and classes of [khiops.core][] are flexible:
Expand Down
Loading
Loading