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

feat: add discrete time sum expression tree node #4501

Merged
merged 8 commits into from
Oct 9, 2024

Conversation

martinjrobins
Copy link
Contributor

@martinjrobins martinjrobins commented Oct 8, 2024

Description

Adds two new subclasses to pybamm.Symbol:

  1. pybamm.DiscreteTimeData which is an interpolant for holding time series data
  2. pybamm.DiscreteTimeSum which is a unary operator representing a sum of its child evaluation over a set of data time points. Its child must have exactly one pybamm.DiscreteTimeData object.

When pybamm.DiscreteTimeSum is evaluated normally it returns the evaluation of its child. If it is evaluated as part of a pybamm.Solution then it interpolates this solution onto the data time points and sums these over the time axis

This also updates the evaluation of pybamm.ExplicitTimeIntegral. Previously this performed a trapezoidal integral over all the time points passed to the __call__ function of pybamm.ProcessedVariable. Now it performs the integral over the solution time points, which is more consistent with its definition and always returns the same value irrespective of the time values that the user passes to __call__. In the future this integral should be updated to use the gradient information of the solution if available.

Fixes #4485

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)

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

@martinjrobins martinjrobins changed the title feat: add discrete time sum expression tree node #4485 feat: add discrete time sum expression tree node Oct 8, 2024
Copy link

codecov bot commented Oct 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.42%. Comparing base (9e62b66) to head (9b3d13f).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4501   +/-   ##
========================================
  Coverage    99.42%   99.42%           
========================================
  Files          297      299    +2     
  Lines        22685    22739   +54     
========================================
+ Hits         22554    22608   +54     
  Misses         131      131           

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

Copy link
Member

@MarcBerliner MarcBerliner left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for also separating out and simplifying the ExplicitTimeIntegral. The changelog needs updating as well.

tests/unit/test_solvers/test_solution.py Outdated Show resolved Hide resolved
@MarcBerliner MarcBerliner merged commit e4eb82a into develop Oct 9, 2024
25 checks passed
@MarcBerliner MarcBerliner deleted the i4485-discrete-time-sum branch October 9, 2024 14:13
pkalbhor pushed a commit to pkalbhor/PyBaMM that referenced this pull request Nov 15, 2024
* feat: add discrete time sum expression tree node pybamm-team#4485

* docs: fix math syntax in docstring

* remove prints

* test casadi solver as well

* coverage

* coverage

* add to changelog and tidy solution test
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.

add DiscreteTimeSum subclass of pybamm.Symbol
2 participants