A guide for using nvalchemi dynamics API for GPU-accelerated molecular simulations.
Install
mkdir -p .claude/skills/nvalchemi-dynamics-api && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/12215" && unzip -o skill.zip -d .claude/skills/nvalchemi-dynamics-api && rm skill.zipInstalls to .claude/skills/nvalchemi-dynamics-api
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
How to configure and run dynamics simulations, compose multi-stage pipelines (FusedStage, DistributedPipeline), use inflight batching, and manage data sinks.Key capabilities
- →Configure dynamics simulations with parameters like `n_steps` and `dt`
- →Compose multi-stage pipelines using `FusedStage` for single GPU scaling
- →Chain dynamics stages across multiple ranks with `DistributedPipeline` for multi-rank scaling
- →Implement convergence detection using `ConvergenceHook` with various criteria
- →Manage data sinks for simulation output
How it works
The skill provides an API to configure dynamics classes, compose multi-stage pipelines for scaling simulations, and manage data sinks for output.
Inputs & outputs
When to use nvalchemi-dynamics-api
- →Run molecular dynamics simulations
- →Configure pipeline stages
- →Manage simulation data
About this skill
nvalchemi Dynamics API
Overview
The dynamics API provides tools to discover available dynamics classes, configure them, and scale simulations up (single GPU) and out (multi-rank pipelines).
from nvalchemi.dynamics import (
BaseDynamics,
DemoDynamics,
FusedStage,
DistributedPipeline,
ConvergenceHook,
Hook,
DynamicsStage,
SizeAwareSampler,
DataSink, GPUBuffer, HostMemory, ZarrData,
hooks,
)
Available dynamics classes
| Class | Description |
|---|---|
BaseDynamics | Abstract base — subclass to create integrators |
DemoDynamics | Velocity Verlet reference implementation (testing only) |
To find all dynamics classes in a codebase, search for subclasses of BaseDynamics.
Configuring a dynamics run
Basic setup
from nvalchemi.dynamics import DemoDynamics, ConvergenceHook
from nvalchemi.models.demo import DemoModelWrapper
from nvalchemi.data import AtomicData, Batch
import torch
model = DemoModelWrapper()
dynamics = DemoDynamics(
model=model,
n_steps=1000, # total steps for run()
dt=0.5, # timestep (fs)
)
# Create batch with required state
data = AtomicData(
atomic_numbers=torch.tensor([6, 8, 1], dtype=torch.long),
positions=torch.randn(3, 3),
)
batch = Batch.from_data_list([data])
batch.forces = torch.zeros(3, 3)
batch.energy = torch.zeros(1, 1)
result = dynamics.run(batch)
With convergence detection
dynamics = DemoDynamics(
model=model,
n_steps=10000,
dt=0.5,
convergence_hook=ConvergenceHook(
criteria=[
{"key": "fmax", "threshold": 0.05, "reduce_op": "max"},
{"key": "energy_change", "threshold": 1e-6},
],
frequency=1,
),
)
Shorthand for force-based convergence:
dynamics = DemoDynamics(
model=model,
n_steps=10000,
dt=0.5,
convergence_hook=ConvergenceHook.from_fmax(threshold=0.05),
)
With hooks
from nvalchemi.dynamics.hooks import MaxForceClampHook, LoggingHook
dynamics = DemoDynamics(
model=model,
n_steps=1000,
dt=0.5,
hooks=[
MaxForceClampHook(max_force=10.0),
LoggingHook(backend="csv", log_path="md_log.csv", frequency=100),
],
)
Scaling up: FusedStage (single GPU, multiple stages)
FusedStage composes multiple dynamics stages on one GPU with a single shared
model forward pass per step. Samples migrate between stages via convergence.
Composition with + operator
# Stage 0: geometry optimization
opt = DemoDynamics(
model=model, n_steps=100, dt=1.0,
convergence_hook=ConvergenceHook.from_fmax(0.05),
)
# Stage 1: production MD
md = DemoDynamics(model=model, n_steps=500, dt=0.5)
# Compose — auto-registers convergence hook to migrate status 0 → 1
fused = opt + md
result = fused.run(batch) # runs until all samples reach exit_status
Constructor (explicit)
fused = FusedStage(
sub_stages=[(0, opt), (1, md)],
entry_status=0, # initial sample status
exit_status=2, # auto-set to len(sub_stages) if -1
compile_step=False, # enable torch.compile
compile_kwargs=None, # kwargs for torch.compile
)
With torch.compile
fused = (opt + md)
fused.compile(fullgraph=True, mode="reduce-overhead")
with fused: # lazy compilation on context entry
result = fused.run(batch)
How it works
- Each sample has a
statusfield (integer) - Each sub-stage processes only samples matching its status code
- When a sub-stage's
ConvergenceHookfires, converged samples' status increments - Samples at
exit_statusare graduated (no longer updated) run()loops until all samples reachexit_statusor sampler is exhausted
Chaining more stages
fused_3 = opt + md + analysis # 3 sub-stages: status 0, 1, 2
fused_3 = fused + extra_stage # append to existing FusedStage
Scaling out: DistributedPipeline (multi-rank)
DistributedPipeline chains dynamics stages across multiple ranks using
torch.distributed. Each rank runs one stage; converged samples are sent
to the next rank. This is pipeline parallelism for dynamics, distinct from
data-parallel multi-GPU training (DDP).
Composition with | operator
opt_stage = DemoDynamics(model=model, n_steps=100, dt=1.0) # rank 0
md_stage = DemoDynamics(model=model, n_steps=500, dt=0.5) # rank 1
pipeline = opt_stage | md_stage
with pipeline: # initializes torch.distributed + setup
pipeline.run()
Constructor (explicit)
pipeline = DistributedPipeline(
stages={0: opt_stage, 1: md_stage},
synchronized=False, # True for debugging (adds barriers)
)
Communication modes
Control how inter-rank buffers synchronize:
stage = DemoDynamics(
model=model, n_steps=100, dt=0.5,
comm_mode="async_recv", # default: deferred blocking
# comm_mode="sync", # immediate blocking (debugging)
# comm_mode="fully_async", # maximum overlap
)
The default comm_mode is "async_recv". The three modes differ in when
blocking occurs:
"sync":irecvcompletes inline in_prestep_sync_buffers; simplest and good for debugging."async_recv":irecvis posted in_prestep_sync_buffers, butwait()is deferred to_complete_pending_recvfor communication overlap."fully_async": send and receive are both deferred for maximum overlap. Pending sends from the prior step are drained at the start of the next_prestep_sync_buffers.
Pre-allocated buffers
For high-throughput pipelines, pre-allocate send/recv buffers:
from nvalchemi.dynamics.base import BufferConfig
buffer_cfg = BufferConfig(
num_systems=100, # max graphs
num_nodes=5000, # total node capacity
num_edges=20000, # total edge capacity
)
stage = DemoDynamics(
model=model, n_steps=100, dt=0.5,
buffer_config=buffer_cfg,
)
Buffers are lazily initialized on the first step using the first concrete batch as a template for attribute keys, dtypes, and shapes. This means the first step has slightly more overhead.
Adjacent stages must use identical BufferConfig values. This is
validated in DistributedPipeline.setup().
Buffer semantics and communication
Three buffer layers
The dynamics framework manages data flow through three layers:
| Layer | Location | Purpose |
|---|---|---|
| Active batch | _CommunicationMixin.active_batch | Working set being integrated |
| Communication buffers | send_buffer / recv_buffer | Pre-allocated Batch.empty() for zero-copy inter-rank transfer |
| Overflow sinks | DataSink list (priority-ordered) | Staging when active batch is full |
Communication protocol (DistributedPipeline)
Each pipeline step follows a four-phase protocol:
_prestep_sync_buffers()zeros the send buffer and postsirecvfrom the prior rank._complete_pending_recv()waits on deferred receive, routes into the active batch, and drains overflow sinks.step()runs dynamics integration._poststep_sync_buffers(converged_indices)extracts converged samples into the send buffer and sends them to the next rank.
Deadlock prevention: when no samples converge, an empty send buffer
is still sent so the downstream irecv completes.
Back-pressure
When send_buffer has limited capacity (via BufferConfig):
- Only
min(converged_count, remaining_capacity)samples are extracted - Excess converged samples remain in the active batch as no-ops. Their positions and velocities are saved before the integrator and restored after it runs.
- Without
BufferConfig, all converged samples are sent without constraints (backward compatible).
Buffer lifecycle: put/defrag/zero
# Pre-allocated buffer created via Batch.empty()
buffer = Batch.empty(num_systems=100, num_nodes=5000, num_edges=20000, template=batch)
# Copy selected graphs into buffer (Warp GPU kernels, float32 only)
mask = converged_mask # bool tensor, True = copy this graph
buffer.put(src_batch, mask)
# Remove copied graphs from source in-place
src_batch.defrag()
# Reset buffer for reuse (preserves allocated memory)
buffer.zero()
Important: Batch.put() uses Warp GPU kernels that only handle
float32 attributes. Adjacent pipeline stages must have identical
BufferConfig values.
Data routing methods
| Method | Purpose |
|---|---|
_recv_to_batch(incoming) | Route received data through recv buffer into active batch |
_buffer_to_batch(incoming) | Append to active batch, overflow to sinks if full |
_batch_to_buffer(mask) | Copy graduated samples into send buffer, defrag active batch |
_overflow_to_sinks(batch) | Write to first non-full sink in priority order |
_drain_sinks_to_batch() | Pull from sinks back into active batch when room available |
Inflight batching with SizeAwareSampler
For streaming workflows, SizeAwareSampler manages dataset access with
bin-packing for size-matched batching. As samples converge and leave
the batch, new samples are pulled from the dataset.
from nvalchemi.dynamics import SizeAwareSampler
sampler = SizeAwareSampler(
dataset=dataset, # must have __len__, __getitem__, get_metadata
max_atoms=1000, # max total atoms per batch (None = auto from GPU)
max_edges=5000, # max total edges per batch
max_batch_size=32, # max graphs per batch
bin_width=10, # group samples by atom count bins
shuffle=False,
max_gpu_memory_fraction=0.8, # for auto max_atoms estimation
)
# Build initial batch via greedy bin-packing
batch = sampler.build_initial_batch()
# Request a replacement sample that fits constraints
replacement = sampler.request_replacement(num_atoms=50,
---
*Content truncated.*
When not to use it
- →When not performing dynamics simulations, structure relaxation, or geometry optimization
- →When not orchestrating many structures through a batched GPU pipeline
Limitations
- →The skill is for dynamics simulations, structure relaxation, geometry optimization, or adsorption scans.
- →It requires a model and initial atomic data for configuration.
- →Scaling with `DistributedPipeline` requires `torch.distributed` setup.
How it compares
This skill offers a structured API for configuring and scaling complex dynamics simulations, enabling advanced features like fused stages and distributed pipelines, which is more efficient than manual orchestration.
Compared to similar skills
nvalchemi-dynamics-api side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| nvalchemi-dynamics-api (this skill) | 0 | 1mo | No flags | Advanced |
| qiskit | 4 | 7mo | Review | Advanced |
| pennylane | 1 | 7mo | Review | Advanced |
| model-registry-maintainer | 0 | 8mo | Caution | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by NVIDIA
View all by NVIDIA →You might also like
qiskit
davila7
Comprehensive quantum computing toolkit for building, optimizing, and executing quantum circuits. Use when working with quantum algorithms, simulations, or quantum hardware including (1) Building quantum circuits with gates and measurements, (2) Running quantum algorithms (VQE, QAOA, Grover), (3) Transpiling/optimizing circuits for hardware, (4) Executing on IBM Quantum or other providers, (5) Quantum chemistry and materials science, (6) Quantum machine learning, (7) Visualizing circuits and results, or (8) Any quantum computing development task.
pennylane
davila7
Cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Enables building and training quantum circuits with automatic differentiation, seamless integration with PyTorch/JAX/TensorFlow, and device-independent execution across simulators and quantum hardware (IBM, Amazon Braket, Google, Rigetti, IonQ, etc.). Use when working with quantum circuits, variational quantum algorithms (VQE, QAOA), quantum neural networks, hybrid quantum-classical models, molecular simulations, quantum chemistry calculations, or any quantum computing tasks requiring gradient-based optimization, hardware-agnostic programming, or quantum machine learning workflows.
model-registry-maintainer
massgen
Guide for maintaining the MassGen model and backend registry. This skill should be used when adding new models, updating model information (release dates, pricing, context windows), or ensuring the registry stays current with provider releases. Covers both the capabilities registry and the pricing/token manager.
hf-mcp
huggingface
Use Hugging Face Hub via MCP server tools. Search models, datasets, Spaces, papers. Get repo details, fetch documentation, run compute jobs, and use Gradio Spaces as AI tools. Available when connected to the HF MCP server.
long-context
davila7
Extend context windows of transformer models using RoPE, YaRN, ALiBi, and position interpolation techniques. Use when processing long documents (32k-128k+ tokens), extending pre-trained models beyond original context limits, or implementing efficient positional encodings. Covers rotary embeddings, attention biases, interpolation methods, and extrapolation strategies for LLMs.
quantum-espresso
Hello-QM
>