Repository navigation
Enhance plot_voltage_components.py for Simulation and Solution classes - #3723
Saransh-cpp merged 9 commits into
Conversation
This commit extends the functionality of the `plot_voltage_components` method in PyBaMM, enhancing its integration within the `Simulation` and `Solution` classes. Key Changes: - Modified the standalone `plot_voltage_components` function in `plot_voltage_components.py` to handle both `Simulation` and `Solution` objects. - `Simulation` Class: Added a new method `plot_voltage_components`. This method calls the standalone `plot_voltage_components` function and utilizes the solution attribute of the `Simulation` instance to generate the plot. - `Solution` Class: Introduced a similar `plot_voltage_components` method to the `Solution` class, enabling direct plotting of voltage components from `Solution` instances. - Modified `test_plot_voltage_components.py`
There was a problem hiding this comment.
Thanks for working on this, @AlessioBugetti!
It would be nice to comb through the example notebooks once and see if the new sim.plot_voltage_components and sol.plot_voltage_components can be added somewhere.
| else: | ||
| raise ValueError("Input must be a Solution or Simulation object") |
There was a problem hiding this comment.
IMO specifying the type of the variable in the docs (docstring) should be enough.
| else: | |
| raise ValueError("Input must be a Solution or Simulation object") |
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
I am reviewing the Getting Started notebooks so will include these in Tutorial 3 once they are merged. |
brosaplanella
left a comment
There was a problem hiding this comment.
Looks good, thanks! Just add a line to the CHANGELOG before we merge.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #3723 +/- ##
========================================
Coverage 99.59% 99.59%
========================================
Files 258 258
Lines 20811 20823 +12
========================================
+ Hits 20726 20738 +12
Misses 85 85 ☔ View full report in Codecov by Sentry. |
…is called on an unsolved simulation
|
@all-contributors please add @AlessioBugetti for code, docs, tests |
|
I've put up a pull request to add @AlessioBugetti! 🎉 |
| - Fixed a bug where if the first step(s) in a cycle are skipped then the cycle solution started from the model's initial conditions instead of from the last state of the previous cycle ([#3708](https://github.com/pybamm-team/PyBaMM/pull/3708)) | ||
| - Updated `plot_voltage_components.py` to support both `Simulation` and `Solution` objects. Added new methods in both `Simulation` and `Solution` classes for allow the syntax `simulation.plot_voltage_components` and `solution.plot_voltage_components`. Updated `test_plot_voltage_components.py` to reflect these changes ([#3723](https://github.com/pybamm-team/PyBaMM/pull/3723)). |
There was a problem hiding this comment.
| - Fixed a bug where if the first step(s) in a cycle are skipped then the cycle solution started from the model's initial conditions instead of from the last state of the previous cycle ([#3708](https://github.com/pybamm-team/PyBaMM/pull/3708)) | |
| - Updated `plot_voltage_components.py` to support both `Simulation` and `Solution` objects. Added new methods in both `Simulation` and `Solution` classes for allow the syntax `simulation.plot_voltage_components` and `solution.plot_voltage_components`. Updated `test_plot_voltage_components.py` to reflect these changes ([#3723](https://github.com/pybamm-team/PyBaMM/pull/3723)). | |
| - Updated `plot_voltage_components.py` to support both `Simulation` and `Solution` objects. Added new methods in both `Simulation` and `Solution` classes for allow the syntax `simulation.plot_voltage_components` and `solution.plot_voltage_components`. Updated `test_plot_voltage_components.py` to reflect these changes ([#3723](https://github.com/pybamm-team/PyBaMM/pull/3723)). | |
| - Fixed a bug where if the first step(s) in a cycle are skipped then the cycle solution started from the model's initial conditions instead of from the last state of the previous cycle ([#3708](https://github.com/pybamm-team/PyBaMM/pull/3708)) |
Small comment: for the CHANGELOG we sort contributions by decreasing PR number (i.e. newer PRs first).
There was a problem hiding this comment.
Sorry, I just corrected this oversight
Commit here
There was a problem hiding this comment.
@AlessioBugetti Just as an FYI, you can accept suggestions too so you don't have to do a separate commit. You just need to press the "commit suggestion" button
|
The CHANGELOG in develop was updated for |
I've updated the CHANGELOG, conflicts resolved |
pybamm-team#3723) * Enhance plot_voltage_components for Simulation and Solution classes This commit extends the functionality of the `plot_voltage_components` method in PyBaMM, enhancing its integration within the `Simulation` and `Solution` classes. Key Changes: - Modified the standalone `plot_voltage_components` function in `plot_voltage_components.py` to handle both `Simulation` and `Solution` objects. - `Simulation` Class: Added a new method `plot_voltage_components`. This method calls the standalone `plot_voltage_components` function and utilizes the solution attribute of the `Simulation` instance to generate the plot. - `Solution` Class: Introduced a similar `plot_voltage_components` method to the `Solution` class, enabling direct plotting of voltage components from `Solution` instances. - Modified `test_plot_voltage_components.py` * Improved code readability by removing explicit variable type checking * Update example notebooks * Update CHANGELOG.md * Fix test_plot_voltage_components.py * Add test to ensure ValueError is raised when plot_voltage_components is called on an unsolved simulation * Sort contributions by decreasing PR number
Description
This commit extends the functionality of the
plot_voltage_componentsmethod, enhancing its integration within theSimulationandSolutionclasses.Key Changes:
Modified the
plot_voltage_componentsfunction inplot_voltage_components.pyto handle bothSimulationandSolutionobjects.SimulationClass: Added a new methodplot_voltage_components. This method calls the standaloneplot_voltage_componentsfunction and utilizes the solution attribute of theSimulationinstance to generate the plot.SolutionClass: Introduced a similarplot_voltage_componentsmethod to theSolutionclass, enabling direct plotting of voltage components fromSolutioninstances.Modified
test_plot_voltage_components.pyFixes #3722
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.
Key checklist:
$ 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)$ python run-tests.py --all(or$ nox -s tests)$ 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: