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

Fixes following phasespaceposition #12

Merged
merged 1 commit into from
Dec 5, 2023
Merged
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
9 changes: 1 addition & 8 deletions src/galdynamix/potential/_potential/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __call__(self, q: jt.Array, /, t: jt.Array) -> jt.Array:
return self.potential_energy(q, t)

@partial_jit()
def gradient(self, q: jt.Array, /, t: jt.Array) -> jt.Array: phasespaceposition
def gradient(self, q: jt.Array, /, t: jt.Array) -> jt.Array:
"""Compute the gradient of the potential at the given position(s).

Parameters
Expand Down Expand Up @@ -126,15 +126,8 @@ def density(self, q: jt.Array, /, t: jt.Array) -> jt.Array:
:class:`~jax.Array`
The potential energy or value of the potential.
"""
lap = xp.trace(jax.hessian(self.potential_energy)(q, t))
"""Compute the gradient."""
return jax.grad(self.potential_energy, argnums=0)(q, t)

@partial_jit()
def density(self, q: jt.Array, /, t: jt.Array) -> jt.Array:
# Note: trace(jacobian(gradient)) is faster than trace(hessian(energy))
lap = xp.trace(jax.jacfwd(self.gradient)(q, t))

return lap / (4 * xp.pi * self._G)

@partial_jit()
Expand Down