-
-
Notifications
You must be signed in to change notification settings - Fork 547
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
[Bug]: pybamm.Simulation.set_parameters
and pybamm.Simulation.set_up_and_parameterise_experiment
made private in simulation.py
#4489
base: develop
Are you sure you want to change the base?
Conversation
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.
I think the other question for this is what we do about the function names and tests.
Improvements:
I think that if we intend to deprecate the public functions we should:
- First rename all the usages to
_set_parameters()
and_set_up_and_parameterise_experiment()
- Create new functions called
set_parameters()
andsetup_and_parametrise_experiments()
- The new functions should be more like this
def set_parameters(...): msg = "pybamm.simulation.set_parameters() is deprecated" warnings,warn(msg, DeprecationWarning, stacklevel=2) self._set_parameters(...)
The renaming is done first so you make sure to catch all usages in the codebase before adding the new one.
Problems:
- The tests use these functions, so this means that we will be accessing private members outside the class.
- In the future I would like to turn on inspections to prevent accessing private methods. This becomes a problem if the tests need to access these methods.
- We should find a solution to having the tests access these members.
src/pybamm/simulation.py
Outdated
@@ -182,7 +182,8 @@ def set_up_and_parameterise_experiment(self, solve_kwargs=None): | |||
reduces simulation time since the model formulation is efficient. | |||
""" | |||
parameter_values = self._parameter_values.copy() | |||
|
|||
msg = "pybamm.simulation.set_up_and_parameterise_experiment is deprecated and not meant to be accessed by users." | |||
warnings(msg, DeprecationWarning) |
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.
Two problems here:
- You need to make it warnings.warn
- You need to explicitly set stacklevel
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.
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.
Yes
…l-Sharma30/PyBaMM into simulation_function_private
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #4489 +/- ##
=========================================
Coverage 99.41% 99.42%
=========================================
Files 293 297 +4
Lines 22554 22693 +139
=========================================
+ Hits 22423 22562 +139
Misses 131 131 ☔ View full report in Codecov by Sentry. |
Description
pybamm.Simulation.set_parameters
,pybamm.Simulation.set_up_and_parameterise_experiment
andpybamm.Simulation.set_up_and_parameterise_model_for_experiment
made private inpybamm/simulation.py
(continuation of #3752 PR)
Fixes #3751
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: