Skip to content

Added an option for multiple initial conditions in IDAKLU solver#4981

Merged
martinjrobins merged 22 commits intopybamm-team:developfrom
Rishab87:multiple-initial-conditions
Sep 8, 2025
Merged

Added an option for multiple initial conditions in IDAKLU solver#4981
martinjrobins merged 22 commits intopybamm-team:developfrom
Rishab87:multiple-initial-conditions

Conversation

@Rishab87
Copy link
Member

Description

Added an option for multiple initial conditions in IDAKLU solver

Fixes #3713

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #)

Important checks:

Please confirm the following before marking the PR as ready for review:

  • No style issues: nox -s pre-commit
  • All tests pass: nox -s tests
  • The documentation builds: nox -s doctests
  • Code is commented for hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@codecov
Copy link

codecov bot commented Apr 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.88%. Comparing base (43f8f43) to head (5ccacf2).
⚠️ Report is 96 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4981   +/-   ##
========================================
  Coverage    98.88%   98.88%           
========================================
  Files          320      320           
  Lines        26949    26981   +32     
========================================
+ Hits         26648    26680   +32     
  Misses         301      301           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

thanks @Rishab87, this is a great start and on the right track. I've made a few comments and suggestions below, happy to discuss any of them just reply to this or message me on the slack.

n_sims = 3
initial_conditions = [{"u": i + 1} for i in range(n_sims)]
inputs = [{} for _ in range(n_sims)]
t_eval = np.linspace(0, 1, 10)
Copy link
Contributor

Choose a reason for hiding this comment

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

use:

t_eval = [0, 1]
t_interp = np.linspace(0, 1, 10)

then

solutions = solver.solve(
            model, t_eval, t_interp=t_interp, inputs=inputs, initial_conditions=initial_conditions
        )

Copy link
Contributor

Choose a reason for hiding this comment

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

This change did not seem to be done yet

Copy link
Member Author

Choose a reason for hiding this comment

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

ohh sorry, ig I missed it in few tests, added this change

@Rishab87 Rishab87 marked this pull request as ready for review April 27, 2025 11:01
@Rishab87 Rishab87 requested a review from a team as a code owner April 27, 2025 11:01
@Rishab87
Copy link
Member Author

@martinjrobins Thanks for the review, I've made few changes accordingly and replied to all the comments

@Rishab87 Rishab87 requested a review from martinjrobins April 27, 2025 11:02
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.

thanks @Rishab87, test_multiple_initial_conditions_spm and test_multiple_initial_conditions_dfn look very similar, can we combine this into a single test that is parameterised by the model class? Also, it would be good to check the solution against two separate solves using those initial conditions, so we know the solution is correct, not just the initial condition

@Rishab87
Copy link
Member Author

Rishab87 commented May 1, 2025

@martinjrobins thanks for the review again, I've made few changes in the tests and replied to the comments

@Rishab87 Rishab87 requested a review from martinjrobins May 1, 2025 09:11
martinjrobins
martinjrobins previously approved these changes Jun 17, 2025
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.

thanks @Rishab87 for making the changes, sorry for the delay in review this fell off my radar. All looks good to me now

@Rishab87
Copy link
Member Author

@martinjrobins thanks for the review

@Rishab87 Rishab87 requested a review from kratman June 17, 2025 12:31
@Rishab87 Rishab87 requested a review from kratman June 17, 2025 13:52
@Rishab87
Copy link
Member Author

@kratman any updates on this?

Co-authored-by: Eric G. Kratz <kratman@users.noreply.github.com>
@kratman
Copy link
Contributor

kratman commented Jul 22, 2025

@Rishab87 From my side we mostly just need traceability on the open items

@Rishab87
Copy link
Member Author

@kratman I've already addressed open items here:

  • used t_eval & t_interp as told there in all the unit tests.
  • used reasonable tolerances in unit tests rtol=1e-3 & atol=1e-5.
  • Added integration tests for PDE models (SPM & DFN).

Anything else you would like to know?

@kratman
Copy link
Contributor

kratman commented Jul 22, 2025

@kratman I've already addressed open items here:

  • used t_eval & t_interp as told there in all the unit tests.
  • used reasonable tolerances in unit tests rtol=1e-3 & atol=1e-5.
  • Added integration tests for PDE models (SPM & DFN).

Anything else you would like to know?

I think a ticket for the Jax solver portion would be good

@Rishab87
Copy link
Member Author

@kratman yeah sure I'll keep jax seperate this PR does not have any jax related code, by ticket you mean should I create a seperate issue for jax?

@kratman
Copy link
Contributor

kratman commented Jul 25, 2025

@kratman yeah sure I'll keep jax seperate this PR does not have any jax related code, by ticket you mean should I create a seperate issue for jax?

Yes

@Rishab87
Copy link
Member Author

Created the issue.

@kratman kratman dismissed their stale review July 25, 2025 19:47

Changes I requested were completed

@Rishab87
Copy link
Member Author

Rishab87 commented Sep 7, 2025

@kratman @martinjrobins any updates on this one?

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 all good to me, thanks @Rishab87

@martinjrobins martinjrobins merged commit f5a6f1e into pybamm-team:develop Sep 8, 2025
21 of 22 checks passed
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.

IDAKLU solver: add option for multiple initial conditions

3 participants