nvalchemi.dynamics.DemoDynamics#
- class nvalchemi.dynamics.DemoDynamics(model, n_steps, dt=1.0, hooks=None, convergence_hook=None, **kwargs)[source]#
Velocity Verlet integrator for molecular dynamics simulations.
Implements the standard Velocity Verlet algorithm, a symplectic, time-reversible integration scheme commonly used in molecular dynamics. The algorithm splits the integration into two half-steps:
pre_update: Update positions using current velocities and accelerations x(t+dt) = x(t) + v(t)*dt + 0.5*a(t)*dt^2post_update: Update velocities using averaged accelerations v(t+dt) = v(t) + 0.5*(a(t) + a(t+dt))*dt
On the first step when previous accelerations are unavailable, falls back to Euler integration for velocities: v(t+dt) = v(t) + a(t+dt)*dt.
Inter-rank communication capabilities for use in pipeline workflows are inherited from
BaseDynamics. Communication attributes includeprior_rank,next_rank,sinks,active_batch,max_batch_size, anddone.This class is intended entirely for testing and debugging, demonstrating how to implement an integrator by overriding
pre_updateandpost_update. Do NOT use this class for production.- Parameters:
model (BaseModelMixin)
n_steps (int)
dt (float)
hooks (list[Hook] | None)
convergence_hook (ConvergenceHook | dict | None)
kwargs (Any)
- __needs_keys__#
Set of output keys required from the model. Set to
{"forces"}.- Type:
set[str]
- __provides_keys__#
Set of keys this dynamics produces beyond model outputs. Set to
{"velocities", "positions"}.- Type:
set[str]
- model#
The neural network potential model.
- Type:
- dt#
The integration timestep.
- Type:
float
- step_count#
The current step number.
- Type:
int
- hooks#
Registered hooks organized by stage.
- Type:
dict[HookStageEnum, list[Hook]]
- _prev_accelerations#
Cached accelerations from the previous step for the velocity half-step.
Noneon the first step.- Type:
torch.Tensor | None
- prior_rank#
Rank of the previous pipeline stage (inherited from
BaseDynamics).- Type:
int | None
- next_rank#
Rank of the next pipeline stage (inherited from
BaseDynamics).- Type:
int | None
Examples
>>> model = DemoModelWrapper() >>> dynamics = DemoDynamics(model, dt=0.5, n_steps=100) >>> dynamics.run(batch) >>> # DistributedPipeline composition: >>> pipeline = dynamics | other_dynamics
- __init__(model, n_steps, dt=1.0, hooks=None, convergence_hook=None, **kwargs)[source]#
Initialize the Velocity Verlet integrator.
- Parameters:
model (BaseModelMixin) – The neural network potential model.
n_steps (int) – Total number of simulation steps for
run().dt (float, optional) – The integration timestep in femtoseconds. Default is 1.0.
hooks (list[Hook] | None, optional) – Initial list of hooks to register. Each hook will be organized by its
stageattribute.convergence_hook (ConvergenceHook | dict | None, optional) – Convergence hook configuration. Accepts a
ConvergenceHookinstance, a dict (unpacked asConvergenceHook(**dict)), orNonefor no convergence checking. Default isNone.**kwargs (Any) – Additional keyword arguments forwarded to the next class in the MRO (for cooperative multiple inheritance).
- Return type:
None
Methods
__init__(model, n_steps[, dt, hooks, ...])Initialize the Velocity Verlet integrator.
compute(batch)Perform the model forward pass to compute forces and energies.
masked_update(batch, mask)Apply pre_update and post_update only to selected samples in the batch.
post_update(batch)Perform the velocity update (second half of Velocity Verlet).
pre_update(batch)Perform the position update (first half of Velocity Verlet).
refill_check(batch, exit_status)Replace graduated samples via index-select and append.
register_bookkeeping_key(key, init_fn)Register a graph-level bookkeeping field to survive refill_check.
register_hook(hook)Register a hook to be executed at its designated stage(s).
run(batch[, n_steps])Run the dynamics simulation for a specified number of steps.
step(batch)Execute a single dynamics step with the full hook-wrapped sequence.
Attributes
active_batch_has_roomReturn whether the active batch can accept more samples.
active_batch_sizeReturn the number of samples currently in the active batch.
deviceCompute the torch device for this rank.
global_rankGet the global rank for this process.
has_neighborConvenient property to see if rank is isolated
inflight_modeReturn whether inflight batching is enabled.
is_final_stageReturn whether this is the last stage in the pipeline.
is_first_stageReturn whether this is the first stage in the pipeline.
local_rankGet the node-local rank for this process.
model_is_conservativeReturns whether or not the model uses conservative forces
room_in_active_batchReturn the number of additional samples the active batch can hold.
streamReturn the active CUDA stream, if any.