Skip to content

Commit

Permalink
feat: make dp neighbor-stat --type-map optional (deepmodeling#4049)
Browse files Browse the repository at this point in the history
In most cases, we can directly read type map from data.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- The `neighbor_stat` function now accepts an optional `type_map`,
enhancing flexibility in function calls.
- The `--type-map` argument in the main parser has been changed to
optional, defaulting to a derived type map if not provided.

- **Improvements**
- Added logging to indicate when the `type_map` is not supplied,
enhancing user awareness and debugging capabilities.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
  • Loading branch information
njzjz authored and mtaillefumier committed Sep 18, 2024
1 parent 677959f commit 9028f9c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion deepmd/entrypoints/neighbor_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
from typing import (
List,
Optional,
)

from deepmd.backend.backend import (
Expand All @@ -21,7 +22,7 @@ def neighbor_stat(
*,
system: str,
rcut: float,
type_map: List[str],
type_map: Optional[List[str]],
mixed_type: bool = False,
backend: str = "tensorflow",
**kwargs,
Expand Down Expand Up @@ -88,6 +89,8 @@ def neighbor_stat(
rcut=rcut,
type_map=type_map,
)
if type_map is None:
log.info(f"type_map: {data.get_type_map()}")
data.get_batch()
nei = NeighborStat(data.get_ntypes(), rcut, mixed_type=mixed_type)
min_nbor_dist, max_nbor_size = nei.get_stat(data)
Expand Down
4 changes: 2 additions & 2 deletions deepmd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,8 @@ def main_parser() -> argparse.ArgumentParser:
"--type-map",
type=str,
nargs="+",
required=True,
help="type map",
required=False,
help="Type map. If not provided, the type map of data will be used.",
)
parser_neighbor_stat.add_argument(
"--mixed-type",
Expand Down

0 comments on commit 9028f9c

Please sign in to comment.