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: Support JAX array API before and after JAX v0.4.1 #2280

Merged
merged 7 commits into from
Aug 16, 2023
Merged
12 changes: 10 additions & 2 deletions src/pyhf/tensor/jax_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@

log = logging.getLogger(__name__)

# v0.7.x backport hack
_old_jax_version = False
try:
from jax import Array
except ImportError:
# jax.Array added in jax v0.4.1
_old_jax_version = True


class _BasicPoisson:
def __init__(self, rate):
Expand Down Expand Up @@ -54,10 +62,10 @@ class jax_backend:
__slots__ = ['name', 'precision', 'dtypemap', 'default_do_grad']

#: The array type for jax
array_type = jnp.DeviceArray
array_type = jnp.DeviceArray if _old_jax_version else Array

#: The array content type for jax
array_subtype = jnp.DeviceArray
array_subtype = jnp.DeviceArray if _old_jax_version else Array

def __init__(self, **kwargs):
self.name = 'jax'
Expand Down
2 changes: 1 addition & 1 deletion tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ def validate_hypotest(
{'init_pars': 2, 'par_bounds': 2},
1.0,
"q",
2e-9,
3e-6,
"asymptotics",
),
(
Expand Down