Skip to content

gh-1063: Default to numpy for all unrecognised array backends#1065

Merged
connoraird merged 5 commits into
mainfrom
connor/1063-default-to-numpy
May 11, 2026
Merged

gh-1063: Default to numpy for all unrecognised array backends#1065
connoraird merged 5 commits into
mainfrom
connor/1063-default-to-numpy

Conversation

@connoraird

@connoraird connoraird commented May 11, 2026

Copy link
Copy Markdown
Contributor

Description

  • Adds logic to default to numpy for any given backend which is not explicitly supported by GLASS.
  • Skips a test which relies on array_api_strict if it isn't installed.
  • Also adds CuPy as a library for testing to check this new functionality.

Closes: #1063

Changelog entry

Changed: Instead of raising an exception, we now default to NumPy if an array backend is not supported.

Checks

  • Is your code passing linting?
  • Is your code passing tests?
  • Have you added additional tests (if required)?
  • Have you modified/extended the documentation (if required)?
  • Have you added a one-liner changelog entry above (if required)?

@connoraird connoraird self-assigned this May 11, 2026
@connoraird connoraird marked this pull request as ready for review May 11, 2026 12:02
@connoraird connoraird requested a review from paddyroddy May 11, 2026 12:06

@paddyroddy paddyroddy 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.

Some Qs

Comment thread glass/_array_api_utils.py Outdated
Comment thread glass/_array_api_utils.py
Comment thread glass/_array_api_utils.py
Comment thread glass/_rng.py
@pytest.mark.skipif(not HAVE_JAX, reason="test requires jax")
def test_rng_dispatcher_jax() -> None:
import jax.numpy as jnp
import jax.numpy as jnp # ty: ignore[unresolved-import]

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.

Trying to work out why we need now 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'm not sure why this wasn't a problem before. I guess we haven't ran ty against this file before? Shoudl we just ignore that rule everywhere?

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.

It's probably just that ty has updated since we last ran it. I think leave ty on for now as it's still early in development.

compare.assert_array_equal(old, new)


@pytest.mark.skipif(not HAVE_ARRAY_API_STRICT, reason="test requires array_api_strict")

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.

Do we need this now from the work of this PR or is this something previously missed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this was previously missed. I just tried to run with ARRAY_BACKEND=numpy and got an error.

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.

Not sure how we missed that. Are we missing something in our CI for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If we always install array-api-strict, then it'll pass.

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.

I know. But we could have a separate test to ensure we're testing it properly. I'm thinking something along the lines of #670

@paddyroddy paddyroddy 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.

Looks good

@connoraird connoraird merged commit 5042a46 into main May 11, 2026
22 checks passed
@connoraird connoraird deleted the connor/1063-default-to-numpy branch May 11, 2026 15:40
@paddyroddy paddyroddy mentioned this pull request Jun 4, 2026
5 tasks
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.

Default to NumPy if a function is not supported

2 participants