Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions deepmd/dpmodel/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
DistributedSameNlocBatchSampler,
LmdbDataReader,
LmdbTestData,
LmdbTestDataNlocView,
SameNlocBatchSampler,
is_lmdb,
make_neighbor_stat_data,
Expand Down Expand Up @@ -58,6 +59,7 @@
"FittingNet",
"LmdbDataReader",
"LmdbTestData",
"LmdbTestDataNlocView",
"NativeLayer",
"NativeNet",
"NetworkCollection",
Expand Down
41 changes: 41 additions & 0 deletions deepmd/dpmodel/utils/lmdb_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,25 @@ def add(
"dtype": dtype,
}

def add_data_requirement(self, data_requirement: list[DataRequirementItem]) -> None:
"""Register expected keys from ``DataRequirementItem`` objects.

Mirrors :meth:`LmdbDataReader.add_data_requirement` so the same
requirement list can be forwarded to both the training reader and
the full-validation test data.
"""
for item in data_requirement:
self.add(
item["key"],
ndof=item["ndof"],
atomic=item["atomic"],
must=item["must"],
high_prec=item["high_prec"],
repeat=item["repeat"],
default=item["default"],
dtype=item["dtype"],
)

def _resolve_dtype(self, key: str) -> np.dtype:
"""Resolve target dtype for a key using registered requirements."""
if key in self._requirements:
Expand Down Expand Up @@ -1404,6 +1423,28 @@ def _stack_frames(
return result


class LmdbTestDataNlocView:
"""Thin wrapper exposing a fixed-``nloc`` view of :class:`LmdbTestData`.

The underlying :class:`LmdbTestData` groups frames by atom count. This
view fixes one ``nloc`` group, so ``get_test()`` returns only the frames
with that atom count and all other attributes (``pbc``, ``mixed_type``,
…) are forwarded to the underlying object. It lets downstream consumers
that expect a ``DeepmdData``-style system (one fixed natoms per
``get_test()``) work on mixed-nloc LMDB datasets without changes.
"""

def __init__(self, lmdb_test_data: "LmdbTestData", nloc: int) -> None:
self._inner = lmdb_test_data
self._nloc = nloc

def __getattr__(self, name: str) -> Any:
return getattr(self._inner, name)

def get_test(self) -> dict[str, Any]:
return self._inner.get_test(nloc=self._nloc)


def merge_lmdb(
src_paths: list[str],
dst_path: str,
Expand Down
Loading