Skip to content

Set the KHIOPS_PROC_NUMBER env var for each training run using the value of max_cores - #623

Open
tramora wants to merge 1 commit into
mainfrom
max-cores-allocated
Open

tramora wants to merge 1 commit into
mainfrom
max-cores-allocated

Conversation

@tramora

@tramora tramora commented Sep 20, 2026 •

Copy link
Copy Markdown
Collaborator
  • the allocated number of CPU cores can never be greater than the value of max_cores

Fixes #585


Implementation details :


TODO Before Asking for a Review

  • Rebase your branch to the latest version of main (or main-v10)
  • Make sure all CI workflows are green
  • When adding a public feature/fix: Update the Unreleased section of CHANGELOG.md (no date)
  • Self-Review: Review "Files Changed" tab and fix any problems you find
  • API Docs (only if there are changes in docstrings, markdown files or samples):
    • Check the docs build without warning: see the log of the API Docs workflow
    • Check that your changes render well in HTML: download the API Docs artifact and open index.html
    • If there are any problems it is faster to iterate by building locally the API Docs

@tramora
tramora force-pushed the max-cores-allocated branch from b2f355a to e532ce2 Compare September 22, 2026 09:53
@tramora
tramora requested a review from popescu-v September 22, 2026 09:54
Comment thread khiops/core/internals/runner.py Outdated
Comment thread tests/test_khiops_integrations.py Outdated

@popescu-v popescu-v left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comments.



def get_default_samples_dir(environment=None):
"""Returns the default samples directory

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document the environment parameter.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -946,8 +968,18 @@ class KhiopsLocalRunner(KhiopsRunner):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would document the environment in the class docstring, then the __init__ should only have "See class docstring" as its docstring (cf. AnalysisResults and other classes in khiops.core).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread khiops/core/internals/runner.py Outdated
def __init__(self, environment=None):
"""Initialize a local runner.

Parameters

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to the class docstring (see the comment above).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread khiops/core/api.py Outdated
Comment on lines +148 to +149
# Ensure the previous runner is a KhiopsLocalRunner
# to avoid overwriting a mocked runner

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mocked runners are test-specific objects. IMHO they should not be mentioned in test code. I would just state "Ensure KHIOPS_PROC_NUMBER is set on KhiopsLocalRunner instances". And, in order to make sure we are dealing with "KhiopsLocalRunner" and not its subclasses, we could do if type(get_runner()) == KhiopsLocalRunner IMHO.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amended

Comment thread khiops/core/api.py
# to avoid overwriting a mocked runner
if isinstance(get_runner(), KhiopsLocalRunner):
khiops_env = os.environ.copy()
# The max pre-allocated cpu cores must have the same value

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insert empty line before this comment.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread khiops/core/api.py Outdated
# Ensure the previous runner is a KhiopsLocalRunner
# to avoid overwriting a mocked runner
if isinstance(get_runner(), KhiopsLocalRunner):
khiops_env = os.environ.copy()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename khiops_env to something like task_environment to avoid confusion with the khiops_env script.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread tests/test_core.py
"kh_samples", "train_predictor_file_paths", "AnalysisResults.khj"
)
# The existing MockedRunnerContext class is not used here
# as it creates a new KhiopsLocalRunner instance that does not fit our needs

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment here, like: "# Patch KhiopsLocalRunner so that Khiops is not run"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread tests/test_core.py Outdated
target_variable="class",
analysis_report_file_path=report_file_path,
trace=True,
max_cores=17,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set to variable, like expected_max_cores rather than hard-coding it, so that the test is more readable (as it would reuse this variable).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@popescu-v popescu-v left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments.

…value of `max_cores`

- the pre-allocated number of CPU cores can never be greater than the value of `max_cores`
- the KhiopsLocalRunner accepts a 'private' local environment so that the `max_cores` value is valid only for the run
@tramora
tramora force-pushed the max-cores-allocated branch from 7e13e1b to 20aab02 Compare October 9, 2026 14:41
@tramora
tramora requested a review from popescu-v October 9, 2026 14:42

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use KHIOPS_PROC_NUMBER when max_cores is set

2 participants