Skip to content

Conversation

MarcBerliner
Copy link
Member

Description

Fixes an issue where updating the slider of a quickplot could produce NaN values at the beginning or end of a timespan due to slight extrapolation because of floating point arithmetic issues.

For example, try running this simulation and moving the slider to the final time:

import pybamm

model = pybamm.lithium_ion.SPM()
parameter_values = pybamm.ParameterValues("Chen2020")
parameter_values.update({"Current function [A]": 0})

solver = pybamm.IDAKLUSolver()
sim = pybamm.Simulation(model, parameter_values=parameter_values, solver=solver)

tf = 3600.04

sol = sim.solve([0, tf])

# This breaks because of issues with floating point precision
# when we normalize and rescale the time
# tf < (tf / 3600.0) * 3600.0

sol.plot()

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #)

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

@MarcBerliner MarcBerliner marked this pull request as ready for review April 23, 2025 15:19
@MarcBerliner MarcBerliner requested a review from a team as a code owner April 23, 2025 15:19
Copy link

codecov bot commented Apr 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.62%. Comparing base (eb9f5fc) to head (8c15534).
Report is 106 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4991   +/-   ##
========================================
  Coverage    98.62%   98.62%           
========================================
  Files          304      304           
  Lines        23755    23757    +2     
========================================
+ Hits         23428    23430    +2     
  Misses         327      327           

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

@kratman kratman enabled auto-merge (squash) April 23, 2025 15:27
@kratman kratman merged commit c2bf6ec into develop Apr 23, 2025
25 checks passed
@kratman kratman deleted the mdb/fix-plot-slider-nan branch April 23, 2025 15:36
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.

2 participants