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

Using unit systems in grad #241

Open
adrn opened this issue Oct 19, 2024 · 1 comment
Open

Using unit systems in grad #241

adrn opened this issue Oct 19, 2024 · 1 comment

Comments

@adrn
Copy link
Contributor

adrn commented Oct 19, 2024

I tried this thinking it might work and was surprised that it throws an error -- is this a bug or not something we can support at the moment?

import jax
import astropy.units as u
from unxt import Quantity
from unxt import experimental


length = u.get_physical_type("length")
time = u.get_physical_type("time")
velocity = u.get_physical_type("velocity")


@jax.jit
def test_ad1(x: Quantity[length], t: Quantity[time]) -> Quantity[velocity]:
    return x / t


experimental.grad(test_ad1, units="si", argnums=1)(
    Quantity(15.0, u.m), Quantity(1.0, u.s)
)
...
UnitConversionError: 'm' (length) and 's' (time) are not convertible
@nstarman
Copy link
Contributor

We should figure out how to support this!

The following does already work.

experimental.grad(test_ad1, units=(u.m, u.s), argnums=1)(
    Quantity(15.0, u.m), Quantity(1.0, u.s)
)

But just "si" would be simpler.

@nstarman nstarman changed the title Grad through a quantity function Using unit systems in grad Dec 3, 2024
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

No branches or pull requests

2 participants