Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix citations on Colab + bump v22.11.1 #2547

Merged
merged 4 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/periodic_benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
with:
python-version: 3.8
- name: Install tox and asv
run: pip install -U pip tox asv
run: pip install -U pip "tox<4" asv
- name: Run benchmarks
run: |
asv machine --machine "GitHubRunner"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_benchmarks_over_history.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
with:
python-version: 3.8
- name: Install tox and asv
run: pip install -U pip tox asv
run: pip install -U pip "tox<4" asv
- name: Fetch develop branch
# Not required when worklow trigerred
# on develop, but useful when
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:

- name: Check style
run: |
python -m pip install tox
python -m pip install "tox<4"
tox -e flake8

build:
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
- name: Install standard python dependencies
run: |
python -m pip install --upgrade pip wheel setuptools
python -m pip install tox
python -m pip install "tox<4"

- name: Install SuiteSparse and Sundials
if: matrix.os == 'ubuntu-latest'
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# [Unreleased](https://github.com/pybamm-team/PyBaMM/)

# [v22.11.1](https://github.com/pybamm-team/PyBaMM/tree/v22.11.1) - 2022-12-13

## Bug fixes

- Fixed installation on Google Colab (`pybtex` issues) ([#2547](https://github.com/pybamm-team/PyBaMM/pull/2547/files))

# [v22.11](https://github.com/pybamm-team/PyBaMM/tree/v22.11) - 2022-11-30

## Features
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ keywords:
- "expression tree"
- "python"
- "symbolic differentiation"
version: "22.11"
version: "22.11.1"
repository-code: "https://github.com/pybamm-team/PyBaMM"
title: "Python Battery Mathematical Modelling (PyBaMM)"
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
author = "The PyBaMM Team"

# The short X.Y version
version = "22.11"
version = "22.11.1"
# The full version, including alpha/beta/rc tags
release = version

Expand Down
2 changes: 1 addition & 1 deletion docs/install/install-from-source.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ You can install it with

.. code:: bash

python3.X -m pip install --user tox
python3.X -m pip install --user "tox<4"

Depending on your operating system, you may or may not have ``pip`` installed along python.
If ``pip`` is not found, you probably want to install the ``python3-pip`` package.
Expand Down
62 changes: 39 additions & 23 deletions pybamm/citations.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ def __init__(self):
# Dict mapping citations keys to BibTex entries
self._all_citations: dict[str, str] = dict()

self.read_citations()
self._reset()
# store citation error
self._citation_err_msg = None

try:
self.read_citations()
self._reset()
except Exception as e: # pragma: no cover
self._citation_err_msg = e

def _reset(self):
"""Reset citations to default only (only for testing purposes)"""
Expand Down Expand Up @@ -91,27 +97,27 @@ def register(self, key):
- The citation key for an entry in `pybamm/CITATIONS.txt` or
- One or more BibTex formatted citations
"""

# Check if citation is a known key
if key in self._all_citations:
self._papers_to_cite.add(key)
return

# Try to parse the citation using pybtex
try:
# Parse string as a bibtex citation, and check that a citation was found
bib_data = parse_string(key, bib_format="bibtex")
if not bib_data.entries:
raise PybtexError("no entries found")

# Add and register all citations
for key, entry in bib_data.entries.items():
self._add_citation(key, entry)
self.register(key)
if self._citation_err_msg is None:
# Check if citation is a known key
if key in self._all_citations:
self._papers_to_cite.add(key)
return
except PybtexError:
# Unable to parse / unknown key
raise KeyError(f"Not a bibtex citation or known citation: {key}")

# Try to parse the citation using pybtex
try:
# Parse string as a bibtex citation, and check that a citation was found
bib_data = parse_string(key, bib_format="bibtex")
if not bib_data.entries:
raise PybtexError("no entries found")

# Add and register all citations
for key, entry in bib_data.entries.items():
self._add_citation(key, entry)
self.register(key)
return
except PybtexError:
# Unable to parse / unknown key
raise KeyError(f"Not a bibtex citation or known citation: {key}")

def print(self, filename=None, output_format="text"):
"""Print all citations that were used for running simulations.
Expand Down Expand Up @@ -143,7 +149,17 @@ def print(self, filename=None, output_format="text"):

def print_citations(filename=None, output_format="text"):
"""See :meth:`Citations.print`"""
pybamm.citations.print(filename, output_format)
if citations._citation_err_msg is not None:
raise ImportError(
f"Citations could not be registered. If you are on Google Colab - "
"pybtex does not work with Google Colab due to a known bug - "
"https://bitbucket.org/pybtex-devs/pybtex/issues/148/. "
"Please manually cite all the references."
"\nError encountered -\n"
f"{citations._citation_err_msg}"
)
else:
pybamm.citations.print(filename, output_format)


citations = Citations()
2 changes: 1 addition & 1 deletion pybamm/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "22.11"
__version__ = "22.11.1"
5 changes: 5 additions & 0 deletions tests/unit/test_citations.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ def test_print_citations(self):
with self.assertRaisesRegex(pybamm.OptionError, "'text' or 'bibtex'"):
pybamm.print_citations("test_citations.txt", "bad format")

pybamm.citations._citation_err_msg = "Error"
with self.assertRaisesRegex(ImportError, "Error"):
pybamm.print_citations()
pybamm.citations._citation_err_msg = None

def test_overwrite_citation(self):
# Unknown citation
fake_citation = r"@article{NotACitation, title = {This Doesn't Exist}}"
Expand Down
2 changes: 1 addition & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pybamm",
"version-string": "22.11",
"version-string": "22.11.1",
"dependencies": [
"casadi",
{
Expand Down