Skip to content
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

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

Akhil-Sharma30
Copy link
Contributor

Description

pybamm.Simulation.set_parameters, pybamm.Simulation.set_up_and_parameterise_experiment and pybamm.Simulation.set_up_and_parameterise_model_for_experiment made private in pybamm/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.

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • No style issues: $ 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)
  • All tests pass: $ python run-tests.py --all (or $ nox -s tests)
  • The documentation builds: $ 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:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

Copy link
Contributor

@kratman kratman left a 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:

  1. First rename all the usages to _set_parameters() and _set_up_and_parameterise_experiment()
  2. Create new functions called set_parameters() and setup_and_parametrise_experiments()
  3. 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.

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two problems here:

  1. You need to make it warnings.warn
  2. You need to explicitly set stacklevel

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this?
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

CHANGELOG.md Outdated Show resolved Hide resolved
src/pybamm/simulation.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Oct 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.42%. Comparing base (2ca16ac) to head (ea4176d).
Report is 5 commits behind head on develop.

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.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants