Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardise BaseSolver.solve() multiprocessing context to fork #3975

Merged
merged 5 commits into from
Apr 10, 2024

Conversation

BradyPlanden
Copy link
Member

@BradyPlanden BradyPlanden commented Apr 9, 2024

Description

This PR updated the multiprocess pool to be constructed with context fork for darwin and linux platforms. It also adds an example and updates integration tests to use the list of dictionaries input functionality which should ensure this get tested in script formation.

Fixes #3974

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • No style issues: $ pre-commit run (or $ nox -s pre-commit) (see CONTRIBUTING.md for how to set this up to run automatically when committing locally, in just two lines of code)
  • All tests pass: $ python run-tests.py --all (or $ nox -s tests)
  • The documentation builds: $ python run-tests.py --doctest (or $ nox -s doctests)

You can run integration tests, unit tests, and doctests together at once, using $ python run-tests.py --quick (or $ nox -s quick).

Further checks:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

Copy link

codecov bot commented Apr 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.58%. Comparing base (c204bdd) to head (4047b37).
Report is 3 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3975   +/-   ##
========================================
  Coverage    99.58%   99.58%           
========================================
  Files          257      257           
  Lines        21251    21254    +3     
========================================
+ Hits         21163    21166    +3     
  Misses          88       88           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@agriyakhetarpal
Copy link
Member

The Windows tests are still failing, I guess it is related to the fact that fork() syscalls are not available on Windows (can we fix this just conditionally in case the MWE you posted works on Windows but fails on Unix-like systems?)

@BradyPlanden
Copy link
Member Author

This is now ready for merge for those that have permissions.

It's worth noting that this only fixes #3974 for darwin systems and protects linux systems from the default context change in Python 3.14. Windows systems will still require the __main__ guard discussed in #3974.

Longer term, @martinjrobins and I discussed moving to a more robust solution by implementing the multiprocessing in C++.

Copy link
Contributor

@martinjrobins martinjrobins left a comment

Choose a reason for hiding this comment

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

looks good, just need approval from @kratman, then can merge

@kratman
Copy link
Contributor

kratman commented Apr 10, 2024

It's worth noting that this only fixes #3974 for darwin systems and protects linux systems from the default context change in Python 3.14. Windows systems will still require the main guard

@BradyPlanden If this does not fix the problem on windows, is the task completed? Merging this PR will close the issue.

@BradyPlanden
Copy link
Member Author

I would recommend we merge this and reopen (or unlink) #3974 to continue discussion on a longer-term solution that doesn't depend on the multiprocessing. Open to other suggestions though.

@kratman
Copy link
Contributor

kratman commented Apr 10, 2024

I would recommend we merge this and reopen (or unlink) #3974 to continue discussion on a longer-term solution that doesn't depend on the multiprocessing. Open to other suggestions though.

Yeah I think it should be unlinked or a new ticket opened for the windows side

@kratman kratman merged commit b068ba6 into pybamm-team:develop Apr 10, 2024
39 of 40 checks passed
js1tr3 pushed a commit to js1tr3/PyBaMM that referenced this pull request Aug 12, 2024
…amm-team#3975)

* Enforce multiprocessing context fork, add example & updt integration test

* updt changelog

* Add OS conditional context

---------

Co-authored-by: Eric G. Kratz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: BaseSolver.solve() multiprocessing is broken on system's defaulting to spawn context
5 participants