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

Fix indexing bug with infeasible experiments for IDAKLUSolver #4541

Merged
merged 2 commits into from
Oct 23, 2024

Conversation

MarcBerliner
Copy link
Member

Description

@pipliggins figured out why infeasible experiments were failing with the IDAKLUSolver:

I checked this with #4534 to confirm it's not an output_variables specific problem - it's not, but related.

Having the voltage limit violation at the start of a cycle step results in the final solution containing an empty array in the middle of all_ys. The assumption leading to the output_variables error was that the only time an empty numpy array would be present in all_ys is if the solver isn’t returning the full state vector, as with IDAKLU(output_variables=true), so an false error is being flagged. I fixed that by checking for an empty t array too in _update_variables(), i.e.:

      for i, (model, ts, ys, inputs, var_pybamm) in enumerate(
          zip(self.all_models, self.all_ts, self.all_ys, self.all_inputs, vars_pybamm)
      ):
          if (
              ys.size == 0
              and var_pybamm.has_symbol_of_classes(
                  pybamm.expression_tree.state_vector.StateVector
              )
              and not ts.size == 0
          ):

But using this I get a different error related to the hermite interpolation. Turning off hermite interpolation in the solver (and with the output_variables fix) the example runs as expected. I suspect the interpolation issue is also being caused by an unexpected empty array in the state vector, but haven’t dug that far.

Originally posted by @pipliggins in #4496

I added additional checking in the ProcessedVariable class to ignore empty sub-solutions.

Fixes #4496

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.

  • 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

Co-Authored-By: Pip Liggins <55396775+pipliggins@users.noreply.github.com>
Copy link

codecov bot commented Oct 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.42%. Comparing base (164f71e) to head (b68b139).
Report is 198 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4541      +/-   ##
===========================================
- Coverage    99.42%   99.42%   -0.01%     
===========================================
  Files          299      299              
  Lines        22717    22716       -1     
===========================================
- Hits         22586    22585       -1     
  Misses         131      131              

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

@kratman kratman self-requested a review October 23, 2024 19:08
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 @MarcBerliner and @pipliggins. just one comment that will hopefully simplify the logic

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 👍

@MarcBerliner MarcBerliner merged commit 9560875 into develop Oct 23, 2024
26 checks passed
@MarcBerliner MarcBerliner deleted the fix-empty-solution-interp branch October 23, 2024 21:07
MarcBerliner added a commit that referenced this pull request Oct 23, 2024
pkalbhor pushed a commit to pkalbhor/PyBaMM that referenced this pull request Nov 15, 2024
…mm-team#4541)

* fix interp indexing

Co-Authored-By: Pip Liggins <55396775+pipliggins@users.noreply.github.com>

* simplify indexing

---------

Co-authored-by: Pip Liggins <55396775+pipliggins@users.noreply.github.com>
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]: IDAKLUSolver output variables
2 participants