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

Jax cli #1881

Merged
merged 9 commits into from
Jan 20, 2022
Merged

Jax cli #1881

Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# [Unreleased](https://github.com/pybamm-team/PyBaMM/)

## Features

- Added an option to force install compatible versions of jax and jaxlib if already installed using CLI ([#1881](https://github.com/pybamm-team/PyBaMM/pull/1881))

# [v21.12](https://github.com/pybamm-team/PyBaMM/tree/v21.11) - 2021-12-29

## Features
Expand Down
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion pybamm/parameters_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def edit_parameter(arguments=None):

.. code::

edit_param(["lithium_ion"])
edit_parameter(["lithium_ion"])

will create the directory structure::

Expand Down
60 changes: 44 additions & 16 deletions pybamm/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# The code in this file is adapted from Pints
# (see https://github.com/pints-team/pints)
#
import argparse
import importlib.util
import numbers
import os
Expand All @@ -15,9 +16,9 @@
import warnings
from collections import defaultdict
from platform import system
import pkg_resources

import numpy as np
import pkg_resources

import pybamm

Expand Down Expand Up @@ -364,23 +365,50 @@ def is_jax_compatible():
)


def install_jax(): # pragma: no cover
"""Install jax, jaxlib"""
def install_jax(arguments=None): # pragma: no cover
"""
Install compatible versions of jax, jaxlib.

Command Line Interface:
-----------------------
>>> pybamm_install_jax

optional arguments:
-h, --help show help message
-f, --force force install compatible versions of jax and jaxlib
"""
parser = argparse.ArgumentParser(description="Install jax and jaxlib")
parser.add_argument(
"-f",
"--force",
action="store_true",
help=f"force install compatible versions of jax ({JAX_VERSION}) and jaxlib ({JAXLIB_VERSION})", # noqa: E501
priyanshuone6 marked this conversation as resolved.
Show resolved Hide resolved
)

args = parser.parse_args(arguments)

if system() == "Windows":
raise NotImplementedError("Jax is not available on Windows")

# Raise an error if jax and jaxlib are already installed, but incompatible
# and --force is not set
elif importlib.util.find_spec("jax") is not None:
if not is_jax_compatible():
if not args.force and not is_jax_compatible():
raise ValueError(
"Jax is already installed but the installed version of jax or jaxlib is not supported by PyBaMM", # noqa: E501
f"""
Jax is already installed but the installed version of jax or jaxlib is not supported by PyBaMM.

You can force install compatible versions of jax ({JAX_VERSION}) and jaxlib ({JAXLIB_VERSION}) using the following command:
pybamm_install_jax --force""", # noqa: E501
priyanshuone6 marked this conversation as resolved.
Show resolved Hide resolved
)
else:
subprocess.check_call(
[
sys.executable,
"-m",
"pip",
"install",
f"jax=={JAX_VERSION}",
f"jaxlib=={JAXLIB_VERSION}",
]
)

subprocess.check_call(
[
sys.executable,
"-m",
"pip",
"install",
f"jax=={JAX_VERSION}",
f"jaxlib=={JAXLIB_VERSION}",
]
)