diff --git a/CMakeLists.txt b/CMakeLists.txt index ef08ba51900..b2e015b12d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -525,6 +525,10 @@ if(MPI_FOUND) include (${CMAKE_CURRENT_SOURCE_DIR}/parallelUnitTests.cmake) endif() +if(OPM_ENABLE_PYTHON) + include (${CMAKE_CURRENT_SOURCE_DIR}/pythonIntegrationTests.cmake) +endif() + include(OpmBashCompletion) if (NOT BUILD_FLOW) diff --git a/python/test/ml/README.md b/python/integration_tests/ml/README.md similarity index 100% rename from python/test/ml/README.md rename to python/integration_tests/ml/README.md diff --git a/python/test/ml/__init__.py b/python/integration_tests/ml/__init__.py similarity index 100% rename from python/test/ml/__init__.py rename to python/integration_tests/ml/__init__.py diff --git a/python/test/ml/hybrid_newton/README.md b/python/integration_tests/ml/hybrid_newton/README.md similarity index 100% rename from python/test/ml/hybrid_newton/README.md rename to python/integration_tests/ml/hybrid_newton/README.md diff --git a/python/test/ml/hybrid_newton/__init__.py b/python/integration_tests/ml/hybrid_newton/__init__.py similarity index 100% rename from python/test/ml/hybrid_newton/__init__.py rename to python/integration_tests/ml/hybrid_newton/__init__.py diff --git a/python/test/ml/hybrid_newton/test_hybrid_newton.py b/python/integration_tests/ml/hybrid_newton/test_hybrid_newton.py similarity index 91% rename from python/test/ml/hybrid_newton/test_hybrid_newton.py rename to python/integration_tests/ml/hybrid_newton/test_hybrid_newton.py index e032683f05c..a4db6f64032 100644 --- a/python/test/ml/hybrid_newton/test_hybrid_newton.py +++ b/python/integration_tests/ml/hybrid_newton/test_hybrid_newton.py @@ -8,8 +8,7 @@ from .utils import collect_input_features, compute_output_vars, write_config, extract_newtit_from_file, extract_unrst_variables from .utils import (ABSOLUTE_CASES, RELATIVE_CASES, FEATURE_ENGINEERING_CASES, SCALING_CASES, MULTI_MODEL_CASES, ZERO_NEWTON_CASES, ALL_CASES) -from kerasify import export_model - +from opm.ml.ml_tools.kerasify import export_model class TestHybridNewton(unittest.TestCase): @classmethod @@ -24,27 +23,28 @@ def setUpClass(cls): cls.times = [] baseline_cmd = [ - "flow", + os.environ.get("FLOW_BINARY", default="flow"), str(cls.data_dir / cls.deck_file), "--output-extra-convergence-info=steps,iterations", "--newton-min-iterations=0", + "--output-dir=.", "--full-time-step-initially=true", ] - print("Running baseline simulation...") - subprocess.run(baseline_cmd, cwd=cls.data_dir, stdout=subprocess.DEVNULL, check=True) + print("Running baseline simulation... ") + subprocess.run(baseline_cmd, stdout=subprocess.DEVNULL, check=True) # Extract Newton iterations - cls.baseline_iters = extract_newtit_from_file(cls.data_dir / Path(cls.deck_file).stem) + cls.baseline_iters = extract_newtit_from_file(Path('.') / Path(cls.deck_file).stem) print(f"Baseline Newton iterations: {cls.baseline_iters}") # Extract fluid state from UNRST for all timesteps - cls.unrst, cls.times = extract_unrst_variables(cls.data_dir, cls.deck_file) + cls.unrst, cls.times = extract_unrst_variables(".", cls.deck_file) cls.rd_init["PERMX"] = [10**2] * len(cls.unrst["PRESSURE"][0]) cls.n_cells = len(cls.unrst["PRESSURE"][0]) def _run_cases(self, cases): - models_dir = self.data_dir / "models" + models_dir = Path('.') / "models" os.makedirs(models_dir, exist_ok=True) for case in cases: @@ -125,21 +125,22 @@ def _build_case_models(self, case, models_dir): def _run_hybrid_newton_test(self, json_path): """Run hybrid Newton via subprocess and extract Newton iterations.""" cmd = [ - "flow", + os.environ.get("FLOW_BINARY", default="flow"), str(self.data_dir / self.deck_file), f"--hy-ne-config-file={json_path}", "--use-hy-ne=true", "--output-extra-convergence-info=steps,iterations", "--newton-min-iterations=0", + "--output-dir=.", "--full-time-step-initially=true" ] print(f"Running hybrid Newton simulation with config {json_path}...") - subprocess.run(cmd, cwd=self.data_dir, + subprocess.run(cmd, stdout=subprocess.DEVNULL, check=True) - hybrid_iters = extract_newtit_from_file(self.data_dir / Path(self.deck_file).stem) + hybrid_iters = extract_newtit_from_file(Path('.') / Path(self.deck_file).stem) return hybrid_iters def test_absolute_cases(self): diff --git a/python/test/ml/hybrid_newton/utils.py b/python/integration_tests/ml/hybrid_newton/utils.py similarity index 100% rename from python/test/ml/hybrid_newton/utils.py rename to python/integration_tests/ml/hybrid_newton/utils.py diff --git a/pythonIntegrationTests.cmake b/pythonIntegrationTests.cmake new file mode 100644 index 00000000000..40d259e2e8a --- /dev/null +++ b/pythonIntegrationTests.cmake @@ -0,0 +1,20 @@ +file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/tests/integration/HybridNewton) + +add_test(NAME + HybridNewton + COMMAND + pytest ${PROJECT_SOURCE_DIR}/python/integration_tests/ml/hybrid_newton + WORKING_DIRECTORY + ${PROJECT_BINARY_DIR}/tests/integration/HybridNewton + ) +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.22) + set(modifications + "PYTHONPATH=path_list_append:${opm-common_DIR}/python" + "PYTHONPATH=path_list_append:${CMAKE_CURRENT_BINARY_DIR}/python" + "FLOW_BINARY=set:$" + ) + set_tests_properties(HybridNewton PROPERTIES + ENVIRONMENT_MODIFICATION + "${modifications}" + ) +endif()