Skip to content

khiops.core.internals.runner

Submodule of khiops.core.internals

Classes implementing Khiops Python' backend runners

CLASS DESCRIPTION
KhiopsRunner

Abstract Khiops Python runner to be re-implemented

KhiopsLocalRunner

Implementation of a local Khiops runner

FUNCTION DESCRIPTION
get_default_samples_dir

Returns the default samples directory

set_runner

Sets the current KhiopsRunner of the module

get_runner

Returns the current KhiopsRunner of the module

Classes

KhiopsRunner()

Bases: ABC

Abstract Khiops Python runner to be re-implemented

See class docstring

METHOD DESCRIPTION
create_temp_file

Creates a unique temporary file in the runner's root temporary directory

create_temp_dir

Creates a unique directory in the runner's root temporary directory

print_status

Prints the status of the runner to stdout

run

Runs a Khiops Task

ATTRIBUTE DESCRIPTION
root_temp_dir

str: The runner's temporary directory

samples_dir

str: Location of the Khiops' sample datasets directory

khiops_version

KhiopsVersion: The version of the Khiops backend of this runner

Attributes

root_temp_dir property writable

str: The runner's temporary directory

The temporary scenarios/templates and dictionary files created by the Khiops Python library are stored here.

Default value: - Windows: %TEMP%\khiops\python - Linux: $TMP/khiops/python

When set to a local path it tries to create the specified directory if it doesn't exist.

RAISES DESCRIPTION
KhiopsEnvironmentError

If set to a local path: if it is a file or if it does not have +rwx permissions.

samples_dir property writable

str: Location of the Khiops' sample datasets directory

Can be an URI.

khiops_version property

KhiopsVersion: The version of the Khiops backend of this runner

Methods:

create_temp_file(prefix, suffix)

Creates a unique temporary file in the runner's root temporary directory

Note

For remote filesystems no actual file is created, just a (highly probable) unique path is returned.

PARAMETER DESCRIPTION
prefix

Prefix for the file's name.

TYPE: str

suffix

Suffix for the file's name.

TYPE: str

RETURNS DESCRIPTION
str

A unique path within the root temporary directory. The file is created only in the case of a local filesystem.

create_temp_dir(prefix)

Creates a unique directory in the runner's root temporary directory

PARAMETER DESCRIPTION
prefix

Prefix for the directory's name.

TYPE: str

RETURNS DESCRIPTION
str

A unique directory path within the root temporary directory. The directory is created only in the case of a local filesystem.

print_status()

Prints the status of the runner to stdout

run(task, task_args, command_line_options=None, trace=False, system_settings=None, stdout_file_path='', stderr_file_path='', force_ansi_scenario=False, **kwargs)

Runs a Khiops Task

PARAMETER DESCRIPTION
task

Khiops task to be run.

TYPE: KhiopsTask

task_args

Arguments for the task.

TYPE: dict

command_line_options

Command line options for all tasks. If not set the default values are used. See the CommandLineOptions for more information.

TYPE: CommandLineOptions DEFAULT: None

trace

If True prints the command line executed of the process and does not delete any temporary files created.

TYPE: bool DEFAULT: `False`

system_settings

Advanced: System settings for all tasks. See the SystemSettings class for more information.

TYPE: SystemSettings DEFAULT: None

stdout_file_path

Advanced Path to a file where the Khiops process writes its stdout stream. Normally Khiops should not write to this stream but MPI, filesystems plugins or debug versions may do it. The stream is captured with a UTF-8 encoding and replacing encoding errors. If equal to "" then it writes no file.

TYPE: str DEFAULT: ""

stderr_file_path

Advanced Path to a file where the Khiops process writes its stderr stream. Normally Khiops should not write to this stream but MPI, filesystems plugins or debug versions may do it. The stream is captured with a UTF-8 encoding and replacing encoding errors. If equal to "" then it writes no file.

TYPE: str DEFAULT: ""

force_ansi_scenario

Advanced: If True the internal scenario generated by Khiops will force characters such as accentuated ones to be decoded with the UTF8->ANSI khiops transformation.

TYPE: bool DEFAULT: `False`

RAISES DESCRIPTION
ValueError
  • Unknown keyword argument
  • Files or executable not found
  • Errors in the execution of the Khiops tool
TypeError
  • Invalid type of a keyword argument
  • When the search/replace pairs are not strings

KhiopsLocalRunner()

Bases: KhiopsRunner

Implementation of a local Khiops runner

Requires either:

  • This library installed through Conda and run from a Conda environment, or
  • the khiops-core Linux native library installed on the local machine, or
  • the Windows Khiops desktop application installed on the local machine

Samples directory settings

Default values for the samples_dir attribute:

  • The value of the KHIOPS_SAMPLES_DIR environment variable (path to the Khiops sample datasets directory).
  • Otherwise:

  • Windows:

    • %PUBLIC%\khiops_data\samples% if %PUBLIC% is defined
    • %USERPROFILE%\khiops_data\samples% otherwise
  • Linux and macOS:

    • $HOME/khiops_data/samples
METHOD DESCRIPTION
raw_run

Execute a Khiops tool with given command line arguments

ATTRIBUTE DESCRIPTION
khiops_path

str: Path to the MODL* Khiops binary

khiops_coclustering_path

str: Path to the MODL_Coclustering Khiops Coclustering binary

Attributes

khiops_path property writable

str: Path to the MODL* Khiops binary

Set by the khiops_env script from the khiops-core package.

khiops_coclustering_path property writable

str: Path to the MODL_Coclustering Khiops Coclustering binary

Set by the khiops_env script from the khiops-core package.

Methods:

raw_run(tool_name, command_line_args=None, use_mpi=True, trace=False)

Execute a Khiops tool with given command line arguments

PARAMETER DESCRIPTION
tool_name

Name of the tool to execute.

TYPE: (khiops, khiops_coclustering) DEFAULT: "khiops"

command_line_args

Command line arguments of Khiops.

TYPE: list of str DEFAULT: None

use_mpi

Whether to execute the application with MPI

TYPE: bool DEFAULT: True

trace

If True print the trace of the process.

TYPE: bool DEFAULT: False

Examples:

>>> raw_run("khiops", ["-b", "-i" , "scenario._kh"])

is equivalent to execute in a shell:

> khiops -b -i scenario._kh

Functions:

get_default_samples_dir()

Returns the default samples directory

The default samples directory is computed according to the following priorities: - all systems: KHIOPS_SAMPLES_DIR/khiops_data/samples if set - Windows: - %PUBLIC%\khiops_data\samples if %PUBLIC% is defined - %USERPROFILE%\khiops_data\samples otherwise - Linux/macOS: $HOME/khiops_data/samples

set_runner(runner)

Sets the current KhiopsRunner of the module

get_runner()

Returns the current KhiopsRunner of the module

RETURNS DESCRIPTION
KhiopsRunner

The current Khiops Python runner of the module.