PyBaMM icon indicating copy to clipboard operation
PyBaMM copied to clipboard

Create a base processed variable class

Open pipliggins opened this issue 6 months ago • 1 comments

Description

This PR addresses an issue encountered when using first_state or last_state solution objects with the output_variables option in the IDAKLU solver - for example, when supplying an starting solution to .solve() within an experiment.

When adding a first_state or last_state solution to a new solution computed with the output_variables option, a conflict arises due to the differing types of processed variables:

  • first_state/last_state solutions dynamically generate ProcessedVariable objects on demand.
  • New solutions (e.g. from .solve()) use ComputedProcessedVariable objects. These two classes currently share no functionality and cannot interoperate. Consequently, attempting to combine them to form a new solution results in failure.

This PR introduces a new abstract base class for both ProcessedVariable and ComputedProcessedVariable, providing a shared _update() method. This enables consistent combination of these objects when merging solutions. The concatenated object is always a ComputedProcessedVariable, since converting to a ProcessedVariable is not viable - it requires access to the full state vector, which is unavailable when output_variables is used.

Fixes #4743

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

pipliggins avatar Jun 25 '25 12:06 pipliggins

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 99.12%. Comparing base (1ce4ef2) to head (b9c351b). :warning: Report is 182 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5076   +/-   ##
========================================
  Coverage    99.12%   99.12%           
========================================
  Files          304      305    +1     
  Lines        23576    23608   +32     
========================================
+ Hits         23369    23401   +32     
  Misses         207      207           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

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

codecov[bot] avatar Jun 25 '25 12:06 codecov[bot]