Repository: pybamm-team/PyBaMM (python)

Issue:
Rename `set_events`
As discussed in the PR #4254, `set_event` should be renamed because of misleading.

              This adds a side effect to what would be expected to be a simple setter. At minimum it should be changed to `append_events()` or `add_events()`. Was there an actual bug that this was fixing or just not sure if it would cause issues?

_Originally posted by @kratman in https://github.com/pybamm-team/PyBaMM/pull/4254#discussion_r1672332716_
            

Pull request description:
Renames `set_events` to `add_events_from`
# Description

I have renamed `set_events` to `add_events_from`  in all occurrences

Fixes #4266 

## 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:

- [x] 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)
- [x] All relevant tests pass, except latxeify which are unrelated.
- [x] The documentation builds: `$ python run-tests.py --doctest` (or `$ nox -s doctests`)




Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5203229bd..7764a3b24 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,9 @@
 ## Optimizations
 - Removed the `start_step_offset` setting and disabled minimum `dt` warnings for drive cycles with the (`IDAKLUSolver`). ([#4416](https://github.com/pybamm-team/PyBaMM/pull/4416))
 
+## Breaking changes
+- Renamed `set_events` function to `add_events_from` to better reflect its purpose. ([#4421](https://github.com/pybamm-team/PyBaMM/pull/4421))
+
 # [v24.9.0](https://github.com/pybamm-team/PyBaMM/tree/v24.9.0) - 2024-09-03
 
 ## Features
diff --git a/src/pybamm/models/base_model.py b/src/pybamm/models/base_model.py
index 0d4638e17..989465e37 100644
--- a/src/pybamm/models/base_model.py
+++ b/src/pybamm/models/base_model.py
@@ -757,7 +757,7 @@ class BaseModel:
                 f"Setting initial conditions for {submodel_name} submodel ({self.name})"
             )
             submodel.set_initial_conditions(self.variables)
-            submodel.set_events(self.variables)
+            submodel.add_events_from(self.variables)
             pybamm.logger.verbose(f"Updating {submodel_name} submodel ({self.name})")
             self.update(submodel)
             self.check_no_repeated_keys()
diff --git a/src/pybamm/models/full_battery_models/base_battery_model.py b/src/pybamm/models/full_battery_models/base_battery_model.py
index ccda594b1..e0ade7b42 100644
--- a/src/pybamm/models/full_battery_models/base_battery_model.py
+++ b/src/pybamm/models/full_battery_models/base_battery_model.py
@@ -1033,7 +1033,7 @@ class BaseBatteryModel(pybamm.BaseModel):
                 f"Setting initial conditions for {submodel_name} submodel ({self.name})"
             )
             submodel.set_initial_conditions(self.variables)
-            submodel.set_events(self.variables)
+            submodel.add_events_from(self.variables)
             pybamm.logger.verbose(f"Updating {submodel_name} submodel ({self.name})")
             self.update(submodel)
             self.check_no_repeated_keys()
diff --git a/src/pybamm/models/submodels/base_submodel.py b/src/pybamm/models/submodels/base_submodel.py
index e120691ed..d5e313e15 100644
--- a/src/pybamm/models/submodels/base_submodel.py
+++ b/src/pybamm/models/submodels/base_submodel.py
@@ -221,7 +221,7 @@ class BaseSubModel(pybamm.BaseModel):
         """
         pass
 
-    def set_events(self, variables):
+    def add_events_from(self, variables):
         """
         A method to set events related to the state of submodel variable. Note: this
         method modifies the state of self.events. Unless overwritten by a submodel, the
diff --git a/src/pybamm/models/submodels/electrolyte_diffusion/constant_concentration.py b/src/pybamm/models/submodels/electrolyte_diffusion/constant_concentration.py
index eee441446..006619e8b 100644
--- a/src/pybamm/models/submodels/electrolyte_diffusion/constant_concentration.py
+++ b/src/pybamm/models/submodels/electrolyte_diffusion/constant_concentration.py
@@ -76,6 +76,6 @@ class ConstantConcentration(BaseElectrolyteDiffusion):
             }
         }
 
-    def set_events(self, variables):
+    def add_events_from(self, variables):
         # No event since the concentration is constant
         pass
diff --git a/src/pybamm/models/submodels/equivalent_circuit_elements/diffusion_element.py b/src/pybamm/models/submodels/equivalent_circuit_elements/diffusion_element.py
index c7f1b4bcd..bf9a18387 100644
--- a/src/pybamm/models/submodels/equivalent_circuit_elements/diffusion_element.py
+++ b/src/pybamm/models/submodels/equivalent_circuit_elements/diffusion_element.py
@@ -102,7 +102,7 @@ class DiffusionElement(pybamm.BaseSubModel):
         z = variables["Distributed SoC"]
         self.initial_conditions = {z: self.param.initial_soc}
 
-    def set_events(self, variables):
+    def add_events_from(self, variables):
         z_surf = variables["Surface SoC"]
         self.events += [
             pybamm.Event("Minimum surface SoC", z_surf),
diff --git a/src/pybamm/models/submodels/equivalent_circuit_elements/ocv_element.py b/src/pybamm/models/submodels/equivalent_circuit_elements/ocv_element.py
index 9d1adf3d5..901b63cf7 100644
--- a/src/pybamm/models/submodels/equivalent_circuit_elements/ocv_element.py
+++ b/src/pybamm/models/submodels/equivalent_circuit_elements/ocv_element.py
@@ -54,7 +54,7 @@ class OCVElement(pybamm.BaseSubModel):
         soc = variables["SoC"]
         self.initial_conditions = {soc: self.param.initial_soc}
 
-    def set_events(self, variables):
+    def add_events_from(self, variables):
         soc = variables["SoC"]
         self.events += [
             pybamm.Event("Minimum SoC", soc),
diff --git a/src/pybamm/models/submodels/equivalent_circuit_elements/voltage_model.py b/src/pybamm/models/submodels/equivalent_circuit_elements/voltage_model.py
index 380902fca..89f8904f3 100644
--- a/src/pybamm/models/submodels/equivalent_circuit_elements/voltage_model.py
+++ b/src/pybamm/models/submodels/equivalent_circuit_elements/voltage_model.py
@@ -54,7 +54,7 @@ class VoltageModel(pybamm.BaseSubModel):
 
         return variables
 
-    def set_events(self, variables):
+    def add_events_from(self, variables):
         voltage = variables["Voltage [V]"]
 
         # Add voltage events
diff --git a/src/pybamm/models/submodels/interface/interface_utilisation/current_driven_utilisation.py b/src/pybamm/models/submodels/interface/interface_utilisation/current_driven_utilisation.py
index bbd9af4fb..e78520488 100644
--- a/src/pybamm/models/submodels/interface/interface_utilisation/current_driven_utilisation.py
+++ b/src/pybamm/models/submodels/interface/interface_utilisation/current_driven_utilisation.py
@@ -89,7 +89,7 @@ class CurrentDriven(BaseModel):
 
         self.initial_conditions = {u: u_init}
 
-    def set_events(self, variables):
+    def add_events_from(self, variables):
         domain, Domain = self.domain_Domain
 
         if self.reaction_loc == "full electrode":
diff --git a/src/pybamm/models/submodels/particle_mechanics/crack_propagation.py b/src/pybamm/models/submodels/particle_mechanics/crack_propagation.py
index 3bb9ecb7e..b51f1d1eb 100644
--- a/src/pybamm/models/submodels/particle_mechanics/crack_propagation.py
+++ b/src/pybamm/models/submodels/particle_mechanics/crack_propagation.py
@@ -102,7 +102,7 @@ class CrackPropagation(BaseMechanics):
             l_cr_0 = pybamm.PrimaryBroadcast(l_cr_0, f"{domain} electrode")
         self.initial_conditions = {l_cr: l_cr_0}
 
-    def set_events(self, variables):
+    def add_events_from(self, variables):
         domain, Domain = self.domain_Domain
 
         if self.x_average is True:
diff --git a/src/pybamm/models/submodels/porosity/constant_porosity.py b/src/pybamm/models/submodels/porosity/constant_porosity.py
index 0b9f3c0da..6d6b93d76 100644
--- a/src/pybamm/models/submodels/porosity/constant_porosity.py
+++ b/src/pybamm/models/submodels/porosity/constant_porosity.py
@@ -27,6 +27,6 @@ class Constant(BaseModel):
 
         return variables
 
-    def set_events(self, variables):
+    def add_events_from(self, variables):
         # No events since porosity is constant
         pass
diff --git a/src/pybamm/models/submodels/porosity/reaction_driven_porosity.py b/src/pybamm/models/submodels/porosity/reaction_driven_porosity.py
index fc69d0f1f..989c90cd9 100644
--- a/src/pybamm/models/submodels/porosity/reaction_driven_porosity.py
+++ b/src/pybamm/models/submodels/porosity/reaction_driven_porosity.py
@@ -64,7 +64,7 @@ class ReactionDriven(BaseModel):
 
         return variables
 
-    def set_events(self, variables):
+    def add_events_from(self, variables):
         eps_p = variables["Positive electrode porosity"]
         self.events.append(
             pybamm.Event(
diff --git a/src/pybamm/models/submodels/porosity/reaction_driven_porosity_ode.py b/src/pybamm/models/submodels/porosity/reaction_driven_porosity_ode.py
index 476845f05..f82a73ae6 100644
--- a/src/pybamm/models/submodels/porosity/reaction_driven_porosity_ode.py
+++ b/src/pybamm/models/submodels/porosity/reaction_driven_porosity_ode.py
@@ -94,7 +94,7 @@ class ReactionDrivenODE(BaseModel):
             eps = variables["Porosity"]
             self.initial_conditions = {eps: self.param.epsilon_init}
 
-    def set_events(self, variables):
+    def add_events_from(self, variables):
         for domain in self.options.whole_cell_domains:
             if domain == "separator":
                 continue


Test patch:
diff --git a/tests/unit/test_models/test_base_model.py b/tests/unit/test_models/test_base_model.py
index 4d5f71201..d50cd66d2 100644
--- a/tests/unit/test_models/test_base_model.py
+++ b/tests/unit/test_models/test_base_model.py
@@ -231,7 +231,7 @@ class TestBaseModel(unittest.TestCase):
                 u = variables["u"]
                 self.initial_conditions = {u: c}
 
-            def set_events(self, variables):
+            def add_events_from(self, variables):
                 e = pybamm.InputParameter("e")
                 u = variables["u"]
                 self.events = [pybamm.Event("u=e", u - e)]
@@ -1178,7 +1178,7 @@ class TestBaseModel(unittest.TestCase):
                 v = variables["v"]
                 self.initial_conditions = {u: 0, v: 0}
 
-            def set_events(self, variables):
+            def add_events_from(self, variables):
                 u = variables["u"]
                 self.events.append(
                     pybamm.Event(