From 23288b406fdd2167ce7f5a3c00537188b7036ea1 Mon Sep 17 00:00:00 2001 From: Priyanshu Agarwal Date: Sun, 7 Feb 2021 14:06:22 +0530 Subject: [PATCH 01/12] add parameter_sets.py script --- .github/update_ps_doc.py | 76 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 .github/update_ps_doc.py diff --git a/.github/update_ps_doc.py b/.github/update_ps_doc.py new file mode 100644 index 0000000000..a1092bf8e2 --- /dev/null +++ b/.github/update_ps_doc.py @@ -0,0 +1,76 @@ +from collections import defaultdict +import os +import re + +import pybtex + +import pybamm +from pybamm.parameters import parameter_sets + + +DOC_INTRO = """ +Parameter sets from papers. The 'citation' entry provides a reference to the appropriate +paper in the file "pybamm/CITATIONS.txt". To see which parameter sets have been used in +your simulation, add the line "pybamm.print_citations()" to your script. +""" + + +def main(): + parameter_set_dict = defaultdict(list) + for ps_name, ps_dict in parameter_sets.__dict__.items(): + if not isinstance(ps_dict, dict): + continue + elif "citation" not in ps_dict or "chemistry" not in ps_dict: + continue + + chemistry = ps_dict["chemistry"] + citation = ps_dict["citation"] + + # Enclose citation in a list if not already enclosed + if not isinstance(citation, list): + citation = [citation] + + parameter_set_dict[chemistry].append((ps_name, citation)) + + output_list = [DOC_INTRO] + citations_file = os.path.join(pybamm.root_dir(), "pybamm", "CITATIONS.txt") + + for ps_chemistry in sorted(parameter_set_dict.keys()): + ps_citations = parameter_set_dict[ps_chemistry] + chem_name = ps_chemistry.capitalize() + " " + "parameter sets" + output_list.append(chem_name) + dashes = "-" * len(ps_chemistry) + "-" * 15 + output_list.append(dashes) + + for ps_name, ps_citation in sorted(ps_citations): + citations = pybtex.format_from_file( + citations_file, + style="plain", + output_backend="plaintext", + citations=ps_citation, + nocite=True, + ) + # Remove citation labels "[3]" + citations = re.sub(r"(?:^|\n)(\[\d+\]\s)", "", citations) + # Break line at the first space before 80 characters + citations = re.findall(r"(.{1,80})(?:\s|$)", citations) + citations = "\n".join(map(lambda x: " " * 8 + x, citations)) + ps_doc = f" * {ps_name:} :\n{citations}" + output_list.append(ps_doc) + + output = "\n".join(output_list) + output += "\n" + + with open( + os.path.join(pybamm.root_dir(), "pybamm", "parameters", "parameter_sets.py"), + "r+", + ) as ps_fp: + ps_output = ps_fp.read() + ps_output = ps_output.replace(parameter_sets.__doc__, output) + ps_fp.truncate(0) + ps_fp.seek(0) + ps_fp.write(ps_output) + + +if __name__ == "__main__": + main() From 15ad960a0a8fa65e285364e7694724e7b7257c99 Mon Sep 17 00:00:00 2001 From: Priyanshu Agarwal Date: Sun, 7 Feb 2021 14:07:07 +0530 Subject: [PATCH 02/12] add update_ps_doc workflow --- .github/workflows/update_ps_doc.yml | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/update_ps_doc.yml diff --git a/.github/workflows/update_ps_doc.yml b/.github/workflows/update_ps_doc.yml new file mode 100644 index 0000000000..20c668c9c5 --- /dev/null +++ b/.github/workflows/update_ps_doc.yml @@ -0,0 +1,37 @@ +name: Update parameter_sets.py docstring + +on: + push: + paths: + - 'pybamm/parameters/parameter_sets.py' + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.8] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pybamm + pip install pybtex + - name: Update docstring + run: python .github/update_ps_doc.py + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + delete-branch: true + commit-message: update parameter_sets + title: Update parameter_sets + body: | + Update parameter_sets.py + Auto-generated From 5e8a1f57efb5aaa212b149de5128aba2c67ebe3a Mon Sep 17 00:00:00 2001 From: Priyanshu Agarwal Date: Sun, 7 Feb 2021 15:44:28 +0530 Subject: [PATCH 03/12] minor changes --- .github/workflows/update_ps_doc.yml | 6 ++++-- CHANGELOG.md | 1 + .github/update_ps_doc.py => update_ps_doc.py | 0 3 files changed, 5 insertions(+), 2 deletions(-) rename .github/update_ps_doc.py => update_ps_doc.py (100%) diff --git a/.github/workflows/update_ps_doc.yml b/.github/workflows/update_ps_doc.yml index 20c668c9c5..be7d1d0ef1 100644 --- a/.github/workflows/update_ps_doc.yml +++ b/.github/workflows/update_ps_doc.yml @@ -4,6 +4,7 @@ on: push: paths: - 'pybamm/parameters/parameter_sets.py' + - 'pybamm/parameters/CITATIONS.txt' jobs: build: @@ -25,13 +26,14 @@ jobs: pip install pybamm pip install pybtex - name: Update docstring - run: python .github/update_ps_doc.py + run: python update_ps_doc.py - name: Create Pull Request uses: peter-evans/create-pull-request@v3 with: delete-branch: true + branch-suffix: short-commit-hash commit-message: update parameter_sets title: Update parameter_sets body: | Update parameter_sets.py - Auto-generated + Auto-generated pull request diff --git a/CHANGELOG.md b/CHANGELOG.md index c73d1cd503..421d2815c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ ## Optimizations +- Add script and workflow to automatically update parameter_sets.py docstrings ([#1371](https://github.com/pybamm-team/PyBaMM/pull/1371)) - Add URLs checker in workflows ([#1347](https://github.com/pybamm-team/PyBaMM/pull/1347)) - The `Solution` class now only creates the concatenated `y` when the user asks for it. This is an optimization step as the concatenation can be slow, especially with larger experiments ([#1331](https://github.com/pybamm-team/PyBaMM/pull/1331)) - If solver method `solve()` is passed a list of inputs as the `inputs` keyword argument, the resolution of the model for each input set is spread across several Python processes, usually running in parallel on different processors. The default number of processes is the number of processors available. `solve()` takes a new keyword argument `nproc` which can be used to set this number a manually. diff --git a/.github/update_ps_doc.py b/update_ps_doc.py similarity index 100% rename from .github/update_ps_doc.py rename to update_ps_doc.py From 92030143848d301d2641f3f36dae3ed8eb5bf07d Mon Sep 17 00:00:00 2001 From: Priyanshu Agarwal Date: Tue, 9 Feb 2021 15:50:45 +0530 Subject: [PATCH 04/12] change update_parameter_sets_doc workflow --- .../{update_ps_doc.yml => update_parameter_sets_doc.yml} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename .github/workflows/{update_ps_doc.yml => update_parameter_sets_doc.yml} (90%) diff --git a/.github/workflows/update_ps_doc.yml b/.github/workflows/update_parameter_sets_doc.yml similarity index 90% rename from .github/workflows/update_ps_doc.yml rename to .github/workflows/update_parameter_sets_doc.yml index be7d1d0ef1..b351626721 100644 --- a/.github/workflows/update_ps_doc.yml +++ b/.github/workflows/update_parameter_sets_doc.yml @@ -23,10 +23,10 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install pybamm + pip install --editable . pip install pybtex - name: Update docstring - run: python update_ps_doc.py + run: python pybamm/parameters/update_parameter_sets_doc.py - name: Create Pull Request uses: peter-evans/create-pull-request@v3 with: From cb1f46a6af38820d76d253d12dfc9f315e5664ee Mon Sep 17 00:00:00 2001 From: Priyanshu Agarwal Date: Tue, 9 Feb 2021 15:51:46 +0530 Subject: [PATCH 05/12] divide script into functions --- .../parameters/update_parameter_sets_doc.py | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 pybamm/parameters/update_parameter_sets_doc.py diff --git a/pybamm/parameters/update_parameter_sets_doc.py b/pybamm/parameters/update_parameter_sets_doc.py new file mode 100644 index 0000000000..1d908db2c6 --- /dev/null +++ b/pybamm/parameters/update_parameter_sets_doc.py @@ -0,0 +1,102 @@ +""" +Automatically update the docstring of parameter_sets.py +""" + +from collections import defaultdict +import os +import re + +import pybtex + +import pybamm +from pybamm.parameters import parameter_sets + + +DOC_INTRO = """ +Parameter sets from papers. The 'citation' entry provides a reference to the appropriate +paper in the file "pybamm/CITATIONS.txt". To see which parameter sets have been used in +your simulation, add the line "pybamm.print_citations()" to your script.""" + + +def get_ps_dict(): + """ + Returns {chemistry:(author_year, [citations])} from all dictionaries in + parameter_sets.py + """ + parameter_set_dict = defaultdict(list) + for ps_name, ps_dict in parameter_sets.__dict__.items(): + if not isinstance(ps_dict, dict): + continue + elif "citation" not in ps_dict or "chemistry" not in ps_dict: + continue + + chemistry = ps_dict["chemistry"] + citation = ps_dict["citation"] + + # Enclose citation in a list if not already enclosed + if not isinstance(citation, list): + citation = [citation] + + parameter_set_dict[chemistry].append((ps_name, citation)) + return parameter_set_dict + + +def generate_ps_doc(parameter_set_dict): + """ + Generates docstring of parameter_sets.py from the given dictionary + """ + output_list = [DOC_INTRO] + citations_file = os.path.join(pybamm.root_dir(), "pybamm", "CITATIONS.txt") + + for ps_chemistry in sorted(parameter_set_dict.keys()): + output_list.append("") + ps_citations = parameter_set_dict[ps_chemistry] + chem_name = ps_chemistry.capitalize() + " " + "parameter sets" + output_list.append(chem_name) + dashes = "-" * len(ps_chemistry) + "-" * 15 + output_list.append(dashes) + + for ps_name, ps_citation in sorted(ps_citations): + citations = pybtex.format_from_file( + citations_file, + style="plain", + output_backend="plaintext", + citations=ps_citation, + nocite=True, + ) + # Remove citation labels "[3]" + citations = re.sub(r"(?:^|\n)(\[\d+\]\s)", "", citations) + # Break line at the first space before 80 characters + citations = re.findall(r"(.{1,80})(?:\s|$)", citations) + citations = "\n".join(map(lambda x: " " * 8 + x, citations)) + ps_doc = f" * {ps_name:} :\n{citations}" + output_list.append(ps_doc) + + output = "\n".join(output_list) + output += "\n" + return output + + +def update_doc(generated_doc): + """ + Opens parameter_sets.py, replaces the docstring and then writes it + """ + with open( + os.path.join(pybamm.root_dir(), "pybamm", "parameters", "parameter_sets.py"), + "r+", + ) as ps_fp: + ps_output = ps_fp.read() + ps_output = ps_output.replace(parameter_sets.__doc__, generated_doc) + ps_fp.truncate(0) + ps_fp.seek(0) + ps_fp.write(ps_output) + + +def main(): + parameter_set_dict = get_ps_dict() + generated_doc = generate_ps_doc(parameter_set_dict) + update_doc(generated_doc) + + +if __name__ == "__main__": + main() From 1d7ad365b5a5220bc68c7bc5c5663679d4b96767 Mon Sep 17 00:00:00 2001 From: Priyanshu Agarwal Date: Tue, 9 Feb 2021 15:52:19 +0530 Subject: [PATCH 06/12] add tests --- .../test_update_parameter_sets_doc.py | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tests/unit/test_parameters/test_update_parameter_sets_doc.py diff --git a/tests/unit/test_parameters/test_update_parameter_sets_doc.py b/tests/unit/test_parameters/test_update_parameter_sets_doc.py new file mode 100644 index 0000000000..20b3a00e66 --- /dev/null +++ b/tests/unit/test_parameters/test_update_parameter_sets_doc.py @@ -0,0 +1,63 @@ +""" +Tests for the update_parameter_sets_doc.py +""" +from pybamm.parameters.update_parameter_sets_doc import generate_ps_doc +import pybamm +import unittest + + +DOC = """ +Parameter sets from papers. The 'citation' entry provides a reference to the appropriate +paper in the file "pybamm/CITATIONS.txt". To see which parameter sets have been used in +your simulation, add the line "pybamm.print_citations()" to your script. + +Lead-acid parameter sets +------------------------ + * Sulzer2019 : + Valentin Sulzer, S. Jon Chapman, Colin P. Please, David A. Howey, and Charles W. + Monroe. Faster Lead-Acid Battery Simulations from Porous-Electrode Theory: Part + I. Physical Model. Journal of The Electrochemical Society, 166(12):A2363–A2371, + 2019. doi:10.1149/2.0301910jes. + +Lithium-ion parameter sets +-------------------------- + * Ecker2015 : + Madeleine Ecker, Thi Kim Dung Tran, Philipp Dechent, Stefan Käbitz, Alexander + Warnecke, and Dirk Uwe Sauer. Parameterization of a Physico-Chemical Model of a + Lithium-Ion Battery: I. Determination of Parameters. Journal of the + Electrochemical Society, 162(9):A1836–A1848, 2015. + doi:10.1149/2.0551509jes.Giles Richardson, Ivan Korotkin, Rahifa Ranom, Michael + Castle, and Jamie M. Foster. Generalised single particle models for high-rate + operation of graded lithium-ion electrodes: systematic derivation and + validation. Electrochimica Acta, 339:135862, 2020. + doi:10.1016/j.electacta.2020.135862. + * NCA_Kim2011 : + Gi-Heon Kim, Kandler Smith, Kyu-Jin Lee, Shriram Santhanagopalan, and Ahmad + Pesaran. Multi-domain modeling of lithium-ion batteries encompassing + multi-physics in varied length scales. Journal of the Electrochemical Society, + 158(8):A955–A969, 2011. doi:10.1149/1.3597614. +""" + +AUTHOR_YEAR_DICT = { + "lithium-ion": [ + ("NCA_Kim2011", ["Kim2011"]), + ("Ecker2015", ["Ecker2015i", "Richardson2020"]), + ], + "lead-acid": [("Sulzer2019", ["Sulzer2019physical"])], +} + + +class TestUpdateParameterSetsDoc(unittest.TestCase): + def test_generate_ps_doc(self): + output = generate_ps_doc(AUTHOR_YEAR_DICT) + self.assertEqual(output, DOC) + + +if __name__ == "__main__": + print("Add -v for more debug output") + import sys + + if "-v" in sys.argv: + debug = True + pybamm.settings.debug_mode = True + unittest.main() From 656698717f63678b67238ba605e91edecceeb129 Mon Sep 17 00:00:00 2001 From: Priyanshu Agarwal Date: Tue, 9 Feb 2021 15:55:13 +0530 Subject: [PATCH 07/12] change location --- update_ps_doc.py | 76 ------------------------------------------------ 1 file changed, 76 deletions(-) delete mode 100644 update_ps_doc.py diff --git a/update_ps_doc.py b/update_ps_doc.py deleted file mode 100644 index a1092bf8e2..0000000000 --- a/update_ps_doc.py +++ /dev/null @@ -1,76 +0,0 @@ -from collections import defaultdict -import os -import re - -import pybtex - -import pybamm -from pybamm.parameters import parameter_sets - - -DOC_INTRO = """ -Parameter sets from papers. The 'citation' entry provides a reference to the appropriate -paper in the file "pybamm/CITATIONS.txt". To see which parameter sets have been used in -your simulation, add the line "pybamm.print_citations()" to your script. -""" - - -def main(): - parameter_set_dict = defaultdict(list) - for ps_name, ps_dict in parameter_sets.__dict__.items(): - if not isinstance(ps_dict, dict): - continue - elif "citation" not in ps_dict or "chemistry" not in ps_dict: - continue - - chemistry = ps_dict["chemistry"] - citation = ps_dict["citation"] - - # Enclose citation in a list if not already enclosed - if not isinstance(citation, list): - citation = [citation] - - parameter_set_dict[chemistry].append((ps_name, citation)) - - output_list = [DOC_INTRO] - citations_file = os.path.join(pybamm.root_dir(), "pybamm", "CITATIONS.txt") - - for ps_chemistry in sorted(parameter_set_dict.keys()): - ps_citations = parameter_set_dict[ps_chemistry] - chem_name = ps_chemistry.capitalize() + " " + "parameter sets" - output_list.append(chem_name) - dashes = "-" * len(ps_chemistry) + "-" * 15 - output_list.append(dashes) - - for ps_name, ps_citation in sorted(ps_citations): - citations = pybtex.format_from_file( - citations_file, - style="plain", - output_backend="plaintext", - citations=ps_citation, - nocite=True, - ) - # Remove citation labels "[3]" - citations = re.sub(r"(?:^|\n)(\[\d+\]\s)", "", citations) - # Break line at the first space before 80 characters - citations = re.findall(r"(.{1,80})(?:\s|$)", citations) - citations = "\n".join(map(lambda x: " " * 8 + x, citations)) - ps_doc = f" * {ps_name:} :\n{citations}" - output_list.append(ps_doc) - - output = "\n".join(output_list) - output += "\n" - - with open( - os.path.join(pybamm.root_dir(), "pybamm", "parameters", "parameter_sets.py"), - "r+", - ) as ps_fp: - ps_output = ps_fp.read() - ps_output = ps_output.replace(parameter_sets.__doc__, output) - ps_fp.truncate(0) - ps_fp.seek(0) - ps_fp.write(ps_output) - - -if __name__ == "__main__": - main() From 769820593751dfc6726719b0f653c222699d99cd Mon Sep 17 00:00:00 2001 From: Priyanshu Agarwal Date: Tue, 9 Feb 2021 16:32:21 +0530 Subject: [PATCH 08/12] add dependencies in workflow --- .github/workflows/update_parameter_sets_doc.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/update_parameter_sets_doc.yml b/.github/workflows/update_parameter_sets_doc.yml index b351626721..863233c8a4 100644 --- a/.github/workflows/update_parameter_sets_doc.yml +++ b/.github/workflows/update_parameter_sets_doc.yml @@ -23,6 +23,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip + pip install wheel pip install --editable . pip install pybtex - name: Update docstring @@ -33,7 +34,8 @@ jobs: delete-branch: true branch-suffix: short-commit-hash commit-message: update parameter_sets - title: Update parameter_sets + title: Update parameter_sets.py docstring body: | - Update parameter_sets.py + Update docstring of parameter_sets.py + Auto-generated pull request From 626c34beeffece57c62155d417fa75775646f6c1 Mon Sep 17 00:00:00 2001 From: Priyanshu Agarwal Date: Wed, 10 Feb 2021 10:36:46 +0530 Subject: [PATCH 09/12] fix formatting --- pybamm/parameters/update_parameter_sets_doc.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/pybamm/parameters/update_parameter_sets_doc.py b/pybamm/parameters/update_parameter_sets_doc.py index 1d908db2c6..05676a9794 100644 --- a/pybamm/parameters/update_parameter_sets_doc.py +++ b/pybamm/parameters/update_parameter_sets_doc.py @@ -65,11 +65,19 @@ def generate_ps_doc(parameter_set_dict): nocite=True, ) # Remove citation labels "[3]" - citations = re.sub(r"(?:^|\n)(\[\d+\]\s)", "", citations) - # Break line at the first space before 80 characters - citations = re.findall(r"(.{1,80})(?:\s|$)", citations) - citations = "\n".join(map(lambda x: " " * 8 + x, citations)) - ps_doc = f" * {ps_name:} :\n{citations}" + citations = re.split(r"(?:^|\n)\[\d+\]\s", citations) + # Remove empty strings + citations = filter(bool, citations) + fmt_citations = [] + for citation in citations: + # Break line at the first space before 80 characters + citation = re.findall(r"(.{1,80})(?:\s|$)", citation) + # Join to create a single citation paragraph + citation = "\n".join(map(lambda x: " " * 8 + x, citation)) + fmt_citations.append(citation) + + fmt_citations = "\n".join(fmt_citations) + ps_doc = f" * {ps_name:} :\n{fmt_citations}" output_list.append(ps_doc) output = "\n".join(output_list) From 3a4f628974216f4ae32897278230c50ec95f0b05 Mon Sep 17 00:00:00 2001 From: Priyanshu Agarwal Date: Wed, 10 Feb 2021 10:40:04 +0530 Subject: [PATCH 10/12] change DOC --- .../test_parameters/test_update_parameter_sets_doc.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/unit/test_parameters/test_update_parameter_sets_doc.py b/tests/unit/test_parameters/test_update_parameter_sets_doc.py index 20b3a00e66..c14dadfcdf 100644 --- a/tests/unit/test_parameters/test_update_parameter_sets_doc.py +++ b/tests/unit/test_parameters/test_update_parameter_sets_doc.py @@ -25,12 +25,11 @@ Madeleine Ecker, Thi Kim Dung Tran, Philipp Dechent, Stefan Käbitz, Alexander Warnecke, and Dirk Uwe Sauer. Parameterization of a Physico-Chemical Model of a Lithium-Ion Battery: I. Determination of Parameters. Journal of the - Electrochemical Society, 162(9):A1836–A1848, 2015. - doi:10.1149/2.0551509jes.Giles Richardson, Ivan Korotkin, Rahifa Ranom, Michael - Castle, and Jamie M. Foster. Generalised single particle models for high-rate - operation of graded lithium-ion electrodes: systematic derivation and - validation. Electrochimica Acta, 339:135862, 2020. - doi:10.1016/j.electacta.2020.135862. + Electrochemical Society, 162(9):A1836–A1848, 2015. doi:10.1149/2.0551509jes. + Giles Richardson, Ivan Korotkin, Rahifa Ranom, Michael Castle, and Jamie M. + Foster. Generalised single particle models for high-rate operation of graded + lithium-ion electrodes: systematic derivation and validation. Electrochimica + Acta, 339:135862, 2020. doi:10.1016/j.electacta.2020.135862. * NCA_Kim2011 : Gi-Heon Kim, Kandler Smith, Kyu-Jin Lee, Shriram Santhanagopalan, and Ahmad Pesaran. Multi-domain modeling of lithium-ion batteries encompassing From 64041b8b25de7c7b5bccaadd8c9cfbde26f4a793 Mon Sep 17 00:00:00 2001 From: Priyanshu Agarwal Date: Wed, 10 Feb 2021 21:40:43 +0530 Subject: [PATCH 11/12] add '-' before citations --- pybamm/parameters/update_parameter_sets_doc.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pybamm/parameters/update_parameter_sets_doc.py b/pybamm/parameters/update_parameter_sets_doc.py index 05676a9794..0dc76f331b 100644 --- a/pybamm/parameters/update_parameter_sets_doc.py +++ b/pybamm/parameters/update_parameter_sets_doc.py @@ -71,11 +71,20 @@ def generate_ps_doc(parameter_set_dict): fmt_citations = [] for citation in citations: # Break line at the first space before 80 characters - citation = re.findall(r"(.{1,80})(?:\s|$)", citation) + citation_parts = re.findall(r"(.{1,80})(?:\s|$)", citation) + # first_line = citation.split('\n') + + indent_citation_parts = [] + for idx, citation_part in enumerate(citation_parts): + if idx == 0: + citation_part = "- " + citation_part + else: + citation_part = " " + citation_part + indent_citation_parts.append(" " * 6 + citation_part) + # Join to create a single citation paragraph - citation = "\n".join(map(lambda x: " " * 8 + x, citation)) + citation = "\n".join(indent_citation_parts) fmt_citations.append(citation) - fmt_citations = "\n".join(fmt_citations) ps_doc = f" * {ps_name:} :\n{fmt_citations}" output_list.append(ps_doc) From 2378c0f146ef15107f2492ffc04d5db48d4f4818 Mon Sep 17 00:00:00 2001 From: Priyanshu Agarwal Date: Thu, 11 Feb 2021 11:43:39 +0530 Subject: [PATCH 12/12] add tests --- .../test_update_parameter_sets_doc.py | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/tests/unit/test_parameters/test_update_parameter_sets_doc.py b/tests/unit/test_parameters/test_update_parameter_sets_doc.py index c14dadfcdf..33534b6d51 100644 --- a/tests/unit/test_parameters/test_update_parameter_sets_doc.py +++ b/tests/unit/test_parameters/test_update_parameter_sets_doc.py @@ -1,7 +1,7 @@ """ Tests for the update_parameter_sets_doc.py """ -from pybamm.parameters.update_parameter_sets_doc import generate_ps_doc +from pybamm.parameters.update_parameter_sets_doc import get_ps_dict, generate_ps_doc import pybamm import unittest @@ -14,39 +14,43 @@ Lead-acid parameter sets ------------------------ * Sulzer2019 : - Valentin Sulzer, S. Jon Chapman, Colin P. Please, David A. Howey, and Charles W. + - Valentin Sulzer, S. Jon Chapman, Colin P. Please, David A. Howey, and Charles W. Monroe. Faster Lead-Acid Battery Simulations from Porous-Electrode Theory: Part I. Physical Model. Journal of The Electrochemical Society, 166(12):A2363–A2371, 2019. doi:10.1149/2.0301910jes. Lithium-ion parameter sets -------------------------- - * Ecker2015 : - Madeleine Ecker, Thi Kim Dung Tran, Philipp Dechent, Stefan Käbitz, Alexander - Warnecke, and Dirk Uwe Sauer. Parameterization of a Physico-Chemical Model of a - Lithium-Ion Battery: I. Determination of Parameters. Journal of the - Electrochemical Society, 162(9):A1836–A1848, 2015. doi:10.1149/2.0551509jes. - Giles Richardson, Ivan Korotkin, Rahifa Ranom, Michael Castle, and Jamie M. - Foster. Generalised single particle models for high-rate operation of graded - lithium-ion electrodes: systematic derivation and validation. Electrochimica - Acta, 339:135862, 2020. doi:10.1016/j.electacta.2020.135862. - * NCA_Kim2011 : - Gi-Heon Kim, Kandler Smith, Kyu-Jin Lee, Shriram Santhanagopalan, and Ahmad - Pesaran. Multi-domain modeling of lithium-ion batteries encompassing - multi-physics in varied length scales. Journal of the Electrochemical Society, - 158(8):A955–A969, 2011. doi:10.1149/1.3597614. + * Prada2013 : + - Chang-Hui Chen, Ferran Brosa Planella, Kieran O'Regan, Dominika Gastol, W. + Dhammika Widanage, and Emma Kendrick. Development of Experimental Techniques for + Parameterization of Multi-scale Lithium-ion Battery Models. Journal of The + Electrochemical Society, 167(8):080534, 2020. doi:10.1149/1945-7111/ab9050. + - Michael J. Lain, James Brandon, and Emma Kendrick. Design strategies for high + power vs. high energy lithium ion cells. Batteries, 5(4):64, 2019. + doi:10.3390/batteries5040064. + - Eric Prada, D. Di Domenico, Y. Creff, J. Bernard, Valérie Sauvant-Moynot, and + François Huet. A simplified electrochemical and thermal aging model of + LiFePO4-graphite Li-ion batteries: power and capacity fade simulations. Journal + of The Electrochemical Society, 160(4):A616, 2013. doi:10.1149/2.053304jes. """ AUTHOR_YEAR_DICT = { "lithium-ion": [ - ("NCA_Kim2011", ["Kim2011"]), - ("Ecker2015", ["Ecker2015i", "Richardson2020"]), + ("Prada2013", ["Chen2020", "Lain2019", "Prada2013"]), ], "lead-acid": [("Sulzer2019", ["Sulzer2019physical"])], } class TestUpdateParameterSetsDoc(unittest.TestCase): + def test_get_ps_dict(self): + output = get_ps_dict() + for key, values in AUTHOR_YEAR_DICT.items(): + output_values = output.get(key, []) + for value in values: + self.assertIn(value, output_values) + def test_generate_ps_doc(self): output = generate_ps_doc(AUTHOR_YEAR_DICT) self.assertEqual(output, DOC)