Skip to content

Added a condition for jaxlib imports - #1803

Merged
valentinsulzer merged 2 commits into
pybamm-team:developfrom
Saransh-cpp:issue-1801-jaxlib-imports
Nov 13, 2021
Merged

Added a condition for jaxlib imports#1803
valentinsulzer merged 2 commits into
pybamm-team:developfrom
Saransh-cpp:issue-1801-jaxlib-imports

Conversation

@Saransh-cpp

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

Copy link
Copy Markdown
Member

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

Comment thread pybamm/util.py
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

@Saransh-cpp Saransh-cpp Nov 13, 2021

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes

@codecov

codecov Bot commented Nov 13, 2021

Copy link
Copy Markdown

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.

@valentinsulzer valentinsulzer left a comment

Copy link
Copy Markdown
Member

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