Skip to content

gh-438: Add grad tests for all applicable functions - #1251

Merged
paddyroddy merged 49 commits into
mainfrom
connor/add-more-grad-tests
Oct 20, 2026
Merged

paddyroddy merged 49 commits into
mainfrom
connor/add-more-grad-tests

Conversation

@connoraird

@connoraird connoraird commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Description

  • Adds gradients tests for all performance critical functions which take in and return an array.

Closes: #438

Changelog entry

Changed: Pinned JAX to <0.12.0 due to a change in multinomial behaviour.

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 Oct 8, 2026
@connoraird connoraird added array-api Work is related to the Array API jax-porting Removing mutation to make the code JAX compatible labels Oct 8, 2026
@connoraird
connoraird force-pushed the connor/add-more-grad-tests branch from 2c91928 to deff382 Compare October 9, 2026 16:39
@connoraird connoraird changed the title gh-: Add grad tests for all applicable functions gh-438: Add grad tests for all applicable functions Oct 9, 2026
@connoraird connoraird mentioned this pull request Oct 15, 2026
3 of 5 tasks
@connoraird
connoraird force-pushed the connor/add-more-grad-tests branch from d8891a8 to fb2f0aa Compare October 16, 2026 08:48
@connoraird
connoraird force-pushed the connor/add-more-grad-tests branch from d497974 to 6b0c0f0 Compare October 16, 2026 13:24
@connoraird
connoraird changed the base branch from main to connor/1267-make-radwin-diffable October 16, 2026 13:24
@connoraird
connoraird changed the base branch from connor/1267-make-radwin-diffable to main October 16, 2026 14:48
@connoraird
connoraird force-pushed the connor/add-more-grad-tests branch from 6b0c0f0 to be78ea4 Compare October 16, 2026 14:49
@paddyroddy

Copy link
Copy Markdown
Member

I think the multiple dtype=jnp.float64 were needed otherwise the values default to integer which makes the functions not auto-differentiable.

Okay, I'll have a look. Wonder if we can force it with, e.g. 1.0.

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

My comments are stale. I've done various changes to keep the formatting consistent with the rest of the codebase. This is a great piece of work!

I also fixed the readthedocs bug and a JAX bug coming from 0.12.0.

Comment thread pyproject.toml
"ANN202", # missing-return-type-private-function
"D100", # undocumented-public-module
"D103", # TODO: undocumented-public-function
"FBT001", # boolean-type-hint-positional-argument

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.

Probably makes sense

Comment thread tests/gradients/test_shells.py Outdated
jnp: ModuleType,
) -> None:
"""Tests glass.VolumeWeight is auto differentiable."""
z = jnp.linspace(0.1, 1, 6, dtype=jnp.float64)

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.

Shouldn't need to specify the dtype here as we're using the jnp fixture.

Comment thread tests/gradients/test_arraytools.py Outdated

pytest.importorskip("jax", reason="tests require jax")

import jax.numpy as jnp

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.

What about the fixture?

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 had been expecting this as a series of PRs. Impressive work as one. But things like this would have been caught earlier.

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, in hind-sight multiple PRs would have been better.

@paddyroddy paddyroddy mentioned this pull request Oct 19, 2026
3 of 5 tasks

@connoraird connoraird left a comment

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.

A few minor comments but I'm happy with it, if you are.

Comment thread tests/core/test_array_api_utils.py Resolved
Comment thread tests/core/test_jax.py
jnp: ModuleType,
size_input: int | tuple[int, ...] | None,
shape_output: tuple[int, ...],
size_input: int | tuple[int, ...] | None,

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.

There are a lot of changes unrelated to this PR in here. Perhaps that's okay since we're nearing the end but just wanted to mention it.

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.

Totally fair to call out. I just spotted we had stopped following established patterns.

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.

Got a little carried away.

Comment thread tests/fixtures/array_backends.py Resolved
Comment thread .readthedocs.yaml
Comment on lines +8 to +10
jobs:
post_checkout:
- git fetch --unshallow --tags origin || true

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.

Fixes the readthedocs bug

def test_apply_visibility(jnp: ModuleType) -> None:
"""Tests glass.points._apply_visibility is auto differentiable."""
k = (1, 1)
n = 24751.77674965 * jnp.ones(12)

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.

This is very precise!

@paddyroddy

Copy link
Copy Markdown
Member

This looks good now, going to merge!

@paddyroddy
paddyroddy merged commit 8ffa463 into main Oct 20, 2026
15 of 16 checks passed
@paddyroddy
paddyroddy deleted the connor/add-more-grad-tests branch October 20, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

array-api Work is related to the Array API jax-porting Removing mutation to make the code JAX compatible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test all performance critical funtions with jax.test_util.check_grads to ensure differentiability

2 participants