Repository: pybamm-team/PyBaMM
Pull request #4834 (2025-02-11 00:02:22)

rename CrateTermination to CRateTermination because the step is CRate
# Description

I noticed today that to use a step for c-rate you call `pybamm.step.CRate` but to create a termination you use `pybamm.step.CrateTermination`. This is inconsistent,  so this pr fixes it.

Fixes # (issue)

## Type of change

Please add a line in the relevant section of [CHANGELOG.md](https://github.com/pybamm-team/PyBaMM/blob/develop/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](https://github.com/pybamm-team/PyBaMM/blob/develop/CONTRIBUTING.md#installing-and-using-pre-commit) for how to set this up to run automatically when committing locally, in just two lines of code)
- [ ] All tests pass: `$ python -m pytest` (or `$ nox -s tests`)
- [ ] The documentation builds: `$ python -m pytest --doctest-plus src` (or `$ nox -s doctests`)

You can run integration tests, unit tests, and doctests together at once, using `$ 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


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/pybamm-team/PyBaMM/pull/4834?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pybamm-team) Report
Attention: Patch coverage is `62.50000%` with `3 lines` in your changes missing coverage. Please review.
> Project coverage is 98.68%. Comparing base [(`b8877b4`)](https://app.codecov.io/gh/pybamm-team/PyBaMM/commit/b8877b47814d72ae3ddeabf80e72dacbf84e1761?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pybamm-team) to head [(`b2b7fd7`)](https://app.codecov.io/gh/pybamm-team/PyBaMM/commit/b2b7fd7d25a5a5ed27d614d9ed03325a44c31100?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pybamm-team).
> Report is 3 commits behind head on develop.

| [Files with missing lines](https://app.codecov.io/gh/pybamm-team/PyBaMM/pull/4834?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pybamm-team) | Patch % | Lines |
|---|---|---|
| [src/pybamm/experiment/step/step\_termination.py](https://app.codecov.io/gh/pybamm-team/PyBaMM/pull/4834?src=pr&el=tree&filepath=src%2Fpybamm%2Fexperiment%2Fstep%2Fstep_termination.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pybamm-team#diff-c3JjL3B5YmFtbS9leHBlcmltZW50L3N0ZXAvc3RlcF90ZXJtaW5hdGlvbi5weQ==) | 57.14% | [3 Missing :warning: ](https://app.codecov.io/gh/pybamm-team/PyBaMM/pull/4834?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pybamm-team) |

<details><summary>Additional details and impacted files</summary>


```diff
@@             Coverage Diff             @@
##           develop    #4834      +/-   ##
===========================================
- Coverage    98.70%   98.68%   -0.02%     
===========================================
  Files          303      303              
  Lines        23312    23320       +8     
===========================================
+ Hits         23009    23014       +5     
- Misses         303      306       +3     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/pybamm-team/PyBaMM/pull/4834?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pybamm-team).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pybamm-team).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8d8712134..583f63f12 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,10 @@
 - Added 'get_summary_variables' to return dictionary of computed summary variables ([#4824](https://github.com/pybamm-team/PyBaMM/pull/4824))
 - Added support for particle size distributions combined with particle mechanics. ([#4807](https://github.com/pybamm-team/PyBaMM/pull/4807))
 
+## Breaking changes
+
+- Deprecated `CrateTermination` and renamed it to `CRateTermination`. ([#4834](https://github.com/pybamm-team/PyBaMM/pull/4834))
+
 # [v25.1.1](https://github.com/pybamm-team/PyBaMM/tree/v25.1.1) - 2025-01-20
 
 ## Features
diff --git a/docs/source/api/experiment/experiment_steps.rst b/docs/source/api/experiment/experiment_steps.rst
index ca26b02a4..3a1d2d78d 100644
--- a/docs/source/api/experiment/experiment_steps.rst
+++ b/docs/source/api/experiment/experiment_steps.rst
@@ -37,7 +37,7 @@ Standard step termination events are implemented by the following classes, which
 called when the termination is specified by a specific string. These classes can be
 either be called directly or via the string format specified in the class docstring
 
-.. autoclass:: pybamm.step.CrateTermination
+.. autoclass:: pybamm.step.CRateTermination
     :members:
 
 .. autoclass:: pybamm.step.CurrentTermination
diff --git a/src/pybamm/experiment/step/__init__.py b/src/pybamm/experiment/step/__init__.py
index b2613a50d..0ee7f4a1e 100644
--- a/src/pybamm/experiment/step/__init__.py
+++ b/src/pybamm/experiment/step/__init__.py
@@ -1,5 +1,5 @@
 from .steps import *
 from .base_step import BaseStep, BaseStepExplicit, BaseStepImplicit
-from .step_termination import BaseTermination, CurrentTermination, VoltageTermination, CustomTermination, CrateTermination, _read_termination
+from .step_termination import BaseTermination, CurrentTermination, VoltageTermination, CustomTermination, CRateTermination, CrateTermination, _read_termination
 
 __all__ = ['base_step', 'step_termination', 'steps']
diff --git a/src/pybamm/experiment/step/step_termination.py b/src/pybamm/experiment/step/step_termination.py
index a17bae87f..06ec5359b 100644
--- a/src/pybamm/experiment/step/step_termination.py
+++ b/src/pybamm/experiment/step/step_termination.py
@@ -1,4 +1,5 @@
 import pybamm
+from warnings import warn
 
 
 class BaseTermination:
@@ -43,7 +44,7 @@ class BaseTermination:
             return False
 
 
-class CrateTermination(BaseTermination):
+class CRateTermination(BaseTermination):
     """
     Termination based on C-rate, created when a string termination of the C-rate type
     (e.g. "C/10") is provided
@@ -60,6 +61,20 @@ class CrateTermination(BaseTermination):
         return event
 
 
+class CrateTermination(CRateTermination):
+    """
+    Termination based on C-rate, created when a string termination of the C-rate type
+    (e.g. "C/10") is provided
+    """
+
+    def __init__(self, value, operator=None):
+        super().__init__(value, operator)
+        warning = DeprecationWarning(
+            "CrateTermination is deprecated and will be removed in a future release. Use CRateTermination instead."
+        )
+        warn(warning, stacklevel=2)
+
+
 class CurrentTermination(BaseTermination):
     """
     Termination based on current, created when a string termination of the current type
@@ -193,6 +208,6 @@ def _read_termination(termination):
     termination_class = {
         "current": CurrentTermination,
         "voltage": VoltageTermination,
-        "C-rate": CrateTermination,
+        "C-rate": CRateTermination,
     }[typ]
     return termination_class(value)


Test patch:
diff --git a/tests/unit/test_experiments/test_experiment_step_termination.py b/tests/unit/test_experiments/test_experiment_step_termination.py
index 650babf50..95ac9d812 100644
--- a/tests/unit/test_experiments/test_experiment_step_termination.py
+++ b/tests/unit/test_experiments/test_experiment_step_termination.py
@@ -15,3 +15,16 @@ class TestExperimentStepTermination:
         assert term == pybamm.step.BaseTermination(1)
         assert term != pybamm.step.BaseTermination(2)
         assert term != pybamm.step.CurrentTermination(1)
+
+    def test_c_rate_termination(self):
+        term = pybamm.step.CRateTermination(0.02)
+        assert term.value == 0.02
+        assert term.operator is None
+        variables = {"C-rate": pybamm.Scalar(0.02)}
+        assert term.get_event(variables, None).evaluate() == 0
+        with pytest.warns(DeprecationWarning):
+            term_old = pybamm.step.CrateTermination(0.02)
+            assert (
+                term.get_event(variables, None).evaluate()
+                == term_old.get_event(variables, None).evaluate()
+            )
diff --git a/tests/unit/test_experiments/test_experiment_steps.py b/tests/unit/test_experiments/test_experiment_steps.py
index e79b18d47..a4026fa6e 100644
--- a/tests/unit/test_experiments/test_experiment_steps.py
+++ b/tests/unit/test_experiments/test_experiment_steps.py
@@ -163,7 +163,7 @@ class TestExperimentSteps:
                 "value": 3,
                 "type": "Voltage",
                 "duration": 3600 * 24,
-                "termination": [pybamm.step.CrateTermination(0.02)],
+                "termination": [pybamm.step.CRateTermination(0.02)],
             },
             {
                 "type": "CRate",