From 67727c07007619a6ff7ce59a308ea601d1b3c0ea Mon Sep 17 00:00:00 2001 From: Han Wang Date: Tue, 10 Dec 2024 22:48:09 +0800 Subject: [PATCH 1/6] update ruff version --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a5d41652..65f3f166 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: # Python - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.8.1 + rev: v0.8.2 hooks: - id: ruff args: ["--fix"] From 7c14d452df736ac18e7b97099ddf4d6daa97ce26 Mon Sep 17 00:00:00 2001 From: Han Wang Date: Tue, 10 Dec 2024 23:25:14 +0800 Subject: [PATCH 2/6] fix: pyright error: Type "floating[Any]" is not assignable to return type "ndarray[Unknown, Unknown]" --- dpdata/stat.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/dpdata/stat.py b/dpdata/stat.py index 5ec39570..ed74c258 100644 --- a/dpdata/stat.py +++ b/dpdata/stat.py @@ -2,13 +2,14 @@ from abc import ABCMeta, abstractmethod from functools import lru_cache +from typing import Any import numpy as np from dpdata.system import LabeledSystem, MultiSystems -def mae(errors: np.ndarray) -> np.float64: +def mae(errors: np.ndarray) -> np.floating[Any]: """Compute the mean absolute error (MAE). Parameters @@ -18,13 +19,13 @@ def mae(errors: np.ndarray) -> np.float64: Returns ------- - np.float64 + floating[Any] mean absolute error (MAE) """ return np.mean(np.abs(errors)) -def rmse(errors: np.ndarray) -> np.float64: +def rmse(errors: np.ndarray) -> np.floating[Any]: """Compute the root mean squared error (RMSE). Parameters @@ -34,7 +35,7 @@ def rmse(errors: np.ndarray) -> np.float64: Returns ------- - np.float64 + floating[Any] root mean squared error (RMSE) """ return np.sqrt(np.mean(np.square(errors))) @@ -74,22 +75,22 @@ def f_errors(self) -> np.ndarray: """Force errors.""" @property - def e_mae(self) -> np.float64: + def e_mae(self) -> np.floating[Any]: """Energy MAE.""" return mae(self.e_errors) @property - def e_rmse(self) -> np.float64: + def e_rmse(self) -> np.floating[Any]: """Energy RMSE.""" return rmse(self.e_errors) @property - def f_mae(self) -> np.float64: + def f_mae(self) -> np.floating[Any]: """Force MAE.""" return mae(self.f_errors) @property - def f_rmse(self) -> np.float64: + def f_rmse(self) -> np.floating[Any]: """Force RMSE.""" return rmse(self.f_errors) From 099a16347a341cd9caa88d78f239085ebd9b5047 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 10 Dec 2024 18:10:53 -0500 Subject: [PATCH 3/6] narrow types --- dpdata/system.py | 1 + 1 file changed, 1 insertion(+) diff --git a/dpdata/system.py b/dpdata/system.py index abe0a755..2bb28ad6 100644 --- a/dpdata/system.py +++ b/dpdata/system.py @@ -1049,6 +1049,7 @@ def remove_atom_names(self, atom_names: str | list[str]): atom_idx = self.data["atom_types"] == idx removed_atom_idx.append(atom_idx) picked_atom_idx = ~np.any(removed_atom_idx, axis=0) + assert not isinstance(picked_atom_idx, np.bool) new_sys = self.pick_atom_idx(picked_atom_idx) # let's remove atom_names # firstly, rearrange atom_names and put these atom_names in the end From c1c93fb9c17d61be2719a1ed1fd7e1450f2dee5f Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Fri, 13 Dec 2024 09:08:56 -0500 Subject: [PATCH 4/6] Fix NPY<2 compatibility Signed-off-by: Jinzhe Zeng --- dpdata/system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpdata/system.py b/dpdata/system.py index 2bb28ad6..00172602 100644 --- a/dpdata/system.py +++ b/dpdata/system.py @@ -1049,7 +1049,7 @@ def remove_atom_names(self, atom_names: str | list[str]): atom_idx = self.data["atom_types"] == idx removed_atom_idx.append(atom_idx) picked_atom_idx = ~np.any(removed_atom_idx, axis=0) - assert not isinstance(picked_atom_idx, np.bool) + assert not isinstance(picked_atom_idx, np.bool_) new_sys = self.pick_atom_idx(picked_atom_idx) # let's remove atom_names # firstly, rearrange atom_names and put these atom_names in the end From c1d07a72d69f992f33becafc4286f9ab79d962f0 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 19 Dec 2024 01:11:38 -0500 Subject: [PATCH 5/6] Fix "ValueError: The truth value of an empty array is ambiguous. Use `array.size > 0` to check that an array is not empty." Signed-off-by: Jinzhe Zeng --- tests/test_abacus_pw_scf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_abacus_pw_scf.py b/tests/test_abacus_pw_scf.py index 20751f81..0d2bdef5 100644 --- a/tests/test_abacus_pw_scf.py +++ b/tests/test_abacus_pw_scf.py @@ -158,7 +158,7 @@ def test_noforcestress_job(self): # check below will not throw error system_ch4 = dpdata.LabeledSystem("abacus.scf", fmt="abacus/scf") # check the returned force is empty - self.assertFalse(system_ch4.data["forces"]) + self.assertFalse(system_ch4.data["forces"].size) self.assertTrue("virials" not in system_ch4.data) # test append self system_ch4.append(system_ch4) From 663bdf6657adc8aa505383d144ce1e1efadf8242 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 19 Dec 2024 01:17:18 -0500 Subject: [PATCH 6/6] pin ubuntu to 22.04 see https://github.com/actions/setup-python/issues/962 Signed-off-by: Jinzhe Zeng --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b195da2f..f0db255a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: matrix: python-version: ["3.7", "3.8", "3.12"]