Skip to content

Commit e8a9c64

Browse files
committed
Merge branch 'develop' of https://github.com/pybamm-team/PyBaMM into issue-2783-benchmarks
2 parents 84cc3fc + 7c69f1d commit e8a9c64

File tree

11 files changed

+153
-18
lines changed

11 files changed

+153
-18
lines changed

.github/workflows/test_on_push.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
fail-fast: false
4747
matrix:
4848
os: [ubuntu-latest, macos-latest, windows-latest]
49-
python-version: [3.8, 3.9]
49+
python-version: ["3.8", "3.9", "3.10", "3.11"]
5050

5151
steps:
5252
- uses: actions/checkout@v3
@@ -89,7 +89,7 @@ jobs:
8989
if: matrix.os == 'ubuntu-latest'
9090
run: tox -e pybamm-requires
9191

92-
- name: Run unit tests for GNU/Linux with Python 3.8
92+
- name: Run unit tests for GNU/Linux with Python 3.8, 3.10, and 3.11
9393
if: matrix.os == 'ubuntu-latest' && matrix.python-version != 3.9
9494
run: python -m tox -e unit
9595

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos:
99
- id: black
1010

1111
- repo: https://github.com/charliermarsh/ruff-pre-commit
12-
rev: "v0.0.260"
12+
rev: "v0.0.261"
1313
hooks:
1414
- id: ruff
1515
args: [--ignore=E741, --exclude=__init__.py]

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
# Features
44

5+
- Added verbose logging to `pybamm.print_citations()` and citation tags for the `pybamm.Citations` class so that users can now see where the citations were registered when running simulations ([#2862](https://github.com/pybamm-team/PyBaMM/pull/2862))
6+
- PyBaMM is now natively supported on Apple silicon chips (`M1/M2`) ([#2435](https://github.com/pybamm-team/PyBaMM/pull/2435))
7+
- PyBaMM is now supported on Python `3.10` and `3.11` ([#2435](https://github.com/pybamm-team/PyBaMM/pull/2435))
58
- Updated to casadi 3.6, which required some changes to the casadi integrator. ([#2859](https://github.com/pybamm-team/PyBaMM/pull/2859))
69

710
## Bug fixes

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pandas >= 0.24
55
anytree >= 2.4.3
66
autograd >= 1.2
77
scikit-fem >= 0.2.0
8-
casadi >= 3.5.0
8+
casadi >= 3.6.0
99
imageio>=2.9.0
1010
jupyter # For example notebooks
1111
pybtex

docs/source/user_guide/installation/GNU-linux.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Prerequisites
88
=============
99

10-
To use and/or contribute to PyBaMM, you must have Python 3.8 or 3.9 installed.
10+
To use and/or contribute to PyBaMM, you must have Python 3.8, 3.9, 3.10, or 3.11 installed.
1111

1212
To install Python 3 on Debian-based distribution (Debian, Ubuntu, Linux
1313
mint), open a terminal and run
@@ -46,7 +46,7 @@ User install
4646

4747
We recommend to install PyBaMM within a virtual environment, in order
4848
not to alter any distribution Python files.
49-
First, make sure you are using Python 3.8 or 3.9.
49+
First, make sure you are using Python 3.8, 3.9, 3.10, or 3.11.
5050
To create a virtual environment ``env`` within your current directory type:
5151

5252
.. code:: bash

docs/source/user_guide/installation/install-from-source.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ or download the source archive on the repository's homepage.
2525

2626
To install PyBaMM, you will need:
2727

28-
- Python 3 (PyBaMM supports versions 3.8 and 3.9)
28+
- Python 3 (PyBaMM supports versions 3.8, 3.9, 3.10, and 3.11)
2929
- The Python headers file for your current Python version.
3030
- A BLAS library (for instance `openblas <https://www.openblas.net/>`_).
3131
- A C compiler (ex: ``gcc``).

docs/source/user_guide/installation/windows.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Windows
66
Prerequisites
77
-------------
88

9-
To use and/or contribute to PyBaMM, you must have Python 3.8 or 3.9 installed.
9+
To use and/or contribute to PyBaMM, you must have Python 3.8, 3.9, 3.10, or 3.11 installed.
1010

1111
To install Python 3 download the installation files from `Python’s
1212
website <https://www.python.org/downloads/windows/>`__. Make sure to

pybamm/citations.py

Lines changed: 85 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
import warnings
99
import pybtex
10+
from inspect import stack
1011
from pybtex.database import parse_file, parse_string, Entry
1112
from pybtex.scanner import PybtexError
1213

@@ -35,6 +36,9 @@ def __init__(self):
3536
# Dict mapping citations keys to BibTex entries
3637
self._all_citations: dict[str, str] = dict()
3738

39+
# Dict mapping citation tags for use when registering citations
40+
self._citation_tags = dict()
41+
3842
# store citation error
3943
self._citation_err_msg = None
4044

@@ -48,10 +52,21 @@ def _reset(self):
4852
"""Reset citations to default only (only for testing purposes)"""
4953
# Initialize empty papers to cite
5054
self._papers_to_cite = set()
55+
# Initialize empty citation tags
56+
self._citation_tags = dict()
5157
# Register the PyBaMM paper and the numpy paper
5258
self.register("Sulzer2021")
5359
self.register("Harris2020")
5460

61+
def _caller_name():
62+
"""
63+
Returns the qualified name of classes that call :meth:`register` internally.
64+
This is used for tagging citations but only for verbose output
65+
"""
66+
# Attributed to https://stackoverflow.com/a/17065634
67+
caller_name = stack()[2][0].f_locals["self"].__class__.__qualname__
68+
return caller_name
69+
5570
def read_citations(self):
5671
"""Reads the citations in `pybamm.CITATIONS.txt`. Other works can be cited
5772
by passing a BibTeX citation to :meth:`register`.
@@ -78,6 +93,14 @@ def _add_citation(self, key, entry):
7893
# Add to database
7994
self._all_citations[key] = new_citation
8095

96+
def _add_citation_tag(self, key, entry):
97+
"""Adds a tag for a citation key which represents the name of the class that
98+
called :meth:`register`"""
99+
100+
# Add a citation tag to the citation_tags ordered dictionary with
101+
# the key being the citation itself and the value being the name of the class
102+
self._citation_tags[key] = entry
103+
81104
@property
82105
def _cited(self):
83106
"""Return a list of the BibTeX entries that have been cited"""
@@ -101,6 +124,14 @@ def register(self, key):
101124
# Check if citation is a known key
102125
if key in self._all_citations:
103126
self._papers_to_cite.add(key)
127+
# Add citation tags for the key
128+
# This is used for verbose output
129+
try:
130+
caller = Citations._caller_name()
131+
self._add_citation_tag(key, entry=caller)
132+
# Don't add citation tags if the citation is registered manually
133+
except KeyError: # pragma: no cover
134+
pass
104135
return
105136

106137
# Try to parse the citation using pybtex
@@ -119,14 +150,54 @@ def register(self, key):
119150
# Unable to parse / unknown key
120151
raise KeyError(f"Not a bibtex citation or known citation: {key}")
121152

122-
def print(self, filename=None, output_format="text"):
123-
"""Print all citations that were used for running simulations.
153+
def tag_citations(self): # pragma: no cover
154+
"""Prints the citations tags for the citations that have been registered
155+
(non-manually). This is used for verbose output when printing citations
156+
such that it can be seen which citations were registered by PyBaMM classes.
157+
158+
To use, either call :meth:`tag_citations` after calling :meth:`register`
159+
for all citations, or enable verbose output with :meth:`print_citations`
160+
or :meth:`print`.
161+
162+
.. note::
163+
If a citation is registered manually, it will not be tagged.
164+
165+
Examples
166+
--------
167+
.. code-block:: python
168+
:linenos:
169+
170+
pybamm.citations.register("Doyle1993")
171+
pybamm.citations.print() or pybamm.print_citations()
172+
173+
will print the following:
174+
175+
.. code-block::
176+
177+
Citations registered:
178+
Sulzer2021 was cited due to the use of
179+
pybamm.models.full_battery_models.lithium_ion.dfn
180+
181+
"""
182+
if self._citation_tags:
183+
print("\n Citations registered: \n")
184+
for key, entry in self._citation_tags.items():
185+
print(f"{key} was cited due to the use of {entry}")
186+
187+
def print(self, filename=None, output_format="text", verbose=False):
188+
"""Print all citations that were used for running simulations. The verbose
189+
option is provided to print the citation tags for the citations that have
190+
been registered non-manually. This is available only upon printing
191+
to the terminal.
124192
125193
Parameters
126194
----------
127195
filename : str, optional
128-
Filename to which to print citations. If None, citations are printed to the
129-
terminal.
196+
Filename to which to print citations. If None, citations are printed
197+
to the terminal.
198+
verbose: bool, optional
199+
If True, prints the citation tags for the citations that have been
200+
registered
130201
"""
131202
if output_format == "text":
132203
citations = pybtex.format_from_strings(
@@ -142,12 +213,14 @@ def print(self, filename=None, output_format="text"):
142213

143214
if filename is None:
144215
print(citations)
216+
if verbose:
217+
self.tag_citations() # pragma: no cover
145218
else:
146219
with open(filename, "w") as f:
147220
f.write(citations)
148221

149222

150-
def print_citations(filename=None, output_format="text"):
223+
def print_citations(filename=None, output_format="text", verbose=False):
151224
"""See :meth:`Citations.print`"""
152225
if citations._citation_err_msg is not None:
153226
raise ImportError(
@@ -159,7 +232,13 @@ def print_citations(filename=None, output_format="text"):
159232
f"{citations._citation_err_msg}"
160233
)
161234
else:
162-
pybamm.citations.print(filename, output_format)
235+
if verbose: # pragma: no cover
236+
warnings.warn(
237+
"Verbose output is not available for printing to files, only to the terminal" # noqa: E501
238+
)
239+
pybamm.citations.print(filename, output_format, verbose=True)
240+
else:
241+
pybamm.citations.print(filename, output_format)
163242

164243

165244
citations = Citations()

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pandas >= 0.24
44
anytree >= 2.4.3
55
autograd >= 1.2
66
scikit-fem >= 0.2.0
7-
casadi >= 3.5.0
7+
casadi >= 3.6.0
88
imageio>=2.9.0
99
pybtex>=0.24.0
1010
sympy >= 1.8

setup.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,21 @@ def compile_KLU():
186186
},
187187
package_data={"pybamm": pybamm_data},
188188
# Python version
189-
python_requires=">=3.8,<3.10",
189+
python_requires=">=3.8,<3.12",
190+
classifiers=[
191+
"Development Status :: 5 - Production/Stable",
192+
"Intended Audience :: Developers",
193+
"Intended Audience :: Science/Research",
194+
"License :: OSI Approved :: BSD License",
195+
"Programming Language :: Python",
196+
"Programming Language :: Python :: 3",
197+
"Programming Language :: Python :: 3 :: Only",
198+
"Programming Language :: Python :: 3.8",
199+
"Programming Language :: Python :: 3.9",
200+
"Programming Language :: Python :: 3.10",
201+
"Programming Language :: Python :: 3.11",
202+
"Topic :: Scientific/Engineering",
203+
],
190204
# List of dependencies
191205
install_requires=[
192206
"numpy>=1.16",
@@ -195,7 +209,7 @@ def compile_KLU():
195209
"anytree>=2.4.3",
196210
"autograd>=1.2",
197211
"scikit-fem>=0.2.0",
198-
"casadi>=3.5.0",
212+
"casadi>=3.6.0",
199213
"imageio>=2.9.0",
200214
"importlib-metadata",
201215
"pybtex>=0.24.0",

0 commit comments

Comments
 (0)