equinor / ert

ERT - Ensemble based Reservoir Tool - is designed for running ensembles of dynamical models such as reservoir models, in order to do sensitivity analysis and data assimilation. ERT supports data assimilation using the Ensemble Smoother (ES), Ensemble Smoother with Multiple Data Assimilation (ES-MDA) and Iterative Ensemble Smoother (IES).
https://ert.readthedocs.io/en/latest/
GNU General Public License v3.0
104 stars 107 forks source link

Investigate discrepancy of running unit and cli tests between py311 and py312 #9334

Closed xjules closed 1 day ago

xjules commented 4 days ago

It is apparent that Python 3.12 is much slower than Python 3.11 when it comes running the all tests. We should find out what's the main source of this slowness. Unit tests: Py311 is 3-4 minutes faster Cli tests: Py311 is 4-5 minutes faster Check here for more info https://github.com/equinor/ert/actions/runs/11971902477/job/33377669575

JHolba commented 4 days ago

Async generators seem to be slower

https://en.lewoniewski.info/2023/python-3-11-vs-python-3-12-performance-testing/

xjules commented 3 days ago

Some performance comparison when testing on RHEL8 python 3.12 and Python 3.11:


Python 3.12

tests/ert/ui_tests/cli/test_field_parameter.py::test_field_param_update_using_heat_equation PASSED
tests/ert/ui_tests/cli/test_field_parameter.py::test_parameter_update_with_inactive_cells_xtgeo_grdecl PASSED
tests/ert/ui_tests/cli/test_field_parameter.py::test_field_param_update_using_heat_equation_zero_var_params_and_adaptive_loc PASSED
tests/ert/ui_tests/cli/test_field_parameter.py::test_foward_init_false PASSED

=========================================================================================================================================================================================================== warnings summary ============================================================================================================================================================================================================
tests/ert/ui_tests/cli/test_field_parameter.py: 430 warnings
  /private/jparu/.local/share/uv/python/cpython-3.12.7-linux-x86_64-gnu/lib/python3.12/subprocess.py:1885: RuntimeWarning: Using fork() can cause Polars to deadlock in the child process.
  In addition, using fork() with Python in general is a recipe for mysterious
  deadlocks and crashes.

  The most likely reason you are seeing this error is because you are using the
  multiprocessing module on Linux, which uses fork() by default. This will be
  fixed in Python 3.14. Until then, you want to use the "spawn" context instead.

  See https://docs.pola.rs/user-guide/misc/multiprocessing/ for details.

    self.pid = _fork_exec(

tests/ert/ui_tests/cli/test_field_parameter.py: 394 warnings
  /data/env/py312-ert/lib/python3.12/site-packages/pydantic/main.py:212: DeprecationWarning: In future, it will be an error for 'np.bool_' scalars to be interpreted as an index
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================================================================================================================================================================== 4 passed, 824 warnings in 136.33s (0:02:16)

Python 3.11

tests/ert/ui_tests/cli/test_field_parameter.py::test_field_param_update_using_heat_equation PASSED
tests/ert/ui_tests/cli/test_field_parameter.py::test_parameter_update_with_inactive_cells_xtgeo_grdecl PASSED
tests/ert/ui_tests/cli/test_field_parameter.py::test_field_param_update_using_heat_equation_zero_var_params_and_adaptive_loc PASSED
tests/ert/ui_tests/cli/test_field_parameter.py::test_foward_init_false PASSED

=========================================================================================================================================================================================================== warnings summary ============================================================================================================================================================================================================
tests/ert/ui_tests/cli/test_field_parameter.py: 394 warnings
  /data/env/py311-zmq/lib64/python3.11/site-packages/pydantic/main.py:212: DeprecationWarning: In future, it will be an error for 'np.bool_' scalars to be interpreted as an index
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================================================================================================================================================================== 4 passed, 394 warnings in 120.61s (0:02:00) =
eivindjahren commented 2 days ago

There is no longer such a big difference after https://github.com/equinor/ert/commit/9566c97b34b78a1119f67c1fe5ab380431132570

xjules commented 1 day ago

It seems indeed that the discrepancy was caused by using parallelization in tests. Closing this one.