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
- Added functionality to create `pybamm.ParameterValues` from a [BPX standard](https://github.com/pybamm-team/BPX) JSON file ([#2555](https://github.com/pybamm-team/PyBaMM/pull/2555)).
8
+
- Allow the option "surface form" to be "differential" in the `MPM` ([#2533](https://github.com/pybamm-team/PyBaMM/pull/2533))
9
+
- Added variables "Loss of lithium due to loss of active material in negative/positive electrode [mol]". These should be included in the calculation of "total lithium in system" to make sure that lithium is truly conserved. ([#2529](https://github.com/pybamm-team/PyBaMM/pull/2529))
10
+
-`initial_soc` can now be a string "x V", in which case the simulation is initialized to start from that voltage ([#2508](https://github.com/pybamm-team/PyBaMM/pull/2508))
11
+
- The `ElectrodeSOH` solver can now calculate electrode balance based on a target "cell capacity" (requires cell capacity "Q" as input), as well as the default "cyclable cell capacity" (requires cyclable lithium capacity "Q_Li" as input). Use the keyword argument `known_value` to control which is used. ([#2508](https://github.com/pybamm-team/PyBaMM/pull/2508))
12
+
13
+
## Bug fixes
14
+
15
+
- Fixed bug with `EntryPoints` in Spyder IDE ([#2584](https://github.com/pybamm-team/PyBaMM/pull/2584))
16
+
- Fixed electrolyte conservation when options {"surface form": "algebraic"} are used
17
+
- Fixed "constant concentration" electrolyte model so that "porosity times concentration" is conserved when porosity changes ([#2529](https://github.com/pybamm-team/PyBaMM/pull/2529))
18
+
- Fix installation on `Google Colab` (`pybtex` and `Colab` issue) ([#2526](https://github.com/pybamm-team/PyBaMM/pull/2526))
19
+
20
+
## Breaking changes
21
+
22
+
- Renamed "Negative/Positive electrode SOC" to "Negative/Positive electrode stoichiometry" to avoid confusion with cell SOC ([#2529](https://github.com/pybamm-team/PyBaMM/pull/2529))
23
+
- Removed external variables and submodels. InputParameter should now be used in all cases ([#2502](https://github.com/pybamm-team/PyBaMM/pull/2502))
24
+
- Trying to use a solver to solve multiple models results in a RuntimeError exception ([#2481](https://github.com/pybamm-team/PyBaMM/pull/2481))
25
+
- Inputs for the `ElectrodeSOH` solver are now (i) "Q_Li", the total cyclable capacity of lithium in the electrodes (previously "n_Li", the total number of moles, n_Li = 3600/F \* Q_Li) (ii) "Q_n", the capacity of the negative electrode (previously "C_n"), and "Q_p", the capacity of the positive electrode (previously "C_p") ([#2508](https://github.com/pybamm-team/PyBaMM/pull/2508))
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+70-59Lines changed: 70 additions & 59 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,7 @@ Finally, if you really, really, _really_ love developing PyBaMM, have a look at
61
61
62
62
## Coding style guidelines
63
63
64
-
PyBaMM follows the [PEP8 recommendations](https://www.python.org/dev/peps/pep-0008/) for coding style. These are very common guidelines, and community tools have been developed to check how well projects implement them. We recommend using pre-commit hooks to check your code before committing it. See [installing and using pre-commit](https://github.com/pybamm-team/PyBaMM/blob/develop/CONTRIBUTING.md#installing-andusing-pre-commit) section for more details.
64
+
PyBaMM follows the [PEP8 recommendations](https://www.python.org/dev/peps/pep-0008/) for coding style. These are very common guidelines, and community tools have been developed to check how well projects implement them. We recommend using pre-commit hooks to check your code before committing it. See [installing and using pre-commit](https://github.com/pybamm-team/PyBaMM/blob/develop/CONTRIBUTING.md#installing-and-using-pre-commit) section for more details.
65
65
66
66
### Flake8
67
67
@@ -194,67 +194,76 @@ This also means that, if you can't fix the bug yourself, it will be much easier
194
194
195
195
1. Run individual test scripts instead of the whole test suite:
196
196
197
-
```bash
198
-
python tests/unit/path/to/test
199
-
```
197
+
```bash
198
+
python tests/unit/path/to/test
199
+
```
200
200
201
-
You can also run an individual test from a particular script, e.g.
201
+
You can also run an individual test from a particular script, e.g.
If you want to run several, but not all, the tests from a script, you can restrict which tests are run from a particular script by using the skipping decorator:
207
+
If you want to run several, but not all, the tests from a script, you can restrict which tests are run from a particular script by using the skipping decorator:
208
208
209
-
```python
210
-
@unittest.skip("")
211
-
deftest_bit_of_code(self):
212
-
...
213
-
```
209
+
```python
210
+
@unittest.skip("")
211
+
deftest_bit_of_code(self):
212
+
...
213
+
```
214
214
215
-
or by just commenting out all the tests you don't want to run 2. Set break points, either in your IDE or using the python debugging module. To use the latter, add the following line where you want to set the break point
215
+
or by just commenting out all the tests you don't want to run.
216
216
217
-
```python
218
-
import ipdb; ipdb.set_trace()
219
-
```
217
+
2. Set break points, either in your IDE or using the python debugging module. To use the latter, add the following line where you want to set the break point
220
218
221
-
This will start the [Python interactive debugger](https://gist.github.com/mono0926/6326015). If you want to be able to use magic commands from `ipython`, such as `%timeit`, then set
219
+
```python
220
+
import ipdb; ipdb.set_trace()
221
+
```
222
222
223
-
```python
224
-
from IPython import embed; embed(); import ipdb; ipdb.set_trace()
225
-
```
223
+
This will start the [Python interactive debugger](https://gist.github.com/mono0926/6326015). If you want to be able to use magic commands from `ipython`, such as `%timeit`, then set
226
224
227
-
at the break point instead.
228
-
Figuring out where to start the debugger is the real challenge. Some good ways to set debugging break points are:
229
-
a. Try-except blocks. Suppose the line `do_something_complicated()` is raising a `ValueError`. Then you can put a try-except block around that line as:
225
+
```python
226
+
from IPython import embed; embed(); import ipdb; ipdb.set_trace()
227
+
```
230
228
231
-
```python
232
-
try:
233
-
do_something_complicated()
234
-
exceptValueError:
235
-
import ipdb; ipdb.set_trace()
236
-
```
229
+
at the break point instead.
230
+
Figuring out where to start the debugger is the real challenge. Some good ways to set debugging break points are:
237
231
238
-
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.
239
-
b. 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:
232
+
1. Try-except blocks. Suppose the line `do_something_complicated()` is raising a `ValueError`. Then you can put a try-except block around that line as:
240
233
241
-
```python
242
-
import warnings
243
-
warnings.simplefilter("error")
244
-
```
234
+
```python
235
+
try:
236
+
do_something_complicated()
237
+
exceptValueError:
238
+
import ipdb; ipdb.set_trace()
239
+
```
245
240
246
-
Then you can use a try-except block, as in a., but with, for example, `RuntimeWarning` instead of `ValueError`.
247
-
c. Stepping through the expression tree. Most calls in PyBaMM are operations on [expression trees](https://github.com/pybamm-team/PyBaMM/blob/develop/examples/notebooks/expression_tree/expression-tree.ipynb). To view an expression tree in ipython, you can use the `render` command:
241
+
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.
248
242
249
-
```python
250
-
expression_tree.render()
251
-
```
243
+
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:
252
244
253
-
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. 3. To isolate whether a bug is in 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). 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. 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:
245
+
```python
246
+
import warnings
247
+
warnings.simplefilter("error")
248
+
```
254
249
255
-
```python3
256
-
pybamm.set_logging_level("DEBUG")
257
-
```
250
+
Then you can use a try-except block, asin a., but with, for example, `RuntimeWarning` instead of `ValueError`.
251
+
252
+
3. Stepping through the expression tree. Most calls in PyBaMM are operations on [expression trees](https://github.com/pybamm-team/PyBaMM/blob/develop/examples/notebooks/expression_tree/expression-tree.ipynb). To view an expression tree in ipython, you can use the `render` command:
253
+
254
+
```python
255
+
expression_tree.render()
256
+
```
257
+
258
+
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.
259
+
260
+
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).
261
+
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.
262
+
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:
263
+
264
+
```python3
265
+
pybamm.set_logging_level("DEBUG")
266
+
```
258
267
259
268
6. In models that inherit from`pybamm.BaseBatteryModel` (i.e. any battery model), you can use `self.process_parameters_and_discretise` to process a symbol and see what it will look like.
260
269
@@ -270,24 +279,26 @@ as above, and then use some of the profiling tools. In order of increasing detai
270
279
271
280
1. Simple timer. In ipython, the command
272
281
273
-
```
274
-
%time command_to_time()
275
-
```
282
+
```
283
+
%time command_to_time()
284
+
```
276
285
277
-
tells you how long the line `command_to_time()` takes. You can use `%timeit` instead to run the command several times and obtain more accurate timings. 2. Simple profiler. Using `%prun` instead of `%time` will give a brief profiling report 3. Detailed profiler. You can install the detailed profiler `snakeviz` through pip:
286
+
tells you how long the line `command_to_time()` takes. You can use `%timeit` instead to run the command several times and obtain more accurate timings.
278
287
279
-
```bash
280
-
pip install snakeviz
281
-
```
288
+
2. Simple profiler. Using `%prun` instead of `%time` will give a brief profiling report 3. Detailed profiler. You can install the detailed profiler `snakeviz` through pip:
282
289
283
-
and then, in ipython, run
290
+
```bash
291
+
pip install snakeviz
292
+
```
284
293
285
-
```
286
-
%load_ext snakeviz
287
-
%snakeviz command_to_time()
288
-
```
294
+
and then, in ipython, run
295
+
296
+
```
297
+
%load_ext snakeviz
298
+
%snakeviz command_to_time()
299
+
```
289
300
290
-
This will open a window in your browser with detailed profiling information.
301
+
This will open a window in your browser with detailed profiling information.
0 commit comments