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

Summary variables calculated only when called #4621

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from

Conversation

pipliggins
Copy link
Contributor

@pipliggins pipliggins commented Nov 26, 2024

Description

Rather than calculating summary variables and storing them in every Solution class, a 'SummaryVariables' class is created which stores the first + last state of the solution, plus any relevant esoh parameters, so that the summary variables are only calculated and stored when they are called (similar to accessing standard variables). If an esoh variable is requested, they are all calculated and stored at once to reduce the number of calls to the esoh solver.

rather than viewing the list of summary variable names as

sol.summary_variables.keys()

you can now use

sol.summary_variables.all_variables

to view the names without calculating the variables.

Similarly, when plotting rather than getting the number of cycles as

sol.summary_variables['Cycle number']

they are accessed as

sol.summary_variables.cycle_number

Fixes #4058

Type of change

  • Optimization (back-end change that speeds up the code)

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

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link

codecov bot commented Nov 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.22%. Comparing base (72c23ea) to head (ef05257).
Report is 12 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4621   +/-   ##
========================================
  Coverage    99.21%   99.22%           
========================================
  Files          302      303    +1     
  Lines        22858    22950   +92     
========================================
+ Hits         22679    22771   +92     
  Misses         179      179           

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

self._possible_variables = model.summary_variables # minus esoh variables
self._esoh_variables = [] # Store eSOH variable names

# Flag if eSOH calculations are needed
Copy link
Contributor

Choose a reason for hiding this comment

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

related: #4619

@pipliggins pipliggins force-pushed the 4058-lazy-summary-variables branch from 67542c0 to b76d866 Compare December 2, 2024 11:17
@pipliggins pipliggins requested a review from rtimms December 3, 2024 13:48
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.

sorry for the delay in the review! This looks great, can you please add to the CHANGELOG under breaking changes, since this changes the api for the summary variables?

self.first_state = None
self.last_state = None
self.cycles = cycle_summary_variables
self.cycle_number = np.arange(1, len(self.cycles) + 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

I can see that at least cycle_number is used outside this class, can you please document the attributes that are meant to be public in the docstring?

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.

Calculate summary variables only when they are called
4 participants