From 0de47d8a47caca58d9d5603ba31a5c7ea94fce83 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 6 Apr 2023 04:06:01 +0530 Subject: [PATCH 1/9] #1182 updating citation tags via separate dict --- pybamm/citations.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/pybamm/citations.py b/pybamm/citations.py index f236da8d71..699a9675f5 100644 --- a/pybamm/citations.py +++ b/pybamm/citations.py @@ -7,6 +7,9 @@ import os import warnings import pybtex + +# from collections import OrderedDict +from inspect import stack from pybtex.database import parse_file, parse_string, Entry from pybtex.scanner import PybtexError @@ -35,6 +38,9 @@ def __init__(self): # Dict mapping citations keys to BibTex entries self._all_citations: dict[str, str] = dict() + # Ordered dict mapping citation tags for use when registering citations + self.citation_tags = dict() + # store citation error self._citation_err_msg = None @@ -52,6 +58,13 @@ def _reset(self): self.register("Sulzer2021") self.register("Harris2020") + def _get_caller_name(self): + """Returns the name of the class that calls :meth:`register` internally. This + is used for tagging citations only for verbose output.""" + # get the name of the class the register function was called from + caller_name = stack()[2][0].f_locals["self"].__class__.__name__ + return caller_name + def read_citations(self): """Reads the citations in `pybamm.CITATIONS.txt`. Other works can be cited by passing a BibTeX citation to :meth:`register`. @@ -78,6 +91,17 @@ def _add_citation(self, key, entry): # Add to database self._all_citations[key] = new_citation + def _update_citation_tags(self, key, entry): + """Updates the citation tags dictionary with the name of the class that called + :meth:`register`""" + # todo check input types are correct + # todo check if key is in self._all_citations + + # Add a citation tag to the citation_tags ordered dictionary with + # the key being the citation itself + for key in self._all_citations: + self.citation_tags[key] = entry + @property def _cited(self): """Return a list of the BibTeX entries that have been cited""" @@ -110,16 +134,18 @@ def register(self, key): if not bib_data.entries: raise PybtexError("no entries found") - # Add and register all citations + # Add and register all citations and citation tags for key, entry in bib_data.entries.items(): self._add_citation(key, entry) self.register(key) + self._update_citation_tags(key, entry=self._get_caller_name()) 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"): + # todo verbose + def print(self, filename=None, output_format="text", verbose=False): """Print all citations that were used for running simulations. Parameters @@ -147,7 +173,8 @@ def print(self, filename=None, output_format="text"): f.write(citations) -def print_citations(filename=None, output_format="text"): +# todo: implement the verbose functionality +def print_citations(filename=None, output_format="text", verbose=False): """See :meth:`Citations.print`""" if citations._citation_err_msg is not None: raise ImportError( From 52cd46c19415062d4debafd06e6b78245668094f Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 6 Apr 2023 08:01:17 +0530 Subject: [PATCH 2/9] #1182 verbose output while printing citations --- pybamm/citations.py | 88 +++++++++++++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 22 deletions(-) diff --git a/pybamm/citations.py b/pybamm/citations.py index 699a9675f5..75fa128640 100644 --- a/pybamm/citations.py +++ b/pybamm/citations.py @@ -38,8 +38,8 @@ def __init__(self): # Dict mapping citations keys to BibTex entries self._all_citations: dict[str, str] = dict() - # Ordered dict mapping citation tags for use when registering citations - self.citation_tags = dict() + # Dict mapping citation tags for use when registering citations + self._citation_tags = dict() # store citation error self._citation_err_msg = None @@ -54,15 +54,19 @@ def _reset(self): """Reset citations to default only (only for testing purposes)""" # Initialize empty papers to cite self._papers_to_cite = set() + # Initialize empty citation tags + self._citation_tags = dict() # Register the PyBaMM paper and the numpy paper self.register("Sulzer2021") self.register("Harris2020") - def _get_caller_name(self): - """Returns the name of the class that calls :meth:`register` internally. This - is used for tagging citations only for verbose output.""" - # get the name of the class the register function was called from - caller_name = stack()[2][0].f_locals["self"].__class__.__name__ + def _caller_name(): + """ + Returns the qualified name of classes that call :meth:`register` internally. + This is used for tagging citations but only for verbose output + """ + # Attributed to https://stackoverflow.com/a/17065634 + caller_name = stack()[2][0].f_locals["self"].__class__.__qualname__ return caller_name def read_citations(self): @@ -91,16 +95,13 @@ def _add_citation(self, key, entry): # Add to database self._all_citations[key] = new_citation - def _update_citation_tags(self, key, entry): - """Updates the citation tags dictionary with the name of the class that called - :meth:`register`""" - # todo check input types are correct - # todo check if key is in self._all_citations + def _add_citation_tag(self, key, entry): + """Adds a tag for a citation key which represents the name of the class that + called :meth:`register`""" # Add a citation tag to the citation_tags ordered dictionary with - # the key being the citation itself - for key in self._all_citations: - self.citation_tags[key] = entry + # the key being the citation itself and the value being the name of the class + self._citation_tags[key] = entry @property def _cited(self): @@ -125,6 +126,14 @@ def register(self, key): # Check if citation is a known key if key in self._all_citations: self._papers_to_cite.add(key) + # Add citation tags for the key + # This is used for verbose output + try: + caller = Citations._caller_name() + self._add_citation_tag(key, entry=caller) + # Don't add citation tags if the citation is registered manually + except KeyError: + pass return # Try to parse the citation using pybtex @@ -134,25 +143,52 @@ def register(self, key): if not bib_data.entries: raise PybtexError("no entries found") - # Add and register all citations and citation tags + # Add and register all citations for key, entry in bib_data.entries.items(): self._add_citation(key, entry) self.register(key) - self._update_citation_tags(key, entry=self._get_caller_name()) return except PybtexError: # Unable to parse / unknown key raise KeyError(f"Not a bibtex citation or known citation: {key}") - # todo verbose + def tag_citations(self): + """Prints the citations tags for the citations that have been registered + (non-manually). This is used for verbose output when printing citations + such that it can be seen which citations were registered by PyBaMM classes. + + To use, call :meth:`tag_citations` after calling :meth:`register` for + all citations and enable verbose output with :meth:`print_citations` + or :meth:`print`. + + Examples + -------- + >>> pybamm.citations.register("Doyle1993") + >>> pybamm.citations.print() or pybamm.print_citations() + + Citations registered: + Sulzer2021 was cited due to the use of + pybamm.models.full_battery_models.lithium_ion.dfn + """ + if self._citation_tags: + print("Citations registered:") + for key, entry in self._citation_tags.items(): + print(f"{key} was cited due to the use of {entry}") + def print(self, filename=None, output_format="text", verbose=False): - """Print all citations that were used for running simulations. + """Print all citations that were used for running simulations. The verbose + option is provided to print the citation tags for the citations that have + been registered non-manually. This is available only upon printing + to the terminal. Parameters ---------- filename : str, optional - Filename to which to print citations. If None, citations are printed to the - terminal. + Filename to which to print citations. If None, citations are printed + to the terminal. + verbose: bool, optional + If True, prints the citation tags for the citations that have been + registered """ if output_format == "text": citations = pybtex.format_from_strings( @@ -168,6 +204,8 @@ def print(self, filename=None, output_format="text", verbose=False): if filename is None: print(citations) + if verbose: + self.tag_citations() else: with open(filename, "w") as f: f.write(citations) @@ -186,7 +224,13 @@ def print_citations(filename=None, output_format="text", verbose=False): f"{citations._citation_err_msg}" ) else: - pybamm.citations.print(filename, output_format) + if verbose: + warnings.warn( + "Verbose output is not available for printing to files, only to the terminal" # noqa: E501 + ) + pybamm.citations.print(filename, output_format, verbose=True) + else: + pybamm.citations.print(filename, output_format) citations = Citations() From 07d1b1d0599167d6196c5ecba61291a1072c254c Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 6 Apr 2023 08:16:23 +0530 Subject: [PATCH 3/9] remove comment and unused import --- pybamm/citations.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pybamm/citations.py b/pybamm/citations.py index 75fa128640..962145dca7 100644 --- a/pybamm/citations.py +++ b/pybamm/citations.py @@ -7,8 +7,6 @@ import os import warnings import pybtex - -# from collections import OrderedDict from inspect import stack from pybtex.database import parse_file, parse_string, Entry from pybtex.scanner import PybtexError @@ -211,7 +209,6 @@ def print(self, filename=None, output_format="text", verbose=False): f.write(citations) -# todo: implement the verbose functionality def print_citations(filename=None, output_format="text", verbose=False): """See :meth:`Citations.print`""" if citations._citation_err_msg is not None: From b79d25f19fc75293c8e1d957ab355fc5b3f154cf Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 6 Apr 2023 08:20:30 +0530 Subject: [PATCH 4/9] docs --- pybamm/citations.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pybamm/citations.py b/pybamm/citations.py index 962145dca7..263a2d9a1f 100644 --- a/pybamm/citations.py +++ b/pybamm/citations.py @@ -163,10 +163,9 @@ def tag_citations(self): -------- >>> pybamm.citations.register("Doyle1993") >>> pybamm.citations.print() or pybamm.print_citations() - - Citations registered: - Sulzer2021 was cited due to the use of - pybamm.models.full_battery_models.lithium_ion.dfn + >>> Citations registered: + >>> Sulzer2021 was cited due to the use of + >>> pybamm.models.full_battery_models.lithium_ion.dfn """ if self._citation_tags: print("Citations registered:") From 2f4ad5c9335e40b199f8893226f750029dabb0b7 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 6 Apr 2023 09:06:40 +0530 Subject: [PATCH 5/9] #1182 some unit tests --- tests/unit/test_citations.py | 41 +++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_citations.py b/tests/unit/test_citations.py index 5480182e6b..91302f1763 100644 --- a/tests/unit/test_citations.py +++ b/tests/unit/test_citations.py @@ -13,7 +13,7 @@ @contextlib.contextmanager def temporary_filename(): - """Create a temporary-file and return yield it's filename""" + """Create a temporary-file and return yield its filename""" f = NamedTemporaryFile(delete=False) try: @@ -116,6 +116,7 @@ def test_marquis_2019(self): self.assertNotIn("Marquis2019", citations._papers_to_cite) pybamm.lithium_ion.SPM(build=False) self.assertIn("Marquis2019", citations._papers_to_cite) + self.assertIn("Marquis2019", citations._citation_tags.keys()) citations._reset() pybamm.lithium_ion.SPMe(build=False) @@ -127,6 +128,7 @@ def test_doyle_1993(self): self.assertNotIn("Doyle1993", citations._papers_to_cite) pybamm.lithium_ion.DFN(build=False) self.assertIn("Doyle1993", citations._papers_to_cite) + self.assertIn("Doyle1993", citations._citation_tags.keys()) def test_sulzer_2019(self): # Test that calling relevant bits of code adds the right paper to citations @@ -136,10 +138,12 @@ def test_sulzer_2019(self): self.assertNotIn("Sulzer2019asymptotic", citations._papers_to_cite) pybamm.lead_acid.LOQS(build=False) self.assertIn("Sulzer2019asymptotic", citations._papers_to_cite) + self.assertIn("Sulzer2019asymptotic", citations._citation_tags.keys()) citations._reset() pybamm.lead_acid.Full(build=False) self.assertIn("Sulzer2019physical", citations._papers_to_cite) + self.assertIn("Sulzer2019physical", citations._citation_tags.keys()) def test_timms_2021(self): # Test that calling relevant bits of code adds the right paper to citations @@ -149,36 +153,43 @@ def test_timms_2021(self): self.assertNotIn("Timms2021", citations._papers_to_cite) pybamm.current_collector.BasePotentialPair(param=None) self.assertIn("Timms2021", citations._papers_to_cite) + self.assertIn("Timms2021", citations._citation_tags.keys()) citations._reset() self.assertNotIn("Timms2021", citations._papers_to_cite) pybamm.current_collector.EffectiveResistance() self.assertIn("Timms2021", citations._papers_to_cite) + self.assertIn("Timms2021", citations._citation_tags.keys()) citations._reset() self.assertNotIn("Timms2021", citations._papers_to_cite) pybamm.current_collector.AlternativeEffectiveResistance2D() self.assertIn("Timms2021", citations._papers_to_cite) + self.assertIn("Timms2021", citations._citation_tags.keys()) citations._reset() self.assertNotIn("Timms2021", citations._papers_to_cite) pybamm.thermal.pouch_cell.CurrentCollector1D(param=None) self.assertIn("Timms2021", citations._papers_to_cite) + self.assertIn("Timms2021", citations._citation_tags.keys()) citations._reset() self.assertNotIn("Timms2021", citations._papers_to_cite) pybamm.thermal.pouch_cell.CurrentCollector2D(param=None) self.assertIn("Timms2021", citations._papers_to_cite) + self.assertIn("Timms2021", citations._citation_tags.keys()) citations._reset() self.assertNotIn("Timms2021", citations._papers_to_cite) pybamm.thermal.Lumped(param=None) self.assertIn("Timms2021", citations._papers_to_cite) + self.assertIn("Timms2021", citations._citation_tags.keys()) citations._reset() self.assertNotIn("Timms2021", citations._papers_to_cite) pybamm.thermal.OneDimensionalX(param=None) self.assertIn("Timms2021", citations._papers_to_cite) + self.assertIn("Timms2021", citations._citation_tags.keys()) def test_subramanian_2005(self): # Test that calling relevant bits of code adds the right paper to citations @@ -190,6 +201,7 @@ def test_subramanian_2005(self): None, "negative", {"particle": "quadratic profile"}, "primary" ) self.assertIn("Subramanian2005", citations._papers_to_cite) + self.assertIn("Subramanian2005", citations._citation_tags.keys()) citations._reset() self.assertNotIn("Subramanian2005", citations._papers_to_cite) @@ -197,6 +209,7 @@ def test_subramanian_2005(self): None, "negative", {"particle": "quadratic profile"}, "primary" ) self.assertIn("Subramanian2005", citations._papers_to_cite) + self.assertIn("Subramanian2005", citations._citation_tags.keys()) def test_brosaplanella_2021(self): # Test that calling relevant bits of code adds the right paper to citations @@ -206,6 +219,7 @@ def test_brosaplanella_2021(self): self.assertNotIn("BrosaPlanella2021", citations._papers_to_cite) pybamm.electrolyte_conductivity.Integrated(None) self.assertIn("BrosaPlanella2021", citations._papers_to_cite) + self.assertIn("BrosaPlanella2021", citations._citation_tags.keys()) def test_brosaplanella_2022(self): # Test that calling relevant bits of code adds the right paper to citations @@ -235,6 +249,7 @@ def test_brosaplanella_2022(self): build=False, options={"lithium plating": "irreversible"} ) self.assertIn("BrosaPlanella2022", citations._papers_to_cite) + self.assertIn("BrosaPlanella2022", citations._citation_tags.keys()) citations._reset() def test_newman_tobias(self): @@ -246,7 +261,9 @@ def test_newman_tobias(self): self.assertNotIn("Chu2020", citations._papers_to_cite) pybamm.lithium_ion.NewmanTobias() self.assertIn("Newman1962", citations._papers_to_cite) + self.assertIn("Newman1962", citations._citation_tags.keys()) self.assertIn("Chu2020", citations._papers_to_cite) + self.assertIn("Chu2020", citations._citation_tags.keys()) def test_scikit_fem(self): citations = pybamm.citations @@ -255,6 +272,7 @@ def test_scikit_fem(self): self.assertNotIn("Gustafsson2020", citations._papers_to_cite) pybamm.ScikitFiniteElement() self.assertIn("Gustafsson2020", citations._papers_to_cite) + self.assertIn("Gustafsson2020", citations._citation_tags.keys()) def test_reniers_2019(self): # Test that calling relevant bits of code adds the right paper to citations @@ -264,6 +282,7 @@ def test_reniers_2019(self): self.assertNotIn("Reniers2019", citations._papers_to_cite) pybamm.active_material.LossActiveMaterial(None, "negative", None, True) self.assertIn("Reniers2019", citations._papers_to_cite) + self.assertIn("Reniers2019", citations._citation_tags.keys()) def test_mohtat_2019(self): citations = pybamm.citations @@ -274,6 +293,7 @@ def test_mohtat_2019(self): pybamm.ParameterValues("Marquis2019") )._get_electrode_soh_sims_full() self.assertIn("Mohtat2019", citations._papers_to_cite) + self.assertIn("Mohtat2019", citations._citation_tags.keys()) def test_mohtat_2021(self): citations = pybamm.citations @@ -282,6 +302,7 @@ def test_mohtat_2021(self): self.assertNotIn("Mohtat2021", citations._papers_to_cite) pybamm.external_circuit.CCCVFunctionControl(None, None) self.assertIn("Mohtat2021", citations._papers_to_cite) + self.assertIn("Mohtat2021", citations._citation_tags.keys()) def test_sripad_2020(self): citations = pybamm.citations @@ -290,11 +311,13 @@ def test_sripad_2020(self): self.assertNotIn("Sripad2020", citations._papers_to_cite) pybamm.kinetics.Marcus(None, None, None, None, None) self.assertIn("Sripad2020", citations._papers_to_cite) + self.assertIn("Sripad2020", citations._citation_tags.keys()) citations._reset() self.assertNotIn("Sripad2020", citations._papers_to_cite) pybamm.kinetics.MarcusHushChidsey(None, None, None, None, None) self.assertIn("Sripad2020", citations._papers_to_cite) + self.assertIn("Sripad2020", citations._citation_tags.keys()) def test_parameter_citations(self): citations = pybamm.citations @@ -302,30 +325,40 @@ def test_parameter_citations(self): citations._reset() pybamm.ParameterValues("Chen2020") self.assertIn("Chen2020", citations._papers_to_cite) + self.assertIn("Chen2020", citations._citation_tags.keys()) citations._reset() pybamm.ParameterValues("NCA_Kim2011") self.assertIn("Kim2011", citations._papers_to_cite) + self.assertIn("Kim2011", citations._citation_tags.keys()) citations._reset() pybamm.ParameterValues("Marquis2019") self.assertIn("Marquis2019", citations._papers_to_cite) + self.assertIn("Marquis2019", citations._citation_tags.keys()) citations._reset() pybamm.ParameterValues("Sulzer2019") self.assertIn("Sulzer2019physical", citations._papers_to_cite) + self.assertIn("Sulzer2019physical", citations._citation_tags.keys()) citations._reset() pybamm.ParameterValues("Ecker2015") self.assertIn("Ecker2015i", citations._papers_to_cite) + self.assertIn("Ecker2015i", citations._citation_tags.keys()) self.assertIn("Ecker2015ii", citations._papers_to_cite) + self.assertIn("Ecker2015ii", citations._citation_tags.keys()) self.assertIn("Zhao2018", citations._papers_to_cite) + self.assertIn("Zhao2018", citations._citation_tags.keys()) self.assertIn("Hales2019", citations._papers_to_cite) + self.assertIn("Hales2019", citations._citation_tags.keys()) self.assertIn("Richardson2020", citations._papers_to_cite) + self.assertIn("Richardson2020", citations._citation_tags.keys()) citations._reset() pybamm.ParameterValues("ORegan2022") self.assertIn("ORegan2022", citations._papers_to_cite) + self.assertIn("ORegan2022", citations._citation_tags.keys()) def test_solver_citations(self): # Test that solving each solver adds the right citations @@ -335,28 +368,33 @@ def test_solver_citations(self): self.assertNotIn("Virtanen2020", citations._papers_to_cite) pybamm.ScipySolver() self.assertIn("Virtanen2020", citations._papers_to_cite) + self.assertIn("Virtanen2020", citations._citation_tags.keys()) citations._reset() self.assertNotIn("Virtanen2020", citations._papers_to_cite) pybamm.AlgebraicSolver() self.assertIn("Virtanen2020", citations._papers_to_cite) + self.assertIn("Virtanen2020", citations._citation_tags.keys()) if pybamm.have_scikits_odes(): citations._reset() self.assertNotIn("Malengier2018", citations._papers_to_cite) pybamm.ScikitsOdeSolver() self.assertIn("Malengier2018", citations._papers_to_cite) + self.assertIn("Malengier2018", citations._citation_tags.keys()) citations._reset() self.assertNotIn("Malengier2018", citations._papers_to_cite) pybamm.ScikitsDaeSolver() self.assertIn("Malengier2018", citations._papers_to_cite) + self.assertIn("Malengier2018", citations._citation_tags.keys()) if pybamm.have_idaklu(): citations._reset() self.assertNotIn("Hindmarsh2005", citations._papers_to_cite) pybamm.IDAKLUSolver() self.assertIn("Hindmarsh2005", citations._papers_to_cite) + self.assertIn("Hindmarsh2005", citations._citation_tags.keys()) @unittest.skipIf(not pybamm.have_jax(), "jax or jaxlib is not installed") def test_jax_citations(self): @@ -365,6 +403,7 @@ def test_jax_citations(self): self.assertNotIn("jax2018", citations._papers_to_cite) pybamm.JaxSolver() self.assertIn("jax2018", citations._papers_to_cite) + self.assertIn("jax2018", citations._citation_tags.keys()) if __name__ == "__main__": From 2fc0611f8d0e826bed1117fc8cbb8dcfc37e2b62 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 6 Apr 2023 21:07:03 +0530 Subject: [PATCH 6/9] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27b39d9534..25da09c4b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ # Features +- 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)) - Updated to casadi 3.6, which required some changes to the casadi integrator. ([#2859](https://github.com/pybamm-team/PyBaMM/pull/2859)) ## Bug fixes From ef03f368b7763782c8230982ccfedd3f0d4ec7d0 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 6 Apr 2023 22:17:17 +0530 Subject: [PATCH 7/9] fix ubuntu doctest --- pybamm/citations.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pybamm/citations.py b/pybamm/citations.py index 263a2d9a1f..69a8f6ab80 100644 --- a/pybamm/citations.py +++ b/pybamm/citations.py @@ -159,13 +159,25 @@ def tag_citations(self): all citations and enable verbose output with :meth:`print_citations` or :meth:`print`. + .. note:: + If a citation is registered manually, it will not be tagged. + Examples -------- - >>> pybamm.citations.register("Doyle1993") - >>> pybamm.citations.print() or pybamm.print_citations() - >>> Citations registered: - >>> Sulzer2021 was cited due to the use of - >>> pybamm.models.full_battery_models.lithium_ion.dfn + .. code-block:: python + :linenos: + + pybamm.citations.register("Doyle1993") + pybamm.citations.print() or pybamm.print_citations() + + will print the following: + + .. code-block:: + + Citations registered: + Sulzer2021 was cited due to the use of + pybamm.models.full_battery_models.lithium_ion.dfn + """ if self._citation_tags: print("Citations registered:") From fc1bfadf0a7b2460a4e61cb623968d7b6dc803f5 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 6 Apr 2023 23:35:19 +0530 Subject: [PATCH 8/9] #1182 improve coverage --- pybamm/citations.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pybamm/citations.py b/pybamm/citations.py index 69a8f6ab80..ec9fe13144 100644 --- a/pybamm/citations.py +++ b/pybamm/citations.py @@ -130,7 +130,7 @@ def register(self, key): caller = Citations._caller_name() self._add_citation_tag(key, entry=caller) # Don't add citation tags if the citation is registered manually - except KeyError: + except KeyError: # pragma: no cover pass return @@ -150,7 +150,7 @@ def register(self, key): # Unable to parse / unknown key raise KeyError(f"Not a bibtex citation or known citation: {key}") - def tag_citations(self): + def tag_citations(self): # pragma: no cover """Prints the citations tags for the citations that have been registered (non-manually). This is used for verbose output when printing citations such that it can be seen which citations were registered by PyBaMM classes. @@ -232,7 +232,7 @@ def print_citations(filename=None, output_format="text", verbose=False): f"{citations._citation_err_msg}" ) else: - if verbose: + if verbose: # pragma: no cover warnings.warn( "Verbose output is not available for printing to files, only to the terminal" # noqa: E501 ) From a46003528a52243ce5fac9779e5782ac6f1dc1a1 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Fri, 7 Apr 2023 21:01:30 +0530 Subject: [PATCH 9/9] increase coverage --- pybamm/citations.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pybamm/citations.py b/pybamm/citations.py index ec9fe13144..f3f4ed06e0 100644 --- a/pybamm/citations.py +++ b/pybamm/citations.py @@ -155,8 +155,8 @@ def tag_citations(self): # pragma: no cover (non-manually). This is used for verbose output when printing citations such that it can be seen which citations were registered by PyBaMM classes. - To use, call :meth:`tag_citations` after calling :meth:`register` for - all citations and enable verbose output with :meth:`print_citations` + To use, either call :meth:`tag_citations` after calling :meth:`register` + for all citations, or enable verbose output with :meth:`print_citations` or :meth:`print`. .. note:: @@ -180,7 +180,7 @@ def tag_citations(self): # pragma: no cover """ if self._citation_tags: - print("Citations registered:") + print("\n Citations registered: \n") for key, entry in self._citation_tags.items(): print(f"{key} was cited due to the use of {entry}") @@ -214,7 +214,7 @@ def print(self, filename=None, output_format="text", verbose=False): if filename is None: print(citations) if verbose: - self.tag_citations() + self.tag_citations() # pragma: no cover else: with open(filename, "w") as f: f.write(citations)