Repository: pybamm-team/PyBaMM

Issue:
[Bug]:  Error if variable bounds contain an `InputParameter`
Now that we switched to using dimensional variables, if you have an `InputParameter` in the bounds of a variable you can't discretise it. We should skip the bounds in this case IMO, otherwise, you would need to re-discretize each time you changed the input.

Code to reproduce this:

```python3
import pybamm
model = pybamm.lithium_ion.SPM()
param = pybamm.ParameterValues("Chen2020")
param["Maximum concentration in positive electrode [mol.m-3]"] = "[input]"
sim = pybamm.Simulation(model, parameter_values=param)
sim.solve([0, 3600], inputs = {"Maximum concentration in positive electrode [mol.m-3]": 65000})
```


Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 16fd0a486..b3bb9a48f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@
 
 ## Bug fixes
 
+- Fixed a bug where variable bounds could not contain `InputParameters` ([#2795](https://github.com/pybamm-team/PyBaMM/pull/2795))
 - Improved `model.latexify()` to have a cleaner and more readable output ([#2764](https://github.com/pybamm-team/PyBaMM/pull/2764))
 - Fixed electrolyte conservation in the case of concentration-dependent transference number ([#2758](https://github.com/pybamm-team/PyBaMM/pull/2758))
 - Fixed `plot_voltage_components` so that the sum of overpotentials is now equal to the voltage ([#2740](https://github.com/pybamm-team/PyBaMM/pull/2740))
diff --git a/pybamm/discretisations/discretisation.py b/pybamm/discretisations/discretisation.py
index 0f841e9ad..5dfd2405c 100644
--- a/pybamm/discretisations/discretisation.py
+++ b/pybamm/discretisations/discretisation.py
@@ -297,9 +297,23 @@ class Discretisation(object):
             # Add to slices
             y_slices[variable].append(slice(start, end))
             y_slices_explicit[variable].append(slice(start, end))
+
             # Add to bounds
-            lower_bounds.extend([variable.bounds[0].evaluate()] * (end - start))
-            upper_bounds.extend([variable.bounds[1].evaluate()] * (end - start))
+            def evaluate_bound(bound, side):
+                if bound.has_symbol_of_classes(pybamm.InputParameter):
+                    if side == "lower":
+                        return -np.inf
+                    elif side == "upper":
+                        return np.inf
+                else:
+                    return bound.evaluate()
+
+            lower_bounds.extend(
+                [evaluate_bound(variable.bounds[0], "lower")] * (end - start)
+            )
+            upper_bounds.extend(
+                [evaluate_bound(variable.bounds[1], "upper")] * (end - start)
+            )
             # Increment start
             start = end
 


Test patch:
diff --git a/tests/unit/test_discretisations/test_discretisation.py b/tests/unit/test_discretisations/test_discretisation.py
index 9b19c773a..aed16f9c9 100644
--- a/tests/unit/test_discretisations/test_discretisation.py
+++ b/tests/unit/test_discretisations/test_discretisation.py
@@ -142,6 +142,14 @@ class TestDiscretise(unittest.TestCase):
         with self.assertRaisesRegex(TypeError, "y_slices should be"):
             disc.y_slices = 1
 
+        # bounds with an InputParameter
+        a = pybamm.InputParameter("a")
+        b = pybamm.InputParameter("b")
+        v = pybamm.Variable("v", domain=whole_cell, bounds=(a, b))
+        disc.set_variable_slices([v])
+        np.testing.assert_array_equal(disc.bounds[0], [-np.inf] * 100)
+        np.testing.assert_array_equal(disc.bounds[1], [np.inf] * 100)
+
     def test_process_symbol_base(self):
         # create discretisation
         mesh = get_mesh_for_testing()