-
-
Notifications
You must be signed in to change notification settings - Fork 563
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
Enhance plot_voltage_components.py for Simulation and Solution classes #3723
Enhance plot_voltage_components.py for Simulation and Solution classes #3723
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! 🎉 |
CHANGELOG.md
Outdated
- 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I just corrected this oversight
Commit here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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_components
method, enhancing its integration within theSimulation
andSolution
classes.Key Changes:
Modified the
plot_voltage_components
function inplot_voltage_components.py
to handle bothSimulation
andSolution
objects.Simulation
Class: Added a new methodplot_voltage_components
. This method calls the standaloneplot_voltage_components
function and utilizes the solution attribute of theSimulation
instance to generate the plot.Solution
Class: Introduced a similarplot_voltage_components
method to theSolution
class, enabling direct plotting of voltage components fromSolution
instances.Modified
test_plot_voltage_components.py
Fixes #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: