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
4 changes: 2 additions & 2 deletions .github/workflows/test_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
fail-fast: false
matrix:
group: [1, 2, 3, 4, 5, 6]
python: ["3.9", "3.12"]
python: ["3.10", "3.12"]

steps:
- uses: actions/checkout@v6
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python: ["3.9", "3.12"]
python: ["3.10", "3.12"]
needs: testpython
steps:
- name: Get durations from cache
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ source/ # C++ source code and tests

### Build Dependencies and Setup

- **Python 3.9+** required
- **Python 3.10+** required
- **Virtual environment** strongly recommended: `uv venv venv && source venv/bin/activate`
- **Backend dependencies**: TensorFlow, PyTorch, JAX, or Paddle (install before building)
- **Build tools**: CMake, C++ compiler, scikit-build-core
Expand Down
5 changes: 1 addition & 4 deletions backend/dynamic_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
from pathlib import (
Path,
)
from typing import (
Optional,
)

from .find_pytorch import (
get_pt_requirement,
Expand All @@ -31,7 +28,7 @@ def __dir__() -> list[str]:

def dynamic_metadata(
field: str,
settings: Optional[dict[str, object]] = None,
settings: dict[str, object] | None = None,
):
assert field in ["optional-dependencies", "entry-points", "scripts"]
_, _, find_libpython_requires, extra_scripts, tf_version, pt_version = (
Expand Down
8 changes: 2 additions & 6 deletions backend/find_paddle.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@
from sysconfig import (
get_path,
)
from typing import (
Optional,
Union,
)


@lru_cache
def find_paddle() -> tuple[Optional[str], list[str]]:
def find_paddle() -> tuple[str | None, list[str]]:
"""Find PaddlePadle library.

Tries to find PaddlePadle in the order of:
Expand Down Expand Up @@ -111,7 +107,7 @@ def get_pd_requirement(pd_version: str = "") -> dict:


@lru_cache
def get_pd_version(pd_path: Optional[Union[str, Path]]) -> str:
def get_pd_version(pd_path: str | Path | None) -> str:
"""Get Paddle version from a Paddle Python library path.

Parameters
Expand Down
8 changes: 2 additions & 6 deletions backend/find_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
from sysconfig import (
get_path,
)
from typing import (
Optional,
Union,
)

from packaging.specifiers import (
SpecifierSet,
Expand All @@ -35,7 +31,7 @@


@lru_cache
def find_pytorch() -> tuple[Optional[str], list[str]]:
def find_pytorch() -> tuple[str | None, list[str]]:
"""Find PyTorch library.

Tries to find PyTorch in the order of:
Expand Down Expand Up @@ -150,7 +146,7 @@ def get_pt_requirement(pt_version: str = "") -> dict:


@lru_cache
def get_pt_version(pt_path: Optional[Union[str, Path]]) -> str:
def get_pt_version(pt_path: str | Path | None) -> str:
"""Get TF version from a TF Python library path.

Parameters
Expand Down
8 changes: 2 additions & 6 deletions backend/find_tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
from sysconfig import (
get_path,
)
from typing import (
Optional,
Union,
)

from packaging.specifiers import (
SpecifierSet,
Expand All @@ -32,7 +28,7 @@


@lru_cache
def find_tensorflow() -> tuple[Optional[str], list[str]]:
def find_tensorflow() -> tuple[str | None, list[str]]:
"""Find TensorFlow library.

Tries to find TensorFlow in the order of:
Expand Down Expand Up @@ -208,7 +204,7 @@ def get_tf_requirement(tf_version: str = "") -> dict:


@lru_cache
def get_tf_version(tf_path: Optional[Union[str, Path]]) -> str:
def get_tf_version(tf_path: str | Path | None) -> str:
"""Get TF version from a TF Python library path.

Parameters
Expand Down
4 changes: 3 additions & 1 deletion deepmd/backend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
from abc import (
abstractmethod,
)
from collections.abc import (
Callable,
)
from enum import (
Flag,
auto,
)
from typing import (
TYPE_CHECKING,
Callable,
ClassVar,
)

Expand Down
4 changes: 3 additions & 1 deletion deepmd/backend/dpmodel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
from collections.abc import (
Callable,
)
from typing import (
TYPE_CHECKING,
Callable,
ClassVar,
)

Expand Down
4 changes: 3 additions & 1 deletion deepmd/backend/jax.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
from collections.abc import (
Callable,
)
from importlib.util import (
find_spec,
)
from typing import (
TYPE_CHECKING,
Callable,
ClassVar,
)

Expand Down
4 changes: 3 additions & 1 deletion deepmd/backend/paddle.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
from collections.abc import (
Callable,
)
from importlib.util import (
find_spec,
)
from typing import (
TYPE_CHECKING,
Callable,
ClassVar,
)

Expand Down
4 changes: 3 additions & 1 deletion deepmd/backend/pytorch.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
from collections.abc import (
Callable,
)
from importlib.util import (
find_spec,
)
from typing import (
TYPE_CHECKING,
Callable,
ClassVar,
)

Expand Down
10 changes: 3 additions & 7 deletions deepmd/backend/suffix.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
from pathlib import (
Path,
)
from typing import (
Optional,
Union,
)

from deepmd.backend.backend import (
Backend,
Expand All @@ -16,9 +12,9 @@

def format_model_suffix(
filename: str,
feature: Optional[Backend.Feature] = None,
preferred_backend: Optional[Union[str, type["Backend"]]] = None,
strict_prefer: Optional[bool] = None,
feature: Backend.Feature | None = None,
preferred_backend: str | type["Backend"] | None = None,
strict_prefer: bool | None = None,
) -> str:
"""Check and format the suffixes of a filename.

Expand Down
4 changes: 3 additions & 1 deletion deepmd/backend/tensorflow.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
from collections.abc import (
Callable,
)
from importlib.util import (
find_spec,
)
from typing import (
TYPE_CHECKING,
Callable,
ClassVar,
)

Expand Down
4 changes: 2 additions & 2 deletions deepmd/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def __init__(
self,
model: Union[str, "Path"],
label: str = "DP",
type_dict: Optional[dict[str, int]] = None,
type_dict: dict[str, int] | None = None,
neighbor_list: Optional["NeighborList"] = None,
head: Optional[str] = None,
head: str | None = None,
**kwargs: Any,
) -> None:
Calculator.__init__(self, label=label, **kwargs)
Expand Down
7 changes: 3 additions & 4 deletions deepmd/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
TYPE_CHECKING,
Any,
TypeVar,
Union,
get_args,
)

try:
from typing import Literal # python >=3.8
except ImportError:
from typing_extensions import Literal # type: ignore
from typing import Literal # type: ignore

import numpy as np
import yaml
Expand Down Expand Up @@ -159,7 +158,7 @@ def j_deprecated(
return jdata[key]


def j_loader(filename: Union[str, Path]) -> dict[str, Any]:
def j_loader(filename: str | Path) -> dict[str, Any]:
"""Load yaml or json settings file.

Parameters
Expand Down Expand Up @@ -188,7 +187,7 @@ def j_loader(filename: Union[str, Path]) -> dict[str, Any]:
raise TypeError("config file must be json, or yaml/yml")


def expand_sys_str(root_dir: Union[str, Path]) -> list[str]:
def expand_sys_str(root_dir: str | Path) -> list[str]:
"""Recursively iterate over directories taking those that contain `type.raw` file.

Parameters
Expand Down
10 changes: 5 additions & 5 deletions deepmd/dpmodel/array_api.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
"""Utilities for the array API."""

from collections.abc import (
Callable,
)
from typing import (
Any,
Callable,
Optional,
Union,
)

import array_api_compat
Expand All @@ -15,7 +15,7 @@
)

# Type alias for array_api compatible arrays
Array = Union[np.ndarray, Any] # Any to support JAX, PyTorch, etc. arrays
Array = np.ndarray | Any # Any to support JAX, PyTorch, etc. arrays


def support_array_api(version: str) -> Callable:
Expand Down Expand Up @@ -125,7 +125,7 @@ def xp_add_at(x: Array, indices: Array, values: Array) -> Array:
return x


def xp_bincount(x: Array, weights: Optional[Array] = None, minlength: int = 0) -> Array:
def xp_bincount(x: Array, weights: Array | None = None, minlength: int = 0) -> Array:
"""Counts the number of occurrences of each value in x."""
xp = array_api_compat.array_namespace(x)
if array_api_compat.is_numpy_array(x) or array_api_compat.is_jax_array(x):
Expand Down
19 changes: 9 additions & 10 deletions deepmd/dpmodel/atomic_model/base_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import math
from typing import (
Any,
Optional,
)

import array_api_compat
Expand Down Expand Up @@ -45,8 +44,8 @@ def __init__(
type_map: list[str],
atom_exclude_types: list[int] = [],
pair_exclude_types: list[tuple[int, int]] = [],
rcond: Optional[float] = None,
preset_out_bias: Optional[dict[str, Array]] = None,
rcond: float | None = None,
preset_out_bias: dict[str, Array] | None = None,
) -> None:
super().__init__()
self.type_map = type_map
Expand Down Expand Up @@ -133,7 +132,7 @@ def atomic_output_def(self) -> FittingOutputDef:
)

def change_type_map(
self, type_map: list[str], model_with_new_type_stat: Optional[Any] = None
self, type_map: list[str], model_with_new_type_stat: Any | None = None
) -> None:
"""Change the type related params to new ones, according to `type_map` and the original one in the model.
If there are new types in `type_map`, statistics will be updated accordingly to `model_with_new_type_stat` for these new types.
Expand All @@ -154,9 +153,9 @@ def forward_common_atomic(
extended_coord: Array,
extended_atype: Array,
nlist: Array,
mapping: Optional[Array] = None,
fparam: Optional[Array] = None,
aparam: Optional[Array] = None,
mapping: Array | None = None,
fparam: Array | None = None,
aparam: Array | None = None,
) -> dict[str, Array]:
"""Common interface for atomic inference.

Expand Down Expand Up @@ -230,9 +229,9 @@ def call(
extended_coord: Array,
extended_atype: Array,
nlist: Array,
mapping: Optional[Array] = None,
fparam: Optional[Array] = None,
aparam: Optional[Array] = None,
mapping: Array | None = None,
fparam: Array | None = None,
aparam: Array | None = None,
) -> dict[str, Array]:
return self.forward_common_atomic(
extended_coord,
Expand Down
9 changes: 4 additions & 5 deletions deepmd/dpmodel/atomic_model/dp_atomic_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
from typing import (
Any,
Optional,
)

from deepmd.dpmodel.array_api import (
Expand Down Expand Up @@ -130,9 +129,9 @@ def forward_atomic(
extended_coord: Array,
extended_atype: Array,
nlist: Array,
mapping: Optional[Array] = None,
fparam: Optional[Array] = None,
aparam: Optional[Array] = None,
mapping: Array | None = None,
fparam: Array | None = None,
aparam: Array | None = None,
) -> dict[str, Array]:
"""Models' atomic predictions.

Expand Down Expand Up @@ -177,7 +176,7 @@ def forward_atomic(
return ret

def change_type_map(
self, type_map: list[str], model_with_new_type_stat: Optional[Any] = None
self, type_map: list[str], model_with_new_type_stat: Any | None = None
) -> None:
"""Change the type related params to new ones, according to `type_map` and the original one in the model.
If there are new types in `type_map`, statistics will be updated accordingly to `model_with_new_type_stat` for these new types.
Expand Down
Loading
Loading