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 optional dependencies error detection and remove pybtex hidden dependency #3968

Merged
merged 14 commits into from
Apr 14, 2024

Conversation

lorenzofavaro
Copy link
Contributor

@lorenzofavaro lorenzofavaro commented Apr 7, 2024

Description

The goal of this PR is to solve two problems.

  • Remove optional dependencies present in the base version of PyBaMM, so that pybamm can be imported without optional dependencies installed
  • Fix error detection: when an optional dependency is present in non-optional modules, we need to detect these errors and report them.

Fixes #3940

  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • No style issues: $ pre-commit run (or $ nox -s pre-commit)
  • All tests pass: $ python run-tests.py --all (or $ nox -s tests)
  • The documentation builds: $ python run-tests.py --doctest (or $ nox -s doctests)

@agriyakhetarpal
Copy link
Member

agriyakhetarpal commented Apr 8, 2024

Thanks, @lorenzofavaro – with the failing tests we can confirm that we are now testing the PyBaMM import correctly and properly :) I guess the next step is the one you highlighted about pybtex's import being required for PyBaMM's import, which should get revised so that it is only done when someone does pybamm.print_citations() and not when one does import pybamm. Maybe doing so is as easy as either moving self.read_citations() to Citations.print() plus moving self._reset() out of __init__ (since the docstring mentions that it is used for testing purposes, or moving the citations.register() bits), or using try-except blocks again (which would be less desirable).

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@lorenzofavaro
Copy link
Contributor Author

lorenzofavaro commented Apr 9, 2024

Maybe doing so is as easy as either moving self.read_citations() to Citations.print() plus moving self._reset() out of init (since the docstring mentions that it is used for testing purposes, or moving the citations.register() bits), or using try-except blocks again (which would be less desirable).

Thanks @agriyakhetarpal, I tried this way but the problem was being able to handle a single instance of the object, and unit tests were failing. It seems like it is not the intended use of it, so either we change the way we use citations (adjusting all the unit tests) or we change the implementation.

I followed the second way and the solution I found was using the singleton pattern.
I also took the opportunity to add a handy api to register new citations with pybamm.register_citation(...).

Let me know if this solution is fine for you. I'm open to implement any other better ways.

Copy link

codecov bot commented Apr 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.58%. Comparing base (09ee982) to head (9eea94e).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3968   +/-   ##
========================================
  Coverage    99.58%   99.58%           
========================================
  Files          257      257           
  Lines        21245    21249    +4     
========================================
+ Hits         21157    21161    +4     
  Misses          88       88           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @lorenzofavaro, this is great – just a single comment about the new API for registering citations which probably needs a revisit :)

pybamm/citations.py Outdated Show resolved Hide resolved
pybamm/citations.py Outdated Show resolved Hide resolved
@agriyakhetarpal
Copy link
Member

Also, could we update the documentation for the optional dependencies section in the Contributing guide in this PR as necessary, as we had discussed?

pybamm/citations.py Outdated Show resolved Hide resolved
pybamm/citations.py Outdated Show resolved Hide resolved
pybamm/citations.py Outdated Show resolved Hide resolved
pybamm/citations.py Outdated Show resolved Hide resolved
lorenzofavaro and others added 7 commits April 10, 2024 00:23
Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>
Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>
Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>
Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>
Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all great to me now, thanks for the fixes, @lorenzofavaro! Let's hope CI passes on this one, I have no other comments.

@agriyakhetarpal
Copy link
Member

@all-contributors please add @lorenzofavaro for docs

Copy link
Contributor

@agriyakhetarpal

I've put up a pull request to add @lorenzofavaro! 🎉

Copy link
Member

@arjxn-py arjxn-py left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lorenzofavaro, This looks good to me and I'd be happy to merge this seeing the priority. but -

CONTRIBUTING.md Show resolved Hide resolved
pybamm/citations.py Show resolved Hide resolved
@agriyakhetarpal
Copy link
Member

Resolving previous conversations for now and all tests are passing – let's merge

@agriyakhetarpal agriyakhetarpal merged commit 9f8b361 into pybamm-team:develop Apr 14, 2024
38 of 40 checks passed
js1tr3 pushed a commit to js1tr3/PyBaMM that referenced this pull request Aug 12, 2024
…dependency (pybamm-team#3968)

* Edit pybamm import test

* Guard pybtex imports

* Update pybamm/citations.py

Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>

* Update pybamm/citations.py (1)

Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>

* Update pybamm/citations.py (2)

Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>

* Update pybamm/citations.py (3)

Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>

* Update contributing guidelines

* Exclude excepts from test coverage

* style: pre-commit fixes

---------

Co-authored-by: Lorenzo Favaro <lorenzofavaro@users.noreply.github.com>
Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Eric G. Kratz <kratman@users.noreply.github.com>
Co-authored-by: Arjun Verma <arjunverma.oc@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PyBaMM import error - Cannot run anything (import broken due to pybtex)
5 participants