Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion doc/inference/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ model_devi = calc_model_devi(coord, cell, atype, graphs)
Note that if the model inference or model deviation is performed cyclically, one should avoid calling the same model multiple times.
Otherwise, TensorFlow or PyTorch will never release the memory, and this may lead to an out-of-memory (OOM) error.

## External neighbor list algorithm {{ tensorflow_icon }}
## Choosing a neighbor search

### External neighbor list {{ tensorflow_icon }}

> [!NOTE]
> **Supported backends**: TensorFlow {{ tensorflow_icon }}
Expand All @@ -77,3 +79,38 @@ dp = DeepPot("graph.pb", neighbor_list=neighbor_list)
```

The `update` and `build` methods will be called by {class}`DeepPot <deepmd.infer.DeepPot>`, and `first_neigh`, `pair_second`, and `offset_vec` properties will be used.

### PyTorch Exportable neighbor lists {{ pytorch_icon }}

For a frozen `.pt2` or `.pte` model that takes a neighbor list, both
`DeepPot` and the ASE calculator accept `nlist_backend`. The default,
`"auto"`, selects an available search for the input batch. For a single
frame it tries Vesin, then NV, then the native search. For multiple frames it
tries NV, then Vesin, then the native search. Virtual-atom spin models with
the neighbor-list lower accept `"auto"` and `"native"` and use the native
search for both. Native-spin edge-vector models can also use Vesin or NV.

Without an optional search library,
the native extended-coordinate search has quadratic cost in the number of
atoms (including periodic images).

| `nlist_backend` | Neighbor search |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `"auto"` | Select by availability and frame count. |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please qualify this table for virtual-atom spin artifacts with the nlist lower: _setup_neighbor_backend rejects explicit vesin and nv even when the libraries are installed. auto and native use the native builder there; this is distinct from native-spin edge-vector artifacts. It would also help to give the full auto order where eligible: Vesin → NV → native for one frame, and NV → Vesin → native for a batch.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in cf79e64.

Updated the backend table notes to spell out the single-frame order (Vesin, NV, native), the batched order (NV, Vesin, native), and the virtual-atom spin restriction. I checked the selector on AISI: for the virtual-atom nlist path, auto and native used the native builder, while explicit vesin and nv each raised the expected error.

| `"native"` | Use the native extended-coordinate builder for neighbor-list inputs. |
| `"vesin"` | Use Vesin's cell-list search, which scales as $O(N)$ at fixed density and cutoff. Install `vesin[torch]>=0.6`. Explicitly requesting Vesin without the Torch bindings raises `ImportError`. |
| `"nv"` | Use the CPU or CUDA search provided by `nvalchemi-toolkit-ops`. |

```py
from deepmd.calculator import DP
from deepmd.infer import DeepPot

dp = DeepPot("model.pt2", nlist_backend="vesin")
atoms.calc = DP(model="model.pt2", nlist_backend="vesin")
```

Here `atoms` is an ASE `Atoms` object. For graph-form models, including
compressed canonical DPA4C, choose the builder with
`neighbor_graph_method` instead. Passing a non-default `nlist_backend`
to these models raises `ValueError`. Edge-vector models accept either
option to request Vesin or NV. Set only one of them.