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, pybamm.Simulation.set_up_and_parameterise_experiment and pybamm.Simulation.set_up_and_parameterise_model_for_experiment made private in simulation.py #3752

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

## Breaking changes

- Added a deprecated warning for `pybamm.Simulation.set_parameters`, `pybamm.Simulation.set_up_and_parameterise_experiment` and `pybamm.Simulation.set_up_and_parameterise_model_for_experiment` functions in `pybamm.simulation.py`. ([#3752](https://github.com/pybamm-team/PyBaMM/pull/3752))
Copy link
Member

Choose a reason for hiding this comment

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

You'll also need to shift it to the unreleased section

Suggested change
- Added a deprecated warning for `pybamm.Simulation.set_parameters`, `pybamm.Simulation.set_up_and_parameterise_experiment` and `pybamm.Simulation.set_up_and_parameterise_model_for_experiment` functions in `pybamm.simulation.py`. ([#3752](https://github.com/pybamm-team/PyBaMM/pull/3752))
- Deprecated `pybamm.Simulation.set_parameters`, `pybamm.Simulation.set_up_and_parameterise_experiment` and `pybamm.Simulation.set_up_and_parameterise_model_for_experiment` functions in `pybamm.simulation.py`. ([#3752](https://github.com/pybamm-team/PyBaMM/pull/3752))

- The parameters `GeometricParameters.A_cooling` and `GeometricParameters.V_cell` are now automatically computed from the electrode heights, widths and thicknesses if the "cell geometry" option is "pouch" and from the parameters "Cell cooling surface area [m2]" and "Cell volume [m3]", respectively, otherwise. When using the lumped thermal model we recommend using the "arbitrary" cell geometry and specifying the parameters "Cell cooling surface area [m2]", "Cell volume [m3]" and "Total heat transfer coefficient [W.m-2.K-1]" directly. ([#3707](https://github.com/pybamm-team/PyBaMM/pull/3707))
- Dropped support for the `[jax]` extra, i.e., the Jax solver when running on Python 3.8. The Jax solver is now available on Python 3.9 and above ([#3550](https://github.com/pybamm-team/PyBaMM/pull/3550))

Expand Down
10 changes: 9 additions & 1 deletion pybamm/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from datetime import timedelta
from pybamm.util import have_optional_dependency
from typing import Optional
from warnings import warn
Copy link
Member

Choose a reason for hiding this comment

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

Nitpicking here, but we should keep this uniform throughout the codebase -

Suggested change
from warnings import warn
import warnings

and then warnings.warn everywhere


from pybamm.expression_tree.operations.serialise import Serialise

Expand Down Expand Up @@ -177,6 +178,7 @@ def _set_random_seed(self):

def set_up_and_parameterise_experiment(self):
"""
This is a helper function.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
This is a helper function.

Set up a simulation to run with an experiment. This creates a dictionary of
inputs (current/voltage/power, running time, stopping condition) for each
operating condition in the experiment. The model will then be solved by
Expand All @@ -185,6 +187,8 @@ def set_up_and_parameterise_experiment(self):
This needs to be done here and not in the Experiment class because the nominal
cell capacity (from the parameters) is used to convert C-rate to current.
"""
msg = "pybamm.simulation.set_up_and_parameterise_experiment is not meant to be accessed directly."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
msg = "pybamm.simulation.set_up_and_parameterise_experiment is not meant to be accessed directly."
msg = "pybamm.simulation.set_up_and_parameterise_experiment is deprecated and not meant to be accessed by users"

warn(msg, DeprecationWarning)
Copy link
Member

Choose a reason for hiding this comment

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

Given that not a lot of users are using these methods and we want to make them private in the next release - we could create dummy public methods that throw NameError on being invoked -

def set_up_and_parameterise_experiment(self):
    """
    A note here for users that this should not be used and is not private
    with the name _set_up_and_parameterise_experiment
    """
    raise NameError(...)

Just suggestions. We should go ahead with the strategy that most maintainers agree with.

Copy link
Contributor Author

@Akhil-Sharma30 Akhil-Sharma30 Jan 25, 2024

Choose a reason for hiding this comment

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

happy to take suggestions and do what is decided upon

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's a good idea to make them private right in the next release, since it doesn't conform to our policy of three releases – even if the popularity of this API not being relatively high is the question. Keeping them public plus raising a DeprecationWarning should be enough, a NameError sounds a bit odd IMO (I don't think we have used this before).

# Update experiment using capacity
capacity = self._parameter_values["Nominal cell capacity [A.h]"]
for op_conds in self.experiment.operating_conditions_steps:
Expand All @@ -209,12 +213,15 @@ def set_up_and_parameterise_experiment(self):

def set_up_and_parameterise_model_for_experiment(self):
"""
This is a helper function.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
This is a helper function.

Set up self._model to be able to run the experiment (new version).
In this version, a new model is created for each step.

This increases set-up time since several models to be processed, but
reduces simulation time since the model formulation is efficient.
"""
msg = "pybamm.simulation.set_up_and_parameterise_model_for_experiment is not meant to be accessed directly."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
msg = "pybamm.simulation.set_up_and_parameterise_model_for_experiment is not meant to be accessed directly."
msg = "pybamm.simulation.set_up_and_parameterise_model_for_experiment is deprecated not meant to be accessed by users"

warn(msg, DeprecationWarning)
self.experiment_unique_steps_to_model = {}
for op_number, op in enumerate(self.experiment.unique_steps):
new_model = self._model.new_copy()
Expand Down Expand Up @@ -325,7 +332,8 @@ def set_parameters(self):
"""
A method to set the parameters in the model and the associated geometry.
"""

msg = "pybamm.set_paramters is meant to be accessed directly."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
msg = "pybamm.set_paramters is meant to be accessed directly."
msg = "pybamm.set_paramters is deprecated and not meant to be accessed by users"

warn(msg, DeprecationWarning)
if self.model_with_set_params:
return

Expand Down
Loading