Skip to content

Fix Solution.get_data_dict() Step length mismatch with starting_solution (#4990)#5479

Open
kamal20122012 wants to merge 1 commit intopybamm-team:mainfrom
kamal20122012:fix/get-data-dict-starting-solution-length-4990
Open

Fix Solution.get_data_dict() Step length mismatch with starting_solution (#4990)#5479
kamal20122012 wants to merge 1 commit intopybamm-team:mainfrom
kamal20122012:fix/get-data-dict-starting-solution-length-4990

Conversation

@kamal20122012
Copy link
Copy Markdown

Summary

  • When a Simulation is resumed via starting_solution and the very first experiment step's event triggers at the cycle's initial conditions, the simulation loop appends a pybamm.EmptySolution placeholder (with a single time equal to start_time) to that cycle's step list. Solution.__add__ deduplicates that boundary timestamp against the carried-over last_state, so the placeholder time is not present in cycle.t.
  • Solution.get_data_dict previously concatenated np.ones_like(step.t) for every entry in cycle.steps including the EmptySolution, which inflated data["Step"] by exactly one element per such cycle relative to data["Cycle"] and data["Time [s]"].
  • Skip EmptySolution entries when building "Step" so its length stays consistent with cycle.t.

Fixes #4990

Test plan

  • Reproduction script from the issue: Step, Cycle, and Time [s] are all 1763 (previously 1764 / 1763 / 1763).
  • New regression test tests/unit/test_solvers/test_solution.py::TestSolution::test_get_data_cycles_steps_skips_empty_step — verified to fail on pre-fix code (Step=7 vs Cycle=6) and pass with the fix.
  • Existing test_get_data_cycles_steps still passes.
  • pytest tests/unit/test_solvers/test_solution.py — 55 passed (1 pre-existing skipped: test_plot requires optional matplotlib).
  • pre-commit run --files <changed files> — all hooks pass.

…nsistent

When a Simulation is resumed via starting_solution and the first
experiment step's event triggers at initial conditions, the simulation
loop appends a pybamm.EmptySolution placeholder (with a single time
equal to start_time) to the cycle's step list. Solution.__add__
deduplicates that boundary point against the carried-over
last_state, so the placeholder timestamp is absent from cycle.t.
get_data_dict, however, walked cycle.steps and concatenated
np.ones_like(step.t) for every step including the EmptySolution,
inflating the "Step" array by one element per such cycle relative to
"Cycle" and "Time [s]".

Skip EmptySolution entries when building the "Step" array so its length
matches cycle.t. Adds a regression test that mimics the placeholder
scenario and asserts equal lengths across "Step", "Cycle", and the data
variable.

Fixes pybamm-team#4990
@kamal20122012 kamal20122012 requested a review from a team as a code owner April 30, 2026 08:50
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.15%. Comparing base (19c2d57) to head (f663e97).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5479   +/-   ##
=======================================
  Coverage   98.15%   98.15%           
=======================================
  Files         338      338           
  Lines       31115    31124    +9     
=======================================
+ Hits        30542    30551    +9     
  Misses        573      573           

☔ 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.

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]: Different series lengths in get_data_dict() using starting_solution

1 participant