jaxdem.minimizers.routines#
Minimization routines and drivers.
Functions
|
Evaluate force and torque convergence for one set of bodies. |
|
Minimize the configured objective over body positions and orientations. |
Classes
|
Final configuration, objective value, and minimization diagnostics. |
|
Residual norms and convergence status for a mechanical relaxation. |
|
Reason an energy minimization stopped. |
- class jaxdem.minimizers.routines.TerminationReason(*values)[source]#
Bases:
IntEnumReason an energy minimization stopped.
- MAX_STEPS = 0#
- ENERGY_TOLERANCE = 1#
- ENERGY_CHANGE_TOLERANCE = 2#
- FORCE_TOLERANCE = 3#
- FORCE_TORQUE_TOLERANCE = 3#
- NONFINITE = 4#
- SEARCH_OVERFLOW = 5#
- class jaxdem.minimizers.routines.MinimizeInfo(converged: jax.Array, finite: jax.Array, force_max: jax.Array, torque_max: jax.Array, status: jax.Array)[source]#
Bases:
NamedTupleResidual norms and convergence status for a mechanical relaxation.
- Variables:
converged (jax.Array) – Boolean scalar indicating that both residual norms meet their tolerances and the evaluation is valid.
finite (jax.Array) – Boolean scalar indicating finite residual norms. Results from
minimize()also require finite objective gradients and energy.force_max (jax.Array) – Maximum Euclidean force norm over free bodies for mechanical relaxation. Objectives differentiated by AD use the maximum norm of their gradient with respect to body position.
torque_max (jax.Array) – Maximum Euclidean torque norm over free bodies for mechanical relaxation. Objectives differentiated by AD use the maximum norm of their world angular gradient.
status (jax.Array) –
Integer scalar describing convergence:
0 (
CONVERGED): both tolerances are satisfied.2 (
MAX_STEPS): residuals exceed tolerance; a completed minimization exhausted its step budget.3 (
NONFINITE): an evaluated quantity is nonfinite.4 (
COLLIDER_OVERFLOW): spatial search results are incomplete.
reason (jax.Array) – Property mapping
statusto aTerminationReasoncode. The two sets of integer codes differ.
Notes
Fields are scalar arrays for one system. Applying
jax.vmapto the evaluation adds a batch axis to each field.- converged: Array#
Alias for field number 0
- finite: Array#
Alias for field number 1
- force_max: Array#
Alias for field number 2
- torque_max: Array#
Alias for field number 3
- status: Array#
Alias for field number 4
- jaxdem.minimizers.routines.convergence_info(force: Array, torque: Array, fixed: Array, force_tol: float | Array, torque_tol: float | Array) MinimizeInfo[source]#
Evaluate force and torque convergence for one set of bodies.
- Parameters:
force (jax.Array) – Total force on each body, with shape
(n_bodies, dim).torque (jax.Array) – Total torque on each body, with shape
(n_bodies, 1)in two dimensions or(n_bodies, 3)in three dimensions.fixed (jax.Array) – Boolean mask with shape
(n_bodies,). Entries markedTrueare excluded from both residual norms, including nonfinite entries.force_tol (float or jax.Array) – Scalar absolute tolerance on the maximum body force norm.
torque_tol (float or jax.Array) – Scalar absolute tolerance on the maximum body torque norm.
- Returns:
Maximum Euclidean force and torque norms, their finiteness, and convergence status. Convergence requires both norms to be finite,
force_max <= force_tol, andtorque_max <= torque_tol.- Return type:
Notes
Empty or fully fixed body sets have zero residual norms. Finite residuals exceeding either tolerance produce
MAX_STEPS; nonfinite residuals produceNONFINITE. This function evaluates residuals only; optimizer iteration counts and spatial search overflow are handled byminimize(). Usejax.vmapto evaluate independent systems.
- class jaxdem.minimizers.routines.MinimizationResult(state: State, system: System, steps: int | jax.Array, energy: jax.Array, reason: jax.Array, info: MinimizeInfo)#
Bases:
objectFinal configuration, objective value, and minimization diagnostics.
- Variables:
state (State) – Final configuration with evaluated quasistatic forces and torques.
system (System) – System associated with
state, including updated spatial search caches and overflow status.steps (int or jax.Array) – Number of optimizer updates performed. The initial objective or force evaluation is excluded from this count.
energy (jax.Array) – Final potential energy per constituent sphere for the physical objective, or the unnormalized value of a custom
target_fn.reason (jax.Array) – Integer
TerminationReasoncode identifying convergence, step exhaustion, a nonfinite evaluation, or spatial search overflow.info (MinimizeInfo) – Force and torque residuals, finiteness, and convergence status.
converged (jax.Array) – Boolean property equal to
info.converged.
Notes
Supports
jax.jitandjax.vmap. Iteration and indexing expose(state, system, steps, energy).- steps: int | jax.Array#
- energy: jax.Array#
- reason: jax.Array#
- info: MinimizeInfo#
- jaxdem.minimizers.routines.minimize(state: State, system: System, max_steps: int = 10000, force_tol: float = 1e-12, torque_tol: float | None = None, *, advance_history: bool = False) MinimizationResult[source]#
Minimize the configured objective over body positions and orientations.
- Parameters:
state (State) – Initial configuration for a single system. Forces and torques are evaluated at the initial configuration before any optimizer update.
system (System) – System containing the optimizer and force models. The objective is physical potential energy unless
system.target_fnis set.max_steps (int, optional) – Maximum number of optimizer updates. Defaults to 10000.
force_tol (float, optional) – Absolute tolerance on the maximum Euclidean force norm over free bodies. AD objectives use their body-position gradient instead. Defaults to
1e-12.torque_tol (float or None, optional) – Absolute tolerance on the maximum Euclidean torque norm over free bodies. AD objectives use their world angular gradient instead.
Noneuses the numerical value offorce_tol.advance_history (bool, optional) – Whether accepted optimizer updates advance pair history. Defaults to
False, preserving stored history without accumulating slip from optimizer motion. Updates occur once after each accepted step; trial objective evaluations hold history fixed. Stateless force models ignore this option.
- Returns:
Final state, system, update count, energy, and convergence diagnostics. Iteration yields
(state, system, steps, energy). Physical energy is reported per constituent sphere; custom target values are unnormalized.- Return type:
- Raises:
ValueError – If no optimizer is configured, or if the physical objective uses a managed force without a matching energy function.
Notes
Convergence requires both
force_max <= force_tolandtorque_max <= torque_tolwith finite evaluations and complete spatial searches. Fixed bodies are excluded from the residual norms. Custom targets and energies without analytical physical gradients use their translational and world angular AD gradients as residuals. These can differ from mechanical forces for history-dependent laws. Energy magnitude and energy changes do not determine convergence. Step exhaustion, nonfinite evaluations, and spatial search overflow terminate the minimization unsuccessfully.For the physical objective, gradient-only optimizers (
requires_value=False, including FIRE and damped Newtonian) evaluate residual forces initially and after each update, and energy once at exit. Gradient-only optimizers also support force conventions that are not analytical energy gradients. Value-based optimizers use the analytical physical gradient when available and otherwise differentiate the energy directly with stored history fixed. Custom targets use ordinary AD through the State mapping. These optimizers evaluate the objective during optimization. AD through built-in collider energy requires Naive or NeighborList; direct CellList and MultiCellList traversals do not support reverse-mode differentiation.Each rigid body has one set of continuous optimization coordinates. Two-dimensional rotations use an unwrapped angle about the initial orientation; three-dimensional rotations use a raw quaternion normalized only when constructing the trial state. The initial orientation reference and optimizer coordinates are retained, so transformations that remember parameter differences (including L-BFGS) receive consistent coordinates. A zero raw quaternion is invalid and terminates with a nonfinite result. Quaternion sign and radial redundancy do not guarantee convergence for every optimizer; convergence uses world angular residuals independently of the raw quaternion scale. Forces are always evaluated rate-independently: dashpots and other velocity terms are off, so relaxation does not depend on
dt. Pair history is frozen by default; existing spring memory still contributes to force evaluation. Search rebuilds remap surviving pairs and initialize new pairs. Withadvance_history=True, history advances once per accepted coordinate update, using configuration changes from the anchor to the accepted state. Energy and gradients are then evaluated with that updated history fixed. Line-search trials never commit history, and the initial evaluation always holds history fixed.