Repository: pybamm-team/PyBaMM
Pull request #2902 (2023-04-26 20:55:56)

remove chemistry from parameter set dict
# Description

Fixes a small bug when inputting parameters as a dictionary

## 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` (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 run-tests.py --all`
- [ ] The documentation builds: `$ python run-tests.py --doctest`

You can run unit and doctests together at once, using `$ python run-tests.py --quick`.

## Further checks:

- [ ] Code is commented, particularly in hard-to-understand areas
- [ ] Tests added that prove fix is effective or that feature works



Patch:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 44beebc9a..f3958c414 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -9,7 +9,7 @@ repos:
       - id: black
 
   - repo: https://github.com/charliermarsh/ruff-pre-commit
-    rev: "v0.0.262"
+    rev: "v0.0.261"
     hooks:
       - id: ruff
         args: [--ignore=E741, --exclude=__init__.py]
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 44f05b3bc..c4b24ce61 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@
 
 ## Bug fixes
 
+- Parameter sets can now contain the key "chemistry", and will ignore its value (this previously would give errors in some cases) ([#2901](https://github.com/pybamm-team/PyBaMM/pull/2901))
 - Fixed a bug in the discretisation of initial conditions of a scaled variable ([#2856](https://github.com/pybamm-team/PyBaMM/pull/2856))
 - Fixed keyerror on "all" when getting sensitivities from IDAKLU solver([#2883](https://github.com/pybamm-team/PyBaMM/pull/2883))
 
diff --git a/README.md b/README.md
index c5137505a..3b29c6d31 100644
--- a/README.md
+++ b/README.md
@@ -229,7 +229,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
     <tr>
       <td align="center" valign="top" width="14.28%"><a href="https://github.com/chuckliu1979"><img src="https://avatars.githubusercontent.com/u/13491954?v=4?s=100" width="100px;" alt="Chuck Liu"/><br /><sub><b>Chuck Liu</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/issues?q=author%3Achuckliu1979" title="Bug reports">🐛</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=chuckliu1979" title="Code">💻</a></td>
       <td align="center" valign="top" width="14.28%"><a href="https://github.com/partben"><img src="https://avatars.githubusercontent.com/u/88316576?v=4?s=100" width="100px;" alt="partben"/><br /><sub><b>partben</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=partben" title="Documentation">📖</a></td>
-      <td align="center" valign="top" width="14.28%"><a href="https://wigging.me"><img src="https://avatars.githubusercontent.com/u/6828967?v=4?s=100" width="100px;" alt="Gavin Wiggins"/><br /><sub><b>Gavin Wiggins</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/issues?q=author%3Awigging" title="Bug reports">🐛</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=wigging" title="Code">💻</a></td>
+      <td align="center" valign="top" width="14.28%"><a href="https://gavinw.me"><img src="https://avatars.githubusercontent.com/u/6828967?v=4?s=100" width="100px;" alt="Gavin Wiggins"/><br /><sub><b>Gavin Wiggins</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/issues?q=author%3Awigging" title="Bug reports">🐛</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=wigging" title="Code">💻</a></td>
       <td align="center" valign="top" width="14.28%"><a href="https://github.com/dion-w"><img src="https://avatars.githubusercontent.com/u/91852142?v=4?s=100" width="100px;" alt="Dion Wilde"/><br /><sub><b>Dion Wilde</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/issues?q=author%3Adion-w" title="Bug reports">🐛</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=dion-w" title="Code">💻</a></td>
       <td align="center" valign="top" width="14.28%"><a href="https://www.ehtec.co"><img src="https://avatars.githubusercontent.com/u/48386220?v=4?s=100" width="100px;" alt="Elias Hohl"/><br /><sub><b>Elias Hohl</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=ehtec" title="Code">💻</a></td>
       <td align="center" valign="top" width="14.28%"><a href="https://github.com/KAschad"><img src="https://avatars.githubusercontent.com/u/93784399?v=4?s=100" width="100px;" alt="KAschad"/><br /><sub><b>KAschad</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/issues?q=author%3AKAschad" title="Bug reports">🐛</a></td>
diff --git a/casadi-headers b/casadi-headers
new file mode 160000
index 000000000..c31bbfbb5
--- /dev/null
+++ b/casadi-headers
@@ -0,0 +1,1 @@
+Subproject commit c31bbfbb5149f090ab30e6cba6898150525e9dfe
diff --git a/pybamm/parameters/parameter_values.py b/pybamm/parameters/parameter_values.py
index d02f18787..80626be95 100644
--- a/pybamm/parameters/parameter_values.py
+++ b/pybamm/parameters/parameter_values.py
@@ -70,12 +70,14 @@ class ParameterValues:
                 )
                 self.update_from_chemistry(values)
             else:
+                # Remove chemistry if present
+                values.pop("chemistry", None)
                 self.update(values, check_already_exists=False)
         else:
             # Check if values is a named parameter set
             if isinstance(values, str) and values in pybamm.parameter_sets:
                 values = pybamm.parameter_sets[values]
-                values.pop("chemistry")
+                values.pop("chemistry", None)
                 self.update(values, check_already_exists=False)
 
             else:
diff --git a/pybamm/simulation.py b/pybamm/simulation.py
index 9ae217552..d61b775c6 100644
--- a/pybamm/simulation.py
+++ b/pybamm/simulation.py
@@ -8,7 +8,6 @@ import copy
 import warnings
 import sys
 from functools import lru_cache
-import tqdm
 
 
 def is_notebook():
@@ -511,7 +510,6 @@ class Simulation:
         starting_solution=None,
         initial_soc=None,
         callbacks=None,
-        showprogress=False,
         **kwargs,
     ):
         """
@@ -559,10 +557,6 @@ class Simulation:
         callbacks : list of callbacks, optional
             A list of callbacks to be called at each time step. Each callback must
             implement all the methods defined in :class:`pybamm.callbacks.BaseCallback`.
-        showprogress : bool, optional
-            Whether to show a progress bar for cycling. If true, shows a progress bar
-            for cycles. Has no effect when not used with an experiment.
-            Default is False.
         **kwargs
             Additional key-word arguments passed to `solver.solve`.
             See :meth:`pybamm.BaseSolver.solve`.
@@ -704,13 +698,7 @@ class Simulation:
             num_cycles = len(self.experiment.cycle_lengths)
             feasible = True  # simulation will stop if experiment is infeasible
             for cycle_num, cycle_length in enumerate(
-                # tqdm is the progress bar.
-                tqdm.tqdm(
-                    self.experiment.cycle_lengths,
-                    disable=(not showprogress),
-                    desc="Cycling",
-                ),
-                start=1,
+                self.experiment.cycle_lengths, start=1
             ):
                 logs["cycle number"] = (
                     cycle_num + cycle_offset,
diff --git a/requirements.txt b/requirements.txt
index cbc60dddb..d2914dc80 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -9,7 +9,6 @@ imageio>=2.9.0
 pybtex>=0.24.0
 sympy >= 1.8
 bpx
-tqdm
 # Note: Matplotlib is loaded for debug plots but to ensure pybamm runs
 # on systems without an attached display it should never be imported
 # outside of plot() methods.
diff --git a/setup.py b/setup.py
index 331f9f33a..110b53071 100644
--- a/setup.py
+++ b/setup.py
@@ -215,7 +215,6 @@ setup(
         "pybtex>=0.24.0",
         "sympy>=1.8",
         "bpx",
-        "tqdm",
         # Note: Matplotlib is loaded for debug plots, but to ensure pybamm runs
         # on systems without an attached display, it should never be imported
         # outside of plot() methods.


Test patch:
diff --git a/tests/unit/test_experiments/test_simulation_with_experiment.py b/tests/unit/test_experiments/test_simulation_with_experiment.py
index a48f6f08e..fd612a983 100644
--- a/tests/unit/test_experiments/test_simulation_with_experiment.py
+++ b/tests/unit/test_experiments/test_simulation_with_experiment.py
@@ -342,21 +342,6 @@ class TestSimulationExperiment(TestCase):
         # all but the last value should be above the termination condition
         np.testing.assert_array_less(5.04, C[:-1])
 
-    def test_run_experiment_with_pbar(self):
-        # The only thing to test here is for errors.
-        experiment = pybamm.Experiment(
-            [
-                (
-                    "Discharge at 1C for 1 sec",
-                    "Charge at 1C for 1 sec",
-                ),
-            ]
-            * 10,
-        )
-        model = pybamm.lithium_ion.SPM()
-        sim = pybamm.Simulation(model, experiment=experiment)
-        sim.solve(showprogress=True)
-
     def test_run_experiment_termination_voltage(self):
         # with percent
         experiment = pybamm.Experiment(
diff --git a/tests/unit/test_parameters/test_parameter_values.py b/tests/unit/test_parameters/test_parameter_values.py
index db9f8b303..eb267ec1e 100644
--- a/tests/unit/test_parameters/test_parameter_values.py
+++ b/tests/unit/test_parameters/test_parameter_values.py
@@ -56,6 +56,10 @@ class TestParameterValues(TestCase):
         self.assertIn("a", param.keys())
         self.assertIn(1, param.values())
 
+        # from dict "chemistry" key gets removed
+        param = pybamm.ParameterValues({"a": 1, "chemistry": "lithium-ion"})
+        self.assertNotIn("chemistry", param.keys())
+
         # from file
         param = pybamm.ParameterValues(
             "lithium_ion/testing_only/positive_electrodes/lico2_Ai2020/parameters.csv"