Skip to content

Commit 65ba913

Browse files
committed
Run both Khiops and Khiops Coclustering with MPI
closes #380
1 parent 12c99a2 commit 65ba913

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

khiops/core/internals/runner.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,9 +1119,8 @@ def raw_run(self, tool_name, command_line_args=None, use_mpi=True, trace=False):
11191119
)
11201120

11211121
# Build command line arguments
1122-
# Nota: Khiops Coclustering is executed without MPI
11231122
khiops_process_args = []
1124-
if tool_name == "khiops" and use_mpi:
1123+
if use_mpi:
11251124
khiops_process_args += self._mpi_command_args
11261125
khiops_process_args += [self._tool_path(tool_name)]
11271126
if command_line_args:

tests/test_khiops_integrations.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
# which is available at https://spdx.org/licenses/BSD-3-Clause-Clear.html or #
55
# see the "LICENSE.md" file for more details. #
66
######################################################################################
7-
"""Tests for executing fit multiple times on multi-table data"""
7+
"""Various integration tests"""
88

9+
import contextlib
10+
import io
911
import os
1012
import platform
1113
import shutil
@@ -15,6 +17,7 @@
1517
import unittest
1618

1719
import khiops.core as kh
20+
import khiops.core.internals.filesystems as fs
1821
from khiops.core.exceptions import KhiopsEnvironmentError
1922
from khiops.core.internals.runner import KhiopsLocalRunner
2023
from khiops.extras.docker import KhiopsDockerRunner
@@ -208,6 +211,53 @@ def test_runner_environment_initialization(self):
208211

209212
self.assertEqual(env_khiops_api_mode, "true")
210213

214+
def test_khiops_and_khiops_coclustering_are_run_with_mpi(self):
215+
"""Test that MODL and MODL_Coclustering are run with MPI"""
216+
217+
# Get current runner
218+
runner = kh.get_runner()
219+
220+
# Get path to the Iris dataset
221+
iris_data_dir = fs.get_child_path(runner.samples_dir, "Iris")
222+
223+
quote = '"' if platform.system() == "Windows" else "'"
224+
225+
# Run Khiops through an API function and test its stdout
226+
with contextlib.redirect_stdout(io.StringIO()) as khiops_stdout:
227+
kh.check_database(
228+
fs.get_child_path(iris_data_dir, "Iris.kdic"),
229+
"Iris",
230+
fs.get_child_path(iris_data_dir, "Iris.txt"),
231+
trace=True,
232+
)
233+
expected_khiops_command = (
234+
f"{' '.join(runner.mpi_command_args)} {runner.khiops_path}"
235+
)
236+
self.assertTrue(
237+
expected_khiops_command in khiops_stdout.getvalue().replace(quote, "")
238+
)
239+
240+
# Run Khiops Coclustering through an API function and test its stdout
241+
with (
242+
contextlib.redirect_stdout(io.StringIO()) as khiops_coclustering_stdout,
243+
tempfile.TemporaryDirectory() as temp_dir,
244+
):
245+
kh.train_coclustering(
246+
fs.get_child_path(iris_data_dir, "Iris.kdic"),
247+
"Iris",
248+
fs.get_child_path(iris_data_dir, "Iris.txt"),
249+
["SepalLength", "PetalLength"],
250+
fs.get_child_path(temp_dir, "IrisCoclusteringResults.khcj"),
251+
trace=True,
252+
)
253+
expected_khiops_coclustering_command = (
254+
f"{' '.join(runner.mpi_command_args)} {runner.khiops_coclustering_path}"
255+
)
256+
self.assertTrue(
257+
expected_khiops_coclustering_command
258+
in khiops_coclustering_stdout.getvalue().replace(quote, "")
259+
)
260+
211261

212262
class KhiopsMultitableFitTests(unittest.TestCase):
213263
"""Test if Khiops estimator can be fitted on multi-table data"""

0 commit comments

Comments
 (0)