:orphan: :orphan: Examples ======== End-to-end examples demonstrating ALCHEMI Toolkit functionality. .. raw:: html
.. thumbnail-parent-div-open .. thumbnail-parent-div-close .. raw:: html
Basic Examples ============== These examples introduce the core nvalchemi-toolkit workflow to users familiar with tools like ASE. Each script focuses on one feature set and runs end-to-end on a single GPU in under 60 seconds. **01 — Data Structures**: AtomicData and Batch API. **02 — Geometry Optimization**: FIRE optimizer with NeighborListHook and ConvergenceHook. **03 — ASE Integration**: Loading ASE structures, FreezeAtomsHook on a surface system. **04 — NVE MD**: Microcanonical dynamics, WrapPeriodicHook, EnergyDriftMonitorHook. **05 — NVT MD**: Langevin thermostat, thermalization, LoggingHook to CSV. .. raw:: html
.. thumbnail-parent-div-open .. raw:: html
.. only:: html .. image:: /examples/basic/images/thumb/sphx_glr_01_data_structures_thumb.png :alt: :doc:`/examples/basic/01_data_structures` .. raw:: html
AtomicData and Batch: Graph-structured molecular data
.. raw:: html
.. only:: html .. image:: /examples/basic/images/thumb/sphx_glr_02_geometry_optimization_thumb.png :alt: :doc:`/examples/basic/02_geometry_optimization` .. raw:: html
FIRE Geometry Optimization with Lennard-Jones Argon
.. raw:: html
.. only:: html .. image:: /examples/basic/images/thumb/sphx_glr_03_ase_integration_thumb.png :alt: :doc:`/examples/basic/03_ase_integration` .. raw:: html
ASE Integration: Real Molecular Structures in nvalchemi-toolkit
.. raw:: html
.. only:: html .. image:: /examples/basic/images/thumb/sphx_glr_04_nve_energy_conservation_thumb.png :alt: :doc:`/examples/basic/04_nve_energy_conservation` .. raw:: html
Microcanonical (NVE) Molecular Dynamics
.. raw:: html
.. only:: html .. image:: /examples/basic/images/thumb/sphx_glr_05_nvt_langevin_thumb.png :alt: :doc:`/examples/basic/05_nvt_langevin` .. raw:: html
Canonical (NVT) Molecular Dynamics with Langevin Thermostat
.. thumbnail-parent-div-close .. raw:: html
Intermediate Examples ===================== These examples assume familiarity with the basic tier and introduce the storage layer, performance monitoring, and more complex pipeline patterns. **01 — Multi-Stage Pipeline**: FusedStage composition, LoggingHook CSV output, step-budget migration, fused hooks for global status monitoring. **02 — Trajectory I/O**: Writing trajectories to Zarr, reading back with DataLoader, round-trip validation. **03 — NPT MD**: Pressure-controlled dynamics with the MTK barostat, LJ stress computation, cell fluctuation monitoring. **04 — Inflight Batching**: SizeAwareSampler, Mode 2 FusedStage run (batch=None), system_id tracking, ConvergedSnapshotHook collecting results. **05 — Safety and Monitoring**: NaNDetectorHook, MaxForceClampHook, EnergyDriftMonitorHook, ProfilerHook — defensive MD patterns. .. raw:: html
.. thumbnail-parent-div-open .. raw:: html
.. only:: html .. image:: /examples/intermediate/images/thumb/sphx_glr_01_multistage_pipeline_thumb.png :alt: :doc:`/examples/intermediate/01_multistage_pipeline` .. raw:: html
Multi-Stage Dynamics Pipelines with FusedStage
.. raw:: html
.. only:: html .. image:: /examples/intermediate/images/thumb/sphx_glr_02_trajectory_zarr_io_thumb.png :alt: :doc:`/examples/intermediate/02_trajectory_zarr_io` .. raw:: html
Writing and Replaying Trajectories with Zarr
.. raw:: html
.. only:: html .. image:: /examples/intermediate/images/thumb/sphx_glr_03_npt_variable_cell_thumb.png :alt: :doc:`/examples/intermediate/03_npt_variable_cell` .. raw:: html
Pressure-Controlled (NPT) Molecular Dynamics
.. raw:: html
.. only:: html .. image:: /examples/intermediate/images/thumb/sphx_glr_04_inflight_batching_thumb.png :alt: :doc:`/examples/intermediate/04_inflight_batching` .. raw:: html
Processing Large Datasets with Inflight Batching
.. raw:: html
.. only:: html .. image:: /examples/intermediate/images/thumb/sphx_glr_05_safety_and_monitoring_thumb.png :alt: :doc:`/examples/intermediate/05_safety_and_monitoring` .. raw:: html
Defensive MD: Safety Hooks and Performance Monitoring
.. thumbnail-parent-div-close .. raw:: html
Advanced Examples ================= These examples are for users who want to extend the nvalchemi-toolkit framework. They require understanding of the intermediate tier. **01 — Biased Potential**: BiasedPotentialHook for harmonic COM restraints and umbrella sampling patterns. **02 — Custom Hook**: Implementing the Hook protocol with a full radial distribution function accumulator. **03 — Custom Convergence**: ConvergenceHook with multiple criteria and custom_op for arbitrary convergence logic. **04 — MACE NVT**: Using a real MACE MLIP for NVT dynamics; automatic neighbor list wiring via ModelCard; LJ fallback for CI. **05 — Custom Integrator**: Subclassing BaseDynamics to implement a velocity-rescaling thermostat; the pre_update/post_update contract; _init_state for stateful integrators. .. raw:: html
.. thumbnail-parent-div-open .. raw:: html
.. only:: html .. image:: /examples/advanced/images/thumb/sphx_glr_01_biased_potential_thumb.png :alt: :doc:`/examples/advanced/01_biased_potential` .. raw:: html
Biased Sampling with BiasedPotentialHook
.. raw:: html
.. only:: html .. image:: /examples/advanced/images/thumb/sphx_glr_02_custom_hook_thumb.png :alt: :doc:`/examples/advanced/02_custom_hook` .. raw:: html
Writing a Custom Hook: Radial Distribution Function
.. raw:: html
.. only:: html .. image:: /examples/advanced/images/thumb/sphx_glr_03_custom_convergence_thumb.png :alt: :doc:`/examples/advanced/03_custom_convergence` .. raw:: html
Multi-Criteria Convergence with Custom Operators
.. raw:: html
.. only:: html .. image:: /examples/advanced/images/thumb/sphx_glr_04_mace_nvt_thumb.png :alt: :doc:`/examples/advanced/04_mace_nvt` .. raw:: html
NVT MD with MACE (with LJ Fallback)
.. raw:: html
.. only:: html .. image:: /examples/advanced/images/thumb/sphx_glr_05_custom_integrator_thumb.png :alt: :doc:`/examples/advanced/05_custom_integrator` .. raw:: html
Building a Custom Integrator by Subclassing BaseDynamics
.. raw:: html
.. only:: html .. image:: /examples/advanced/images/thumb/sphx_glr_06_ewald_electrostatics_thumb.png :alt: :doc:`/examples/advanced/06_ewald_electrostatics` .. raw:: html
Long-Range Electrostatics with Ewald Summation
.. raw:: html
.. only:: html .. image:: /examples/advanced/images/thumb/sphx_glr_07_composable_model_composition_thumb.png :alt: :doc:`/examples/advanced/07_composable_model_composition` .. raw:: html
Composable Model Composition (LJ + Ewald)
.. thumbnail-parent-div-close .. raw:: html
Distributed Pipeline Examples ============================== These examples demonstrate multi-GPU distributed simulation pipelines using :class:`~nvalchemi.dynamics.DistributedPipeline`. They require multiple GPUs and must be launched with ``torchrun``. .. warning:: These examples are **not executed** during the Sphinx documentation build. To run them, use ``torchrun`` as shown in each example. Architecture Overview --------------------- A :class:`~nvalchemi.dynamics.DistributedPipeline` maps GPU ranks to dynamics stages. Systems flow between stages via fixed-size NCCL communication buffers: .. graphviz:: digraph distributed_pipeline { rankdir=LR; node [shape=box, style="rounded,filled", fillcolor="#e8f4fd", fontname="Helvetica", fontsize=11]; edge [fontname="Helvetica", fontsize=10]; rank0 [label="Rank 0: FIRE\n(upstream)"]; rank1 [label="Rank 1: Langevin\n(downstream + sink)"]; rank0 -> rank1 [label="NCCL"]; } Key concepts: - **Upstream ranks** (``prior_rank=None``): hold a :class:`~nvalchemi.dynamics.SizeAwareSampler` and push graduated (converged) systems to the next rank. - **Downstream ranks** (``next_rank=None``): receive systems from the prior rank and write results to a sink. - **BufferConfig**: must be set to a fixed size on all ranks; NCCL requires identical message sizes every communication step. - ``torchrun --nproc_per_node=N`` launches one process per GPU; each process runs only the stage assigned to its rank. Running the Examples -------------------- **01 — Parallel FIRE → Langevin** (4 GPUs required): .. code-block:: bash torchrun --nproc_per_node=4 examples/distributed/01_distributed_pipeline.py # CPU/debug mode (set backend="gloo" in the script first): torchrun --nproc_per_node=4 --master_port=29500 examples/distributed/01_distributed_pipeline.py **02 — Monitoring with LoggingHook, ProfilerHook, and ZarrData** (4 GPUs required): .. code-block:: bash torchrun --nproc_per_node=4 examples/distributed/02_distributed_monitoring.py After running example 02, per-rank CSV logs and Zarr trajectory stores are written to the working directory. Rank 0 also prints a collated summary. Example Descriptions -------------------- **01 — Distributed Pipeline** Two independent FIRE → NVTLangevin sub-pipelines running on 4 GPUs. Demonstrates DistributedPipeline wiring, BufferConfig, and HostMemory sinks. **02 — Distributed Monitoring** Same topology as example 01, augmented with per-rank LoggingHook and ProfilerHook for observability, and ZarrData sinks for persistent trajectory storage. Shows post-run log collation on rank 0. .. raw:: html
.. thumbnail-parent-div-open .. raw:: html
.. only:: html .. image:: /examples/distributed/images/thumb/sphx_glr_01_distributed_pipeline_thumb.png :alt: :doc:`/examples/distributed/01_distributed_pipeline` .. raw:: html
Distributed Multi-GPU Pipeline: Parallel FIRE → Langevin
.. raw:: html
.. only:: html .. image:: /examples/distributed/images/thumb/sphx_glr_02_distributed_monitoring_thumb.png :alt: :doc:`/examples/distributed/02_distributed_monitoring` .. raw:: html
Monitoring a Distributed Pipeline: Per-Rank Logging and Profiling
.. thumbnail-parent-div-close .. raw:: html
.. toctree:: :hidden: :includehidden: /examples/basic/index.rst /examples/intermediate/index.rst /examples/advanced/index.rst /examples/distributed/index.rst .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-gallery .. container:: sphx-glr-download sphx-glr-download-python :download:`Download all examples in Python source code: examples_python.zip ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download all examples in Jupyter notebooks: examples_jupyter.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_