kups.potential.common.evaluation
¶
Utilities for evaluating potentials outside of JIT-compiled simulation loops.
These functions handle the boilerplate of constructing a one-shot potential call with assertion-based retry logic, making it straightforward to evaluate energies, forces, and Hessians for analysis or initialisation purposes.
evaluate_ewald_potential(point_cloud, parameters, *, gradient_lens=EMPTY_LENS, hessian_lens=EMPTY_LENS, hessian_idx_view=EMPTY_LENS)
¶
Evaluate the full Ewald potential: long-range + short-range + self-interaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point_cloud
|
PointCloud[IsEwaldPointData, HasUnitCell]
|
Particles and systems for the Ewald sum. |
required |
parameters
|
EwaldParameters
|
Ewald parameters (alpha, cutoff, k-vectors, cache). |
required |
gradient_lens
|
Lens[PointCloud[IsEwaldPointData, HasUnitCell], Gradients]
|
Lens selecting the differentiation target on |
EMPTY_LENS
|
hessian_lens
|
Lens[Gradients, Hessians]
|
Lens selecting the gradient for Hessian computation. |
EMPTY_LENS
|
hessian_idx_view
|
View[PointCloud[IsEwaldPointData, HasUnitCell], Hessians]
|
View used to index into the Hessian output. |
EMPTY_LENS
|
Returns:
| Type | Description |
|---|---|
PotentialOut[Gradients, Hessians]
|
|
Source code in src/kups/potential/common/evaluation.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
evaluate_potential(input, *, energy_fn, gradient_lens=EMPTY_LENS, hessian_lens=EMPTY_LENS, hessian_idx_view=EMPTY_LENS)
¶
Evaluate an energy function on a plain input struct (no graph construction).
Useful for potentials whose input is already fully constructed (e.g. Ewald long-range, self-interaction).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
Input
|
Input passed directly to |
required |
energy_fn
|
EnergyFunction[Input, Input]
|
Energy function to evaluate. |
required |
gradient_lens
|
Lens[Input, Gradients]
|
Lens selecting the output to differentiate with respect to. |
EMPTY_LENS
|
hessian_lens
|
Lens[Gradients, Hessians]
|
Lens selecting the gradient output for the Hessian. |
EMPTY_LENS
|
hessian_idx_view
|
View[Input, Hessians]
|
View used to index into the Hessian output. |
EMPTY_LENS
|
Returns:
| Type | Description |
|---|---|
PotentialOut[Gradients, Hessians]
|
|
Source code in src/kups/potential/common/evaluation.py
evaluate_potential_and_fix(potential, state, patch=None, /, max_tries=10)
¶
Evaluate a potential, retrying with assertion fixes until it succeeds.
On each attempt, failed assertions are fixed via their fix functions.
Assertions without a fix function will raise immediately.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
potential
|
Callable[[State, P | None], Result[State, WithPatch[PotentialOut[Gradients, Hessians], Patch[State]]]]
|
Assertion-aware potential (e.g. from |
required |
state
|
State
|
Current simulation state. |
required |
patch
|
P | None
|
Optional patch passed through to the potential. |
None
|
max_tries
|
int
|
Maximum number of retry attempts before raising. |
10
|
Returns:
| Type | Description |
|---|---|
tuple[State, WithPatch[PotentialOut[Gradients, Hessians], Patch[State]]]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If called inside a JAX-traced context. |
RuntimeError
|
If the potential still fails after |
Source code in src/kups/potential/common/evaluation.py
evaluate_radius_graph_potential(point_cloud, parameters, *, cutoffs=None, energy_fn, gradient_lens=EMPTY_LENS, hessian_lens=EMPTY_LENS, hessian_idx_view=EMPTY_LENS)
¶
Build a radius graph and evaluate an edge-based energy function on it.
Uses a pessimistic DenseNearestNeighborList sized to the largest system,
growing as needed via assertion retries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point_cloud
|
PointCloud[P, S]
|
Particles and systems (unit cell). |
required |
parameters
|
Parameters
|
Parameters forwarded to |
required |
cutoffs
|
Table[SystemId, Array] | None
|
Indexed cutoff data per system. If None, tries to extract
from |
None
|
energy_fn
|
EnergyFunction[Any, GraphPotentialInput[Parameters, P, S, Literal[2]]]
|
Edge-based energy function. |
required |
gradient_lens
|
Lens[GraphPotentialInput[Parameters, P, S, Literal[2]], Gradients]
|
Lens selecting the differentiation target. |
EMPTY_LENS
|
hessian_lens
|
Lens[Gradients, Hessians]
|
Lens selecting the gradient for Hessian computation. |
EMPTY_LENS
|
hessian_idx_view
|
View[Any, Hessians]
|
View used to index into the Hessian output. |
EMPTY_LENS
|
Returns:
| Type | Description |
|---|---|
PotentialOut[Gradients, Hessians]
|
|
Source code in src/kups/potential/common/evaluation.py
potential_with_assertions(potential)
¶
Wrap a potential so its output is lifted into a Result carrying assertions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
potential
|
Potential[State, G, H, P]
|
The potential to wrap. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[State, P | None], Result[State, WithPatch[PotentialOut[G, H], Patch[State]]]]
|
A callable with the same signature that returns a |
Callable[[State, P | None], Result[State, WithPatch[PotentialOut[G, H], Patch[State]]]]
|
a raw |