You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Fixed a bug where the JaxSolver would fails when using GPU support with no input parameters ([#3423](https://github.com/pybamm-team/PyBaMM/pull/3423))
10
+
- Make pybamm importable with minimal dependencies ([#3044](https://github.com/pybamm-team/PyBaMM/pull/3044), [#3475](https://github.com/pybamm-team/PyBaMM/pull/3475))
11
+
- Fixed a bug where supplying an initial soc did not work with half cell models ([#3456](https://github.com/pybamm-team/PyBaMM/pull/3456))
- The parameter "Ambient temperature [K]" can now be given as a function of position `(y,z)` and time `t`. The "edge" and "current collector" heat transfer coefficient parameters can also depend on `(y,z)` ([#3257](https://github.com/pybamm-team/PyBaMM/pull/3257))
@@ -17,7 +30,6 @@
17
30
18
31
## Bug fixes
19
32
20
-
- Fixed a bug where the JaxSolver would fails when using GPU support with no input parameters ([#3423](https://github.com/pybamm-team/PyBaMM/pull/3423))
21
33
- Fixed a bug where empty lists passed to QuickPlot resulted in an IndexError and did not return a meaningful error message ([#3359](https://github.com/pybamm-team/PyBaMM/pull/3359))
22
34
- Fixed a bug where there was a missing thermal conductivity in the thermal pouch cell models ([#3330](https://github.com/pybamm-team/PyBaMM/pull/3330))
23
35
- Fixed a bug that caused incorrect results of “{Domain} electrode thickness change [m]” due to the absence of dimension for the variable `electrode_thickness_change`([#3329](https://github.com/pybamm-team/PyBaMM/pull/3329)).
@@ -36,7 +48,6 @@
36
48
- Error generated when invalid parameter values are passed ([#3132](https://github.com/pybamm-team/PyBaMM/pull/3132))
37
49
- Parameters in `Prada2013` have been updated to better match those given in the paper, which is a 2.3 Ah cell, instead of the mix-and-match with the 1.1 Ah cell from Lain2019 ([#3096](https://github.com/pybamm-team/PyBaMM/pull/3096))
38
50
- The `OneDimensionalX` thermal model has been updated to account for edge/tab cooling and account for the current collector volumetric heat capacity. It now gives the correct behaviour compared with a lumped model with the correct total heat transfer coefficient and surface area for cooling. ([#3042](https://github.com/pybamm-team/PyBaMM/pull/3042))
39
-
- Fixed a bug where supplying an initial soc did not work with half cell models ([#3456](https://github.com/pybamm-team/PyBaMM/pull/3456))
40
51
41
52
## Optimizations
42
53
@@ -56,7 +67,7 @@
56
67
- Added option to use an empirical hysteresis model for the diffusivity and exchange-current density ([#3194](https://github.com/pybamm-team/PyBaMM/pull/3194))
57
68
- Double-layer capacity can now be provided as a function of temperature ([#3174](https://github.com/pybamm-team/PyBaMM/pull/3174))
58
69
-`pybamm_install_jax` is deprecated. It is now replaced with `pip install pybamm[jax]` ([#3163](https://github.com/pybamm-team/PyBaMM/pull/3163))
59
-
- PyBaMM now has optional dependencies that can be installed with the pattern `pip install pybamm[option]` e.g. `pybamm[plot]` ([#3044](https://github.com/pybamm-team/PyBaMM/pull/3044))
70
+
- PyBaMM now has optional dependencies that can be installed with the pattern `pip install pybamm[option]` e.g. `pybamm[plot]` ([#3044](https://github.com/pybamm-team/PyBaMM/pull/3044), [#3475](https://github.com/pybamm-team/PyBaMM/pull/3475))
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+38-12Lines changed: 38 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -100,21 +100,52 @@ On the other hand... We _do_ want to compare several tools, to generate document
100
100
101
101
Only 'core pybamm' is installed by default. The others have to be specified explicitly when running the installation command.
102
102
103
-
### Matplotlib
103
+
### Managing Optional Dependencies and Their Imports
104
104
105
-
We use Matplotlib in PyBaMM, but with two caveats:
105
+
PyBaMM utilizes optional dependencies to allow users to choose which additional libraries they want to use. Managing these optional dependencies and their imports is essential to provide flexibility to PyBaMM users.
106
106
107
-
First, Matplotlib should only be used in plotting methods, and these should _never_ be called by other PyBaMM methods. So users who don't like Matplotlib will not be forced to use it in any way. Use in notebooks is OK and encouraged.
107
+
PyBaMM provides a utility function `have_optional_dependency`, to check for the availability of optional dependencies within methods. This function can be used to conditionally import optional dependencies only if they are available. Here's how to use it:
108
108
109
-
Second, Matplotlib should never be imported at the module level, but always inside methods. For example:
109
+
Optional dependencies should never be imported at the module level, but always inside methods. For example:
110
110
111
111
```
112
-
def plot_great_things(self, x, y, z):
113
-
import matplotlib.pyplot as pl
112
+
def use_pybtex(x,y,z):
113
+
pybtex = have_optional_dependency("pybtex")
114
114
...
115
115
```
116
116
117
-
This allows people to (1) use PyBaMM without ever importing Matplotlib and (2) configure Matplotlib's back-end in their scripts, which _must_ be done before e.g. `pyplot` is first imported.
117
+
While importing a specific module instead of an entire package/library:
This allows people to (1) use PyBaMM without importing optional dependencies by default and (2) configure module-dependent functionalities in their scripts, which _must_ be done before e.g. `print_citations` method is first imported.
126
+
127
+
**Writing Tests for Optional Dependencies**
128
+
129
+
Whenever a new optional dependency is added for optional functionality, it is recommended to write a corresponding unit test in `test_util.py`. This ensures that an error is raised upon the absence of said dependency. Here's an example:
130
+
131
+
```python
132
+
from tests import TestCase
133
+
import pybamm
134
+
135
+
136
+
classTestUtil(TestCase):
137
+
deftest_optional_dependency(self):
138
+
# Test that an error is raised when pybtex is not available
139
+
withself.assertRaisesRegex(
140
+
ModuleNotFoundError, "Optional dependency pybtex is not available"
141
+
):
142
+
sys.modules["pybtex"] =None
143
+
pybamm.function_using_pybtex(x, y, z)
144
+
145
+
# Test that the function works when pybtex is available
@@ -266,7 +297,6 @@ This also means that, if you can't fix the bug yourself, it will be much easier
266
297
```
267
298
268
299
This will start the debugger at the point where the `ValueError` was raised, and allow you to investigate further. Sometimes, it is more informative to put the try-except block further up the call stack than exactly where the error is raised.
269
-
270
300
2. Warnings. If functions are raising warnings instead of errors, it can be hard to pinpoint where this is coming from. Here, you can use the `warnings` module to convert warnings to errors:
271
301
272
302
```python
@@ -276,19 +306,15 @@ This also means that, if you can't fix the bug yourself, it will be much easier
276
306
```
277
307
278
308
Then you can use a try-except block, asin a., but with, for example, `RuntimeWarning` instead of `ValueError`.
279
-
280
309
3. Stepping through the expression tree. Most calls in PyBaMM are operations on [expression trees](https://github.com/pybamm-team/PyBaMM/blob/develop/docs/source/examples/notebooks/expression_tree/expression-tree.ipynb). To view an expression tree in ipython, you can use the `render` command:
281
310
282
311
```python
283
312
expression_tree.render()
284
313
```
285
314
286
315
You can then step through the expression tree, using the `children` attribute, to pinpoint exactly where a bug is coming from. For example, if`expression_tree.jac(y)`is failing, you can check `expression_tree.children[0].jac(y)`, then `expression_tree.children[0].children[0].jac(y)`, etc.
287
-
288
316
3. To isolate whether a bug isin a model, its Jacobian or its simplified version, you can set the `use_jacobian`and/or`use_simplify` attributes of the model to `False` (they are both `True` by default for most models).
289
-
290
317
4. If a model isn't giving the answer you expect, you can try comparing it to other models. For example, you can investigate parameter limits in which two models should give the same answer by setting some parameters to be small or zero. The `StandardOutputComparison` class can be used to compare some standard outputs from battery models.
291
-
292
318
5. To get more information about what is going on under the hood, and hence understand what is causing the bug, you can set the [logging](https://realpython.com/python-logging/) level to `DEBUG` by adding the following line to your test or script:
0 commit comments