Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ff6a817
Deprecation for deprecated fucntions
RohitP2005 Jan 16, 2025
7f34a0b
style: pre-commit fixes
pre-commit-ci[bot] Jan 16, 2025
3da7140
Merge branch 'pybamm-team:develop' into issue#2028
RohitP2005 Feb 2, 2025
3a15fe8
Removed previous deprecation warnings
RohitP2005 Feb 2, 2025
9c500b5
Merge branch 'pybamm-team:develop' into issue#2028
RohitP2005 Feb 3, 2025
949571b
Added -W flag to pytest
RohitP2005 Feb 3, 2025
3f327cb
Custom decorator added and filterwarningn adjusted
RohitP2005 Feb 4, 2025
9d29350
Merge branch 'develop' into issue#2028
RohitP2005 Feb 5, 2025
1eb61a0
setuptools fix
RohitP2005 Feb 10, 2025
47051ab
Merge branch 'develop' into issue#2028
RohitP2005 Feb 10, 2025
e57a1fd
using agriyakhetarpal's approach to ignore external warnings
RohitP2005 Feb 13, 2025
dba1881
Merge branch 'develop' into issue#2028
RohitP2005 Feb 13, 2025
c48ed38
Merge branch 'pybamm-team:develop' into issue#2028
RohitP2005 Feb 14, 2025
b91e9ce
Update pyproject.toml
RohitP2005 Feb 15, 2025
c564c87
moving deprecation decorator to uitl.py
RohitP2005 Feb 14, 2025
52e610b
Merge branch 'develop' into issue#2028
RohitP2005 Feb 20, 2025
a4025a1
style: pre-commit fixes
pre-commit-ci[bot] Feb 20, 2025
33ff787
Moved decorators to utils and corrected pytest config
RohitP2005 Feb 20, 2025
9d9c1bf
Added msg parameter in deprecation decorator
RohitP2005 Feb 20, 2025
139704c
Applied decorators to necessary functions
RohitP2005 Feb 20, 2025
808d5cd
Corrected imports for utils
RohitP2005 Feb 20, 2025
28f5397
Update pyproject.toml
RohitP2005 Feb 20, 2025
a703eca
Update pyproject.toml
RohitP2005 Feb 20, 2025
8784b35
removed old deprecation warningsdfasf
RohitP2005 Feb 20, 2025
7902c43
deprecation Decorator accepts msg as a dictionary
RohitP2005 Feb 20, 2025
eaf0994
Merge branch 'develop' into issue#2028
arjxn-py Feb 22, 2025
930190b
Update pyproject.toml
RohitP2005 Mar 13, 2025
6c76623
Merge branch 'develop' into issue#2028
RohitP2005 Mar 13, 2025
422029a
fixed deprecated tests
RohitP2005 Mar 26, 2025
6e2eb5a
Merge branch 'pybamm-team:develop' into issue#2028
RohitP2005 Apr 9, 2025
840b696
test coverage for deprecate warnings
RohitP2005 Apr 9, 2025
194c657
Added _set_paramters function in the test
RohitP2005 Apr 9, 2025
41e58e3
Merge branch 'develop' into issue#2028
RohitP2005 Apr 10, 2025
a565419
Unit test fixed
RohitP2005 Apr 12, 2025
0bf9abf
doctests fix
RohitP2005 Apr 12, 2025
6a63a05
Updated setuptools version
RohitP2005 Apr 13, 2025
444cf08
Merge branch 'develop' into issue#2028
RohitP2005 Apr 13, 2025
6db0714
Merge branch 'pybamm-team:develop' into issue#2028
RohitP2005 Apr 18, 2025
2e8d684
added test auxiliary domains
RohitP2005 Apr 15, 2025
71a5197
Merge branch 'pybamm-team:develop' into issue#2028
RohitP2005 May 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies = [
"posthog",
"pyyaml",
"platformdirs",
"deprecation"
]

[project.urls]
Expand Down Expand Up @@ -80,7 +81,7 @@ plot = [
"matplotlib>=3.6.0",
]
cite = [
"setuptools", # Fix for a pybtex issue
"setuptools==66.1.1", # Fix for a pybtex issue
"pybtex>=0.24.0",
]
# Battery Parameter eXchange format
Expand Down Expand Up @@ -231,8 +232,10 @@ required_plugins = [
addopts = [
"-nauto",
"-vra",
"--showlocals",
"--strict-config",
"--strict-markers",
"--ignore=tests/unit/test_parameters/test_bpx.py",
]
testpaths = [
"tests",
Expand All @@ -244,10 +247,14 @@ filterwarnings = [
# ignore internal nbmake warnings
'ignore:unclosed \<socket.socket:ResourceWarning',
'ignore:unclosed event loop \<:ResourceWarning',
# ignore warnings generated while running tests
"ignore::DeprecationWarning",
# convert internal warnings as errors
"error::DeprecationWarning:pybamm.*",
# ignore setuptools and pybtex deprecation warnings
"ignore::DeprecationWarning:pkg_resources",
"ignore:open_text is deprecated:DeprecationWarning",
"ignore::UserWarning",
"ignore::RuntimeWarning",
"ignore::pydantic.warnings.PydanticDeprecatedSince20",
]

# Logging configuration
Expand Down
7 changes: 7 additions & 0 deletions src/pybamm/expression_tree/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import pybamm
from pybamm.util import import_optional_dependency
from pybamm.expression_tree.printing.print_name import prettify_print_name
from deprecation import deprecated

if TYPE_CHECKING: # pragma: no cover
import casadi
Expand Down Expand Up @@ -357,6 +358,12 @@ def domain(self, domain):
)

@property
@deprecated(
deprecated_in="25.1.0",
removed_in="26.0.0",
current_version=pybamm.__version__,
details="Use `symbol.domains` instead.",
)
def auxiliary_domains(self):
"""Returns auxiliary domains."""
raise NotImplementedError(
Expand Down
18 changes: 18 additions & 0 deletions src/pybamm/parameters/parameter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pprint import pformat
from warnings import warn
from collections import defaultdict
from pybamm.util import deprecate_arguments


class ParameterValues:
Expand Down Expand Up @@ -417,6 +418,23 @@ def set_initial_ocps(
return parameter_values

@staticmethod
@deprecate_arguments(
deprecated_args={
"electrode diffusivity": "Use 'particle diffusivity' instead.",
"1 + dlnf/dlnc": "Use 'Thermodynamic factor' instead.",
"propotional term": " Use proportional term [s-1]', and its value should now be divided"
"by 3600 to get the same results as before",
},
deprecated_in="24.1.0",
removed_in="25.3.0",
current_version="25.1.0",
msg={
"electrode diffusivity": "Use 'particle diffusivity' instead.",
"1 + dlnf/dlnc": "Use 'Thermodynamic factor' instead.",
"propotional term": " Use proportional term [s-1]', and its value should now be divided"
"by 3600 to get the same results as before",
},
)
def check_parameter_values(values):
for param in list(values.keys()):
if "propotional term" in param:
Expand Down
14 changes: 7 additions & 7 deletions src/pybamm/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from datetime import timedelta
import pybamm.telemetry
from pybamm.util import import_optional_dependency

from deprecation import deprecated
from pybamm.expression_tree.operations.serialise import Serialise


Expand Down Expand Up @@ -156,8 +156,6 @@ def __setstate__(self, state):
self.get_esoh_solver = lru_cache()(self._get_esoh_solver)

def set_up_and_parameterise_experiment(self, solve_kwargs=None):
msg = "pybamm.simulation.set_up_and_parameterise_experiment is deprecated and not meant to be accessed by users."
warnings.warn(msg, DeprecationWarning, stacklevel=2)
self._set_up_and_parameterise_experiment(solve_kwargs=solve_kwargs)

def _set_up_and_parameterise_experiment(self, solve_kwargs=None):
Expand Down Expand Up @@ -238,11 +236,13 @@ def _set_up_and_parameterise_experiment(self, solve_kwargs=None):
parameterised_model
)

@deprecated(
deprecated_in="25.1.0",
removed_in="26.0.0",
current_version=pybamm.__version__,
details="pybamm.set_parameters is deprecated and not meant to be accessed by users.",
)
def set_parameters(self):
msg = (
"pybamm.set_parameters is deprecated and not meant to be accessed by users."
)
warnings.warn(msg, DeprecationWarning, stacklevel=2)
self._set_parameters()

def _set_parameters(self):
Expand Down
16 changes: 8 additions & 8 deletions src/pybamm/solvers/base_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import pybamm
from pybamm.expression_tree.binary_operators import _Heaviside
from pybamm import ParameterValues
from pybamm.util import deprecate_arguments


class BaseSolver:
Expand Down Expand Up @@ -1107,6 +1108,13 @@ def process_t_interp(self, t_interp):

return t_interp

@deprecate_arguments(
deprecated_args={"npts": "Use 't_eval' instead."},
deprecated_in="25.1.0",
removed_in="25.3.0",
current_version="25.1.0",
msg="Please refer to the updated documentation.",
)
def step(
self,
old_solution,
Expand Down Expand Up @@ -1179,14 +1187,6 @@ def step(
if dt <= 0:
raise pybamm.SolverError("Step time must be >0")

# Raise deprecation warning for npts and convert it to t_eval
if npts is not None:
warnings.warn(
"The 'npts' parameter is deprecated, use 't_eval' instead.",
DeprecationWarning,
stacklevel=2,
)
t_eval = np.linspace(0, dt, npts)
elif t_eval is None:
t_eval = np.array([0, dt])
elif t_eval[0] != 0 or t_eval[-1] != dt:
Expand Down
48 changes: 48 additions & 0 deletions src/pybamm/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import pickle
import timeit
import difflib
import warnings
from warnings import warn
import functools

import pybamm

Expand Down Expand Up @@ -408,3 +410,49 @@ def import_optional_dependency(module_name, attribute=None):
except ModuleNotFoundError as error:
# Raise an ModuleNotFoundError if the module or attribute is not available
raise ModuleNotFoundError(err_msg) from error


def deprecate_arguments(
deprecated_args: dict[str, str],
deprecated_in: str,
removed_in: str,
current_version: str,
msg: dict[str, str],
):
"""
Custom decorator to deprecate specific function arguments with optional custom messages.

Args:
deprecated_args (dict): Dictionary of deprecated argument names with details.
Example: {"old_arg": "Use 'new_arg' instead."}
deprecated_in (str): Version when the argument was deprecated.
removed_in (str): Version when the argument will be removed.
current_version (str): Current version of the package/module.
msg (dict, optional): Custom messages for specific deprecated arguments.
Example: {"old_arg": "Additional information about the deprecation."}
"""

def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
for arg, message in deprecated_args.items():
if arg in kwargs:
warning_message = (
f"Argument '{arg}' is deprecated since version {deprecated_in} "
f"and will be removed in version {removed_in}. (Current version: {current_version}) "
f"{message}"
)
# Append a custom message if provided in the msg dictionary
if msg and arg in msg:
warning_message += f" {msg[arg]}"

warnings.warn(
warning_message,
category=DeprecationWarning,
stacklevel=2,
)
return func(*args, **kwargs)

return wrapper

return decorator
3 changes: 2 additions & 1 deletion tests/integration/test_solvers/test_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def test_append(self):
# dt should be dimensional
for t in solution.t[1:]:
dt = t - old_t
step_solution = step_solver.step(step_solution, model, dt=dt, npts=10)
t_eval = np.linspace(0, dt, 5)
step_solution = step_solver.step(step_solution, model, dt=dt, t_eval=t_eval)
if t == solution.t[1]:
# Create voltage variable
step_solution.update("Voltage [V]")
Expand Down
20 changes: 15 additions & 5 deletions tests/unit/test_expression_tree/test_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def test_symbol_domains(self):
b.domain = "test"

def test_symbol_auxiliary_domains(self):
# Normal case with auxiliary domains
a = pybamm.Symbol(
"a",
domain="test",
Expand All @@ -80,7 +81,6 @@ def test_symbol_auxiliary_domains(self):
assert a.domain == ["test"]
assert a.secondary_domain == ["sec"]
assert a.tertiary_domain == ["tert"]
assert a.tertiary_domain == ["tert"]
assert a.quaternary_domain == ["quat"]
assert a.domains == {
"primary": ["test"],
Expand All @@ -89,22 +89,32 @@ def test_symbol_auxiliary_domains(self):
"quaternary": ["quat"],
}

# Accepting domain as list
a = pybamm.Symbol("a", domain=["t", "e", "s"])
assert a.domain == ["t", "e", "s"]

# Raise TypeError for invalid domain
with pytest.raises(TypeError):
a = pybamm.Symbol("a", domain=1)
pybamm.Symbol("a", domain=1)

# Raise DomainError for non-unique domains
b = pybamm.Symbol("b", domain="test sec")
with pytest.raises(pybamm.DomainError, match="All domains must be different"):
b.domains = {"primary": "test", "secondary": "test"}

# Raise DomainError due to overlap in auxiliary domains
with pytest.raises(pybamm.DomainError, match="All domains must be different"):
b = pybamm.Symbol(
pybamm.Symbol(
"b",
domain="test",
auxiliary_domains={"secondary": ["test sec"], "tertiary": ["test sec"]},
)

with pytest.raises(NotImplementedError, match="auxiliary_domains"):
a.auxiliary_domains
# Check for deprecation warning when accessing auxiliary_domains directly
with pytest.raises(
NotImplementedError, match="symbol.auxiliary_domains has been deprecated"
):
_ = a.auxiliary_domains

def test_symbol_methods(self):
a = pybamm.Symbol("a")
Expand Down
13 changes: 6 additions & 7 deletions tests/unit/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ def test_simple_model(self):

def test_basic_ops(self):
model = pybamm.lithium_ion.SPM()

sim = pybamm.Simulation(model)

# check that the model is unprocessed
# Check that the model is unprocessed
assert sim._mesh is None
assert sim._disc is None
V = sim.model.variables["Voltage [V]"]
assert V.has_symbol_of_classes(pybamm.Parameter)
assert not V.has_symbol_of_classes(pybamm.Matrix)

sim.set_parameters()
sim._set_parameters()
assert sim._mesh is None
assert sim._disc is None
V = sim.model_with_set_params.variables["Voltage [V]"]
assert not V.has_symbol_of_classes(pybamm.Parameter)
assert not V.has_symbol_of_classes(pybamm.Matrix)

# Make sure model is unchanged
assert sim.model != model
V = model.variables["Voltage [V]"]
Expand Down Expand Up @@ -137,9 +138,7 @@ def test_solve_already_partially_processed_model(self):

def test_reuse_commands(self):
sim = pybamm.Simulation(pybamm.lithium_ion.SPM())

sim.set_parameters()
sim.set_parameters()
sim._set_parameters()

sim.build()
sim.build()
Expand All @@ -149,7 +148,7 @@ def test_reuse_commands(self):

sim.build()
sim.solve([0, 600])
sim.set_parameters()
sim._set_parameters()

def test_set_crate(self):
model = pybamm.lithium_ion.SPM()
Expand Down
22 changes: 17 additions & 5 deletions tests/unit/test_solvers/test_casadi_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ def test_model_step(self):
)

# Step again (return 5 points)
step_sol_2 = solver.step(step_sol, model, dt, npts=5)
t_eval_2 = np.linspace(0, dt, 5)
step_sol_2 = solver.step(step_sol, model, dt, t_eval=t_eval_2)
np.testing.assert_array_equal(
step_sol_2.t, np.array([0, 1, np.nextafter(1, np.inf), 1.25, 1.5, 1.75, 2])
)
Expand Down Expand Up @@ -330,12 +331,17 @@ def test_model_step_with_input(self):

# Step with an input
dt = 0.1
step_sol = solver.step(None, model, dt, npts=5, inputs={"a": 0.1})

t_eval = np.linspace(0, dt, 5)
step_sol = solver.step(None, model, dt, t_eval=t_eval, inputs={"a": 0.1})

np.testing.assert_array_equal(step_sol.t, np.linspace(0, dt, 5))
np.testing.assert_allclose(step_sol.y.full()[0], np.exp(0.1 * step_sol.t))

# Step again with different inputs
step_sol_2 = solver.step(step_sol, model, dt, npts=5, inputs={"a": -1})
t_eval_2 = np.linspace(0, dt, 5)
step_sol_2 = solver.step(step_sol, model, dt, t_eval=t_eval_2, inputs={"a": -1})

np.testing.assert_allclose(
step_sol_2.t,
np.array([0, 0.025, 0.05, 0.075, 0.1, 0.1 + 1e-9, 0.125, 0.15, 0.175, 0.2]),
Expand Down Expand Up @@ -377,7 +383,10 @@ def test_model_step_events(self):
end_time = 5
step_solution = None
while time < end_time:
step_solution = step_solver.step(step_solution, model, dt=dt, npts=10)
t_eval_2 = np.linspace(0, dt, 5)
step_solution = step_solver.step(
step_solution, model, dt=dt, t_eval=t_eval_2
)
time += dt
np.testing.assert_array_less(step_solution.y.full()[0, :-1], 1.5)
np.testing.assert_array_less(step_solution.y.full()[-1, :-1], 2.5)
Expand Down Expand Up @@ -590,7 +599,10 @@ def test_modulo_non_smooth_events(self):
end_time = 3
step_solution = None
while time < end_time:
step_solution = step_solver.step(step_solution, model, dt=dt, npts=10)
t_eval_2 = np.linspace(0, dt, 5)
step_solution = step_solver.step(
step_solution, model, dt=dt, t_eval=t_eval_2
)
time += dt
np.testing.assert_array_less(step_solution.y[0, :-1], 0.55)
np.testing.assert_array_less(step_solution.y[-1, :-1], 1.2)
Expand Down
Loading
Loading