-
-
Notifications
You must be signed in to change notification settings - Fork 551
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
I4087-multiprocessing #4260
Draft
martinjrobins
wants to merge
23
commits into
develop
Choose a base branch
from
i4087-multiprocessing
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
I4087-multiprocessing #4260
+2,171
−1,101
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Partially fixes #4087
This PR expands pybamm's ability to run multiple simulations with different values for input parameters, using multiple cpu threads. The new features added are:
n
sets of input parameters are given tosolve
, user can setbatch_size=n_b
argument to batch thesen
simulations into groups of sizen_b
, so that the number of solves is reduced ton / n_b
. This effectivly duplicates the set of equations solvedn_b
times, so that each solve hasn_s * n_b
equations, wheren_s
is the original number of equations. Events are handled using a softmax function over the batch of simulations, so that the simulation continues until the event is triggered in all simulations in the batch. Note that experiments show that this is effective in reducing simulation duration even when using a single thread, although this batching is probably most useful for running simulations on a GPU (or if you have a small system of equations). However, this is not an effective replacement for the use of the multiprocessing library if you are targetting CPUs, which was the original plan in refactor multiprocessing and multiple inputs #4087.Note that while the original plan for #4087 was to remove multiprocessing, I've only managed to do this for the idaklu solver for now. Once casadi implements events then we can remove multiprocessing (replace with
casadi.vmap
) for this solver as well.Other:
Symbol.diff
function now returns a vector if a vector expression is differentiated wrt itself (previously this gave a scalar). This was a source of a bug and I thought this made more sense mathematicallyHere is a script to demonstrate the timing for solving 1000 SPM models in parallel
This gives, on my machine:
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.
Key checklist:
$ 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)$ python run-tests.py --all
(or$ nox -s tests
)$ 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: