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

Added a condition for jaxlib imports #1803

Merged

Conversation

Saransh-cpp
Copy link
Member

@Saransh-cpp Saransh-cpp commented Nov 13, 2021

Description

If jax is already installed in an environment where the user updates pybamm to develop, importing pybamm gives the following error (as jaxlib is not available on windows but jax is) -

raise ModuleNotFoundError(
ModuleNotFoundError: jax requires jaxlib to be installed. See https://github.com/google/jax#installation for installation instructions.

Fixes #1801

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • No style issues: $ flake8
  • All tests pass: $ python run-tests.py --unit
  • The documentation builds: $ cd docs and then $ make clean; make html

You can run all three at once, using $ python run-tests.py --quick.

Further checks:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

return importlib.util.find_spec("jax") is not None
"""Check if jax and jaxlib are installed"""
return (importlib.util.find_spec("jax") is not None) and (
importlib.util.find_spec("jaxlib") is not None
Copy link
Member Author

Choose a reason for hiding this comment

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

Another approach would be to create a new have_jaxlib function to carry out this condition, but I am not sure if that would be better

With have_jaxlib we will be able to point out if jaxlib is not installed. Otherwise, I guess the exceptions would be "Jax or jaxlib not installed"

Copy link
Member

Choose a reason for hiding this comment

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

Creating have_jaxlib would complicate things unnecessarily

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes

@codecov
Copy link

codecov bot commented Nov 13, 2021

Codecov Report

Merging #1803 (70b5826) into develop (4aa4776) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #1803   +/-   ##
========================================
  Coverage    99.24%   99.24%           
========================================
  Files          345      345           
  Lines        19049    19049           
========================================
  Hits         18906    18906           
  Misses         143      143           
Impacted Files Coverage Δ
...bamm/expression_tree/operations/evaluate_python.py 97.58% <ø> (ø)
pybamm/solvers/jax_bdf_solver.py 98.04% <ø> (ø)
pybamm/solvers/jax_solver.py 96.77% <ø> (ø)
pybamm/util.py 97.12% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4aa4776...70b5826. Read the comment docs.

Copy link
Member

@valentinsulzer valentinsulzer left a comment

Choose a reason for hiding this comment

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

Thanks!

@valentinsulzer valentinsulzer merged commit d69db28 into pybamm-team:develop Nov 13, 2021
@Saransh-cpp Saransh-cpp deleted the issue-1801-jaxlib-imports branch November 14, 2021 06:23
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.

Jaxlib not supported on windows so can we make the imports optional
3 participants