deepmd.pt.utils.nv_nlist#
Toolkit-Ops (nvalchemiops) neighbor-list strategy.
A NeighborList implementation that builds the extended representation (extended_coord, extended_atype, nlist,
mapping) using the device-resident neighbor-list kernels in nvalchemiops.
Toolkit-Ops returns a dense [total_atoms, max_neighbors] neighbor matrix over the flattened batch. The matrix is converted to the DeePMD extended-atom contract by materializing each unique ghost (frame, src_local, shift) once; the candidate list is then distance-sorted and truncated to sum(sel) so the returned neighbor count is fixed. The search is non-differentiable and runs on detached coordinates, while extended_coord is rebuilt from the input coordinates so force and virial gradients propagate unchanged.
Attributes#
Classes#
Neighbor-list strategy using the |
Functions#
| Redirect the process |
| Whether the |
| Choose the Toolkit-Ops neighbor method for a homogeneous batch. |
| Run third-party kernels with both default and current devices pinned. |
| Increase Toolkit-Ops capacity by 1.25x, rounded up. |
| Distance-sort the candidate neighbor list and keep the nearest |
| Convert Toolkit-Ops matrix output to compact extended inputs. |
Module Contents#
- deepmd.pt.utils.nv_nlist._suppress_native_stderr() collections.abc.Iterator[None][source]#
Redirect the process
stderrfile descriptor toos.devnull.nvalchemiopsinitializes NVIDIA Warp on first import, which probes for a CUDA driver and prints a nativeWarp CUDA error 100line straight to thestderrfd on CPU-only hosts. That line bypasses Python logging, so the only way to mute it is at the descriptor level around the triggering import.
- deepmd.pt.utils.nv_nlist.is_nv_available() bool[source]#
Whether the
nvalchemiopsToolkit-Ops neighbor list is importable.
- deepmd.pt.utils.nv_nlist.choose_nv_nlist_method(nloc: int, *, periodic: bool = True, device: torch.device | None = None) str[source]#
Choose the Toolkit-Ops neighbor method for a homogeneous batch.
- Parameters:
- nloc
Number of local atoms per frame.
- periodic
Whether the batch is periodic.
- device
Target device. CPU uses a lower cell-list threshold than CUDA because the
batch_naivemethod does not parallelize well there.
- Returns:
strToolkit-Ops method name.
- deepmd.pt.utils.nv_nlist._input_device_context(device: torch.device) collections.abc.Iterator[None][source]#
Run third-party kernels with both default and current devices pinned.
- class deepmd.pt.utils.nv_nlist.NvNeighborList[source]#
Bases:
deepmd.dpmodel.utils.neighbor_list.NeighborListNeighbor-list strategy using the
nvalchemiopskernels.Implements the
NeighborListinterface on torch tensors; the search runs on the device of the input coordinates. Periodic inputs materialize shifted ghost atoms; non-periodic inputs keep only local atoms.- build(coord: Any, atype: Any, box: Any, rcut: float, sel: list[int], return_mode: str = 'extended') tuple[Any, Any, Any, Any] | deepmd.dpmodel.utils.neighbor_list.EdgeNeighborList[source]#
Build the extended system and neighbor list.
See
deepmd.dpmodel.utils.neighbor_list.NeighborList.build(). The returnednlistis distance-sorted and truncated tosum(sel).
- deepmd.pt.utils.nv_nlist._grow_search_capacity(capacity: int) int[source]#
Increase Toolkit-Ops capacity by 1.25x, rounded up.
- deepmd.pt.utils.nv_nlist._truncate_to_sel(extended_coord: torch.Tensor, nlist: torch.Tensor, nsel: int, rcut: float) torch.Tensor[source]#
Distance-sort the candidate neighbor list and keep the nearest
nselwithinrcut, padding with-1when fewer neighbors exist.The Toolkit-Ops search capacity may exceed
sum(sel)on dense systems; this fixes the returned neighbor count atnsel.The output is the integer
nlist;extended_coordis only read to rank candidates and is returned unchanged by the caller. The routine is therefore non-differentiable and runs underno_gradso it never participates in the autograd graph (forward, backward, or the second-order pass used to train forces), which also avoids retaining the distance temporaries for backward.
- deepmd.pt.utils.nv_nlist._matrix_to_extended_inputs(*, coord: torch.Tensor, atype: torch.Tensor, cell: torch.Tensor | None, nloc: int, neighbor_matrix: torch.Tensor, num_neighbors: torch.Tensor, shifts: torch.Tensor) tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor][source]#
Convert Toolkit-Ops matrix output to compact extended inputs.
Toolkit-Ops returns neighbors as a dense matrix over flattened atoms:
neighbor_matrix[dst_global, slot] = src_globalandshifts[dst_global, slot] = (sx, sy, sz). Heredst_globalandsrc_globalare indices in the concatenatednf * nlocinput.DeePMD lower paths use a different contract:
nliststores indices intoextended_coord. Local atoms occupy[0, nloc)in each frame, while shifted PBC images must be appended as ghost atoms. This conversion builds the minimal ghost set by materializing each unique(frame, src_local, shift)once, then redirects all shifted nlist entries to the corresponding compact ghost index.