Skip to content

[GeoMechanicsApplication] Reuse Python script to run multiple stages#13550

Merged
avdg81 merged 16 commits intomasterfrom
geo/reuse-run-multiple-stages
Jun 23, 2025
Merged

[GeoMechanicsApplication] Reuse Python script to run multiple stages#13550
avdg81 merged 16 commits intomasterfrom
geo/reuse-run-multiple-stages

Conversation

@avdg81
Copy link
Contributor

@avdg81 avdg81 commented Jun 23, 2025

📝 Description
The integration tests that called run_stages from the test_helper.py script now use the cleaned up Python script run_multiple_stages.py.

🆕 Changelog
Changes include:

  • Removed functions run_stages, get_stages, get_separated_directory_names, and get_separated_stages from test_helper.py. Their usages have been replaced by run_stages from run_multiple_stages.py.
  • Added a function that changes the present working directory to the given path as long as the corresponding context has not been left.
  • Removed empty setUp and tearDown methods of the modified integration tests, since doing nothing is the default behavior. Thus no overrides are needed.
  • The run_stages function from run_multiple_stages.py now returns a list of GeoMechanicsAnalysis instances, just like the replaced run_stages function from test_helper.py did.
  • Removed a few empty .mdpa files and used "input_type": "use_input_model_part" to indicate that no model files need to be read for those stages.
  • Some more test cases now read the output files to check the obtained results. The reason is that we can't use the database for any time step except for the last one.

avdg81 added 8 commits June 22, 2025 11:16
- Added a context manager that sets the current working directory in the present context.
- Only read the `ProjectParameters.json` file when we are about to run that stage.
- Don't let the Python script that runs multiple stages modify the system's path.
- The 1D consolidation test now reuses the general run multiple stages function.
All tests that used to call `run_stages` from `test_helper.py` now call `run_stages` from `run_multiple_stages.py`. In this way, we have removed some duplicated code.
After running the geomechanics analysis stages, return a list of run stages.
Prefer to use the Python script that runs multiple analysis stages.
Rather use `"input_type": "use_input_model_part"`, since the model did not change over the stages.
That required reading the analysis results from the output files.
This function was no longer used.
@avdg81 avdg81 requested review from WPK4FEM and rfaasse June 23, 2025 07:30
@avdg81 avdg81 self-assigned this Jun 23, 2025
@avdg81 avdg81 added the Cleanup label Jun 23, 2025
@avdg81 avdg81 requested a review from a team as a code owner June 23, 2025 07:30
@avdg81 avdg81 added the GeoMechanics Issues related to the GeoMechanicsApplication label Jun 23, 2025
@avdg81 avdg81 requested review from mcgicjn2 and removed request for rfaasse June 23, 2025 08:21
mcgicjn2
mcgicjn2 previously approved these changes Jun 23, 2025
Copy link
Contributor

@mcgicjn2 mcgicjn2 left a comment

Choose a reason for hiding this comment

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

This appears to do as expected and I like some of the improvements.

@github-project-automation github-project-automation bot moved this from In progress to Reviewer approved in GeoMechanicsApplication (Deltares) Jun 23, 2025
Copy link
Contributor

@WPK4FEM WPK4FEM left a comment

Choose a reason for hiding this comment

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

Thank you for the clean up. Using context_managers.py makes the behaviour of the test suite more predictable as it solves the directory switching issues. I commented most on the changes in the functional part, the changes in the tests themselves as clear to me and a direct and predictable consequence of the changes in functionality.

import KratosMultiphysics.GeoMechanicsApplication.context_managers as context_managers


def run_stages(project_path, n_stages):
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice that at some point n_stages becomes an optional argument, such that on omission all stages present are executed. The n_stages argument could then be used to execute the first n stages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Also, I can imagine that at some point we'd like to have the option to explicitly specify a set of filenames or a different filename pattern. But, indeed, such extensions need a bit more thought before attempting to implement them.

@avdg81 avdg81 requested a review from WPK4FEM June 23, 2025 13:33
@avdg81 avdg81 merged commit 57545b2 into master Jun 23, 2025
11 checks passed
@avdg81 avdg81 deleted the geo/reuse-run-multiple-stages branch June 23, 2025 18:00
@github-project-automation github-project-automation bot moved this from Reviewer approved to Done in GeoMechanicsApplication (Deltares) Jun 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Cleanup GeoMechanics Issues related to the GeoMechanicsApplication

Development

Successfully merging this pull request may close these issues.

3 participants