Skip to content

Commit 294374b

Browse files
authored
Merge pull request #507 from KhiopsML/506-fix-home-for-openmpi5
Ensure HOME is always set when running khiops core with OpenMPI 5+
2 parents 6aea158 + 79f5d20 commit 294374b

File tree

8 files changed

+254
-36
lines changed

8 files changed

+254
-36
lines changed

.github/workflows/dev-docker.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
name: Dev Docker
33
env:
4-
DEFAULT_KHIOPS_REVISION: 11.0.0-b.0
4+
DEFAULT_KHIOPS_REVISION: 11.0.0-rc.1
55
DEFAULT_IMAGE_INCREMENT: 0
66
DEFAULT_SERVER_REVISION: main
77
DEFAULT_PYTHON_VERSIONS: 3.8 3.9 3.10 3.11 3.12 3.13 3.14
@@ -14,7 +14,7 @@ on:
1414
inputs:
1515
khiops-revision:
1616
type: string
17-
default: 11.0.0-b.0
17+
default: 11.0.0-rc.1
1818
description: Khiops Revision
1919
image-increment:
2020
type: number
@@ -53,7 +53,7 @@ jobs:
5353
strategy:
5454
fail-fast: false
5555
matrix:
56-
khiopsdev-os: [ubuntu22.04, rocky8, rocky9]
56+
khiopsdev-os: [ubuntu22.04, rocky8, rocky9, debian13]
5757
permissions:
5858
packages: write # to write in the Github package registry
5959
steps:

.github/workflows/pip.yml

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
default: 11.0.0
1313
description: khiops-samples repo revision
1414
image-tag:
15-
default: 11.0.0-b.0.0
15+
default: 11.0.0-rc.1.0
1616
description: Development Docker Image Tag
1717
pypi-target:
1818
type: choice
@@ -65,13 +65,13 @@ jobs:
6565
strategy:
6666
fail-fast: false
6767
matrix:
68-
container: [ubuntu22.04, rocky9]
68+
container: [ubuntu22.04, rocky9, debian13]
6969
container:
7070
# 'latest' default image tag cannot be set as an environment variable,
7171
# because the `env` context is only accessible at the step level;
7272
# hence, it is hard-coded
7373
image: |-
74-
ghcr.io/khiopsml/khiops-python/khiopspydev-${{ matrix.container }}:${{ inputs.image-tag || '11.0.0-b.0.0' }}
74+
ghcr.io/khiopsml/khiops-python/khiopspydev-${{ matrix.container }}:${{ inputs.image-tag || '11.0.0-rc.1.0' }}
7575
steps:
7676
- name: Set parameters as env
7777
run: |
@@ -89,28 +89,45 @@ jobs:
8989
with:
9090
name: pip-package
9191
- name: Install package
92+
shell: bash
9293
run: |
9394
# Allow Pip to write to its cache
9495
mkdir -p /github/home/.cache/pip
9596
chown -R $(whoami) /github/home/.cache/pip
9697
# Install the Khiops Python library
98+
99+
# A virtual env is mandatory under debian
100+
if [[ "${{ matrix.container }}" == "debian13" ]]; then
101+
python -m venv khiops-debian-venv
102+
source khiops-debian-venv/bin/activate
103+
fi
97104
pip install --upgrade pip
98105
pip install $(ls khiops*.tar.gz)
106+
if [[ "${{ matrix.container }}" == "debian13" ]]; then
107+
deactivate
108+
fi
99109
- name: Run tests
100110
env:
101111
KHIOPS_SAMPLES_DIR: ${{ github.workspace }}/khiops-samples
102112
# Force > 2 CPU cores to launch mpiexec
103113
KHIOPS_PROC_NUMBER: 4
104-
# Oversubscribe for MPI 4.x
114+
# Oversubscribe for Open MPI 4.x
105115
rmaps_base_oversubscribe: true
106-
# Oversubscribe for MPI > 4.x
107116
OMPI_MCA_rmaps_base_oversubscribe: true
117+
# Oversubscribe for Open MPI >= 5
118+
PRTE_MCA_rmaps_default_mapping_policy: :oversubscribe
119+
shell: bash
108120
run: |-
109121
# Make sure MPI support is not loaded through env modules
110122
# Note: As the Docker container's shell is non-interactive, environment
111123
# modules are currently not initializing the shell anyway
112124
if [ -n "$MODULESHOME" ]; then module unload mpi; fi
113125
126+
# A virtual env is mandatory under debian
127+
if [[ "${{ matrix.container }}" == "debian13" ]]; then
128+
source khiops-debian-venv/bin/activate
129+
fi
130+
114131
# Print khiops installation status
115132
kh-status
116133
@@ -124,6 +141,9 @@ jobs:
124141
# The MPI command is not always named mpiexec, but can be orterun etc
125142
# (as given by khiops_env)
126143
kh-status | grep "MPI command" | grep -vwq "<empty>"
144+
if [[ "${{ matrix.container }}" == "debian13" ]]; then
145+
deactivate
146+
fi
127147
- name: Test package / Git tag version coherence
128148
shell: bash
129149
if: github.ref_type == 'tag'

.github/workflows/tests.yml

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
default: 11.0.0
1111
description: Git Tag/Branch/Commit for the khiops-samples Repo
1212
image-tag:
13-
default: 11.0.0-b.0.1
13+
default: 11.0.0-rc.1.0
1414
description: Development Docker Image Tag
1515
khiops-desktop-revision:
1616
default: 11.0.0-b.0
@@ -37,13 +37,13 @@ jobs:
3737
strategy:
3838
fail-fast: false
3939
matrix:
40-
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
40+
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
4141
container:
4242
# 'latest' default image tag cannot be set as an environment variable,
4343
# because the `env` context is only accessible at the step level;
4444
# hence, it is hard-coded
4545
image: |-
46-
ghcr.io/khiopsml/khiops-python/khiopspydev-ubuntu22.04:${{ inputs.image-tag || '11.0.0-b.0.1' }}
46+
ghcr.io/khiopsml/khiops-python/khiopspydev-ubuntu22.04:${{ inputs.image-tag || '11.0.0-rc.1.0' }}
4747
credentials:
4848
username: ${{ github.actor }}
4949
password: ${{ secrets.GITHUB_TOKEN }}
@@ -175,10 +175,11 @@ jobs:
175175
KHIOPS_RUNNER_SERVICE_PATH: /scripts/run_service.sh
176176
# Force > 2 CPU cores to launch mpiexec
177177
KHIOPS_PROC_NUMBER: 4
178-
# Oversubscribe for MPI 4.x
178+
# Oversubscribe for Open MPI 4.x
179179
rmaps_base_oversubscribe: true
180-
# Oversubscribe for MPI > 4.x
181180
OMPI_MCA_rmaps_base_oversubscribe: true
181+
# Oversubscribe for Open MPI >= 5
182+
PRTE_MCA_rmaps_default_mapping_policy: :oversubscribe
182183
# Var for tests with S3
183184
no_proxy: localhost
184185
run: |
@@ -326,14 +327,14 @@ jobs:
326327
strategy:
327328
fail-fast: false
328329
matrix:
329-
container: [ubuntu22.04, rocky8, rocky9]
330+
container: [ubuntu22.04, rocky8, rocky9, debian13]
330331
runs-on: ubuntu-latest
331332
container:
332333
# 'latest' default image tag cannot be set as an environment variable,
333334
# because the `env` context is only accessible at the step level;
334335
# hence, it is hard-coded
335336
image: |-
336-
ghcr.io/khiopsml/khiops-python/khiopspydev-${{ matrix.container }}:${{ inputs.image-tag || '11.0.0-b.0.1' }}
337+
ghcr.io/khiopsml/khiops-python/khiopspydev-${{ matrix.container }}:${{ inputs.image-tag || '11.0.0-rc.1.0' }}
337338
credentials:
338339
username: ${{ github.actor }}
339340
password: ${{ secrets.GITHUB_TOKEN }}
@@ -357,28 +358,49 @@ jobs:
357358
token: ${{ secrets.GITHUB_TOKEN }}
358359
path: khiops-samples
359360
- name: Install khiops-python dev dependencies
361+
shell: bash
360362
run: |
361363
# The following git command is required,
362364
# as the Git repository is in a directory the current user does not own,
363365
# Python versioneer fails to compute the current version correctly otherwise
364366
git config --global --add safe.directory $(realpath .)
367+
368+
# A virtual env is mandatory under debian
369+
if [[ "${{ matrix.container }}" == "debian13" ]]; then
370+
python -m venv khiops-debian-venv
371+
source khiops-debian-venv/bin/activate
372+
fi
373+
365374
# Install tomli for Python < 3.11
366375
pip install tomli
367376
python scripts/extract_dependencies_from_pyproject_toml.py -f "pyproject.toml" > requires.txt
368377
pip install `cat requires.txt`
369378
rm -f requires.txt
379+
if [[ "${{ matrix.container }}" == "debian13" ]]; then
380+
deactivate
381+
fi
370382
- name: Setup and Install Test Requirements
371-
run: |
383+
shell: bash
384+
run: |-
385+
# A virtual env is mandatory under debian
386+
if [[ "${{ matrix.container }}" == "debian13" ]]; then
387+
source khiops-debian-venv/bin/activate
388+
fi
372389
pip install -r test-requirements.txt
390+
if [[ "${{ matrix.container }}" == "debian13" ]]; then
391+
deactivate
392+
fi
373393
- name: Test Khiops Integration
374394
env:
375395
# Force > 2 CPU cores to launch mpiexec
376396
KHIOPS_PROC_NUMBER: 4
377397
KHIOPS_SAMPLES_DIR: ${{ github.workspace }}/khiops-samples
378-
# Oversubscribe for MPI 4.x
398+
# Oversubscribe for Open MPI 4.x
379399
rmaps_base_oversubscribe: true
380-
# Oversubscribe for MPI > 4.x
381400
OMPI_MCA_rmaps_base_oversubscribe: true
401+
# Oversubscribe for Open MPI >= 5
402+
PRTE_MCA_rmaps_default_mapping_policy: :oversubscribe
403+
shell: bash
382404
run: |-
383405
# Reset the default 'exit-on-error' mode of the bash shell in Github actions
384406
# so that the return code can be evaluated if needed
@@ -389,6 +411,11 @@ jobs:
389411
# modules are currently not initializing the shell anyway
390412
if [ -n "$MODULESHOME" ]; then module unload mpi; fi
391413
414+
# A virtual env is mandatory under debian
415+
if [[ "${{ matrix.container }}" == "debian13" ]]; then
416+
source khiops-debian-venv/bin/activate
417+
fi
418+
392419
# Print status
393420
python -c \
394421
"import sys; import khiops.core as kh; return_code = kh.get_runner().print_status(); sys.exit(return_code)"
@@ -404,3 +431,6 @@ jobs:
404431
405432
# Execute Khiops sample (train and deploy model), which uses MPI
406433
python -m khiops.samples.samples -i deploy_model -e
434+
if [[ "${{ matrix.container }}" == "debian13" ]]; then
435+
deactivate
436+
fi

khiops/core/internals/runner.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,22 @@ def _get_current_library_installer():
327327
return "unknown"
328328

329329

330+
def _build_khiops_process_environment():
331+
"""Build a specific environment used for the execution of khiops in a process
332+
333+
This environment can be modified freely without interfering
334+
with the global one.
335+
"""
336+
khiops_env = os.environ.copy()
337+
338+
# Ensure HOME is always set for OpenMPI 5+
339+
# (using KHIOPS_MPI_HOME if it exists)
340+
khiops_env["HOME"] = os.path.pathsep.join(
341+
[khiops_env.get("KHIOPS_MPI_HOME", ""), khiops_env.get("HOME", "")]
342+
)
343+
return khiops_env
344+
345+
330346
class KhiopsRunner(ABC):
331347
"""Abstract Khiops Python runner to be re-implemented"""
332348

@@ -994,8 +1010,14 @@ def _initialize_khiops_environment(self):
9941010
var_value = ""
9951011
else:
9961012
continue
1013+
1014+
# Special var to export in order
1015+
# to prepend to or to set to HOME for OpenMPI 5+
1016+
# when running khiops core
1017+
if var_name == "KHIOPS_MPI_HOME":
1018+
os.environ["KHIOPS_MPI_HOME"] = var_value
9971019
# Set paths to Khiops binaries
998-
if var_name == "KHIOPS_PATH":
1020+
elif var_name == "KHIOPS_PATH":
9991021
self.khiops_path = var_value
10001022
os.environ["KHIOPS_PATH"] = var_value
10011023
elif var_name == "KHIOPS_COCLUSTERING_PATH":
@@ -1443,6 +1465,11 @@ def raw_run(self, tool_name, command_line_args=None, use_mpi=True, trace=False):
14431465
khiops_call += f" {quote}{arg}{quote}"
14441466
print(f"Khiops execution call: {khiops_call}")
14451467

1468+
# Build custom Khiops process environment
1469+
# which makes sure HOME is defined and set
1470+
# according to khiops_env's KHIOPS_MPI_HOME
1471+
khiops_env = _build_khiops_process_environment()
1472+
14461473
# Execute the process
14471474
with subprocess.Popen(
14481475
khiops_process_args,
@@ -1452,6 +1479,7 @@ def raw_run(self, tool_name, command_line_args=None, use_mpi=True, trace=False):
14521479
encoding="utf8",
14531480
errors="replace",
14541481
universal_newlines=True,
1482+
env=khiops_env,
14551483
) as khiops_process:
14561484
stdout, stderr = khiops_process.communicate()
14571485

0 commit comments

Comments
 (0)