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

feat: pot call allows all options #331

Merged
merged 2 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 6 additions & 8 deletions src/galax/potential/_potential/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,14 @@ def potential(
return potential(self, *args, **kwargs)

@partial(jax.jit)
def __call__(
self, q: gt.LengthBatchVec3, /, t: gt.BatchableRealQScalar
) -> Float[Quantity["specific energy"], "*batch"]:
def __call__(self, *args: Any) -> Float[Quantity["specific energy"], "*batch"]:
"""Compute the potential energy at the given position(s).

Parameters
----------
q : Quantity[float, (*batch, 3), 'length']
The position to compute the value of the potential.
t : Array[float | int, *batch] | float | int
The time at which to compute the value of the potential.
*args : Any
Arguments to pass to the potential method.
See :func:`~galax.potential.potential`.

Returns
-------
Expand All @@ -180,9 +177,10 @@ def __call__(

See Also
--------
:func:`galax.potential.potential`
:meth:`galax.potential.AbstractPotentialBase.potential`
"""
return self.potential(q, t)
return self.potential(*args)

# ---------------------------------------
# Gradient
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/potential/io/test_gala.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def test_galax_to_gala_to_galax_roundtrip(
rpot = gp.io.gala_to_galax(galax_to_gala(pot))

# quick test that the potential energies are the same
got = rpot(x, t=0)
exp = pot(x, t=0)
got = rpot(x, 0)
exp = pot(x, 0)
assert qnp.allclose(got, exp, atol=Quantity(1e-14, exp.unit))

# TODO: add more robust tests
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/potential/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_potential_batch(

def test_call(self, pot: AbstractPotentialBase, x: gt.QVec3) -> None:
"""Test the `AbstractPotentialBase.__call__` method."""
assert xp.equal(pot(x, t=0), pot.potential(x, t=0))
assert xp.equal(pot(x, 0), pot.potential(x, 0))

@abstractmethod
def test_gradient(self, pot: AbstractPotentialBase, x: gt.QVec3) -> None:
Expand Down