core.internals.runner

Submodule of khiops.core.internals

Classes implementing Khiops Python’ backend runners

Functions

get_runner

Returns the current KhiopsRunner of the module

set_runner

Sets the current KhiopsRunner of the module

Classes

KhiopsLocalRunner

Implementation of a local Khiops runner

KhiopsRunner

Abstract Khiops Python runner to be re-implemented

class khiops.core.internals.runner.KhiopsLocalRunner

Bases: KhiopsRunner

Implementation of a local Khiops runner

Requires either:

  • This package installed through Conda and run from a Conda environment, or

  • the khiops-core Linux native package 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 it exists and is a directory

      • %USERPROFILE%\khiops_data\samples% otherwise

    • Linux and macOS:

      • $HOME/khiops_data/samples

property khiops_coclustering_path

str: Path to the MODL_Coclustering Khiops Coclustering binary

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

property khiops_path

str: Path to the MODL* Khiops binary

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

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

Execute a Khiops tool with given command line arguments

Parameters:
tool_name{“khiops”, “khiops_coclustering”}

Name of the tool to execute.

command_line_argslist of str, optional

Command line arguments of Khiops.

use_mpibool, optional

Whether to execute the application with MPI

tracebool, default False

If True print the trace of the process.

Examples

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

is equivalent to execute in a shell:

> khiops -b -i scenario._kh
class khiops.core.internals.runner.KhiopsRunner

Bases: ABC

Abstract Khiops Python runner to be re-implemented

create_temp_dir(prefix)

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

Parameters:
prefixstr

Prefix for the directory’s name.

Returns:
str

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

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.

Parameters:
prefixstr

Prefix for the file’s name.

suffixstr

Suffix for the file’s name.

Returns:
str

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

property khiops_version

KhiopsVersion: The version of the Khiops backend of this runner

print_status()

Prints the status of the runner to stdout

property root_temp_dir

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:
KhiopsEnvironmentError

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

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

Parameters:
taskKhiopsTask

Khiops task to be run.

task_argsdict

Arguments for the task.

command_line_optionsCommandLineOptions, optional

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

tracebool, default False

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

system_settingsSystemSettings, optional

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

stdout_file_pathstr, default “”

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.

stderr_file_pathstr, default “”

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.

force_ansi_scenariobool, default False

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.

Raises:
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

property samples_dir

str: Location of the Khiops’ sample datasets directory. May be an URL/URI

khiops.core.internals.runner.get_runner()

Returns the current KhiopsRunner of the module

Returns:
KhiopsRunner

The current Khiops Python runner of the module.

khiops.core.internals.runner.set_runner(runner)

Sets the current KhiopsRunner of the module