Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: enable N804 and N805 #4024

Merged
merged 1 commit into from
Jul 26, 2024
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: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ repos:
exclude: ^source/3rdparty
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.4
rev: v0.5.5
hooks:
- id: ruff
args: ["--fix"]
Expand Down
2 changes: 1 addition & 1 deletion deepmd/pt/model/task/ener.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
def serialize(self) -> dict:
raise NotImplementedError

def deserialize(cls) -> "EnergyFittingNetDirect":
def deserialize(self) -> "EnergyFittingNetDirect":

Check warning on line 184 in deepmd/pt/model/task/ener.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/task/ener.py#L184

Added line #L184 was not covered by tests
raise NotImplementedError

def change_type_map(
Expand Down
4 changes: 2 additions & 2 deletions deepmd/utils/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@


class VariantMeta:
def __call__(cls, *args, **kwargs):
def __call__(self, *args, **kwargs):
"""Remove `type` and keys that starts with underline."""
obj = cls.__new__(cls, *args, **kwargs)
obj = self.__new__(self, *args, **kwargs)

Check warning on line 80 in deepmd/utils/plugin.py

View check run for this annotation

Codecov / codecov/patch

deepmd/utils/plugin.py#L80

Added line #L80 was not covered by tests
kwargs.pop("type", None)
to_pop = []
for kk in kwargs:
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ select = [
"TID253", # banned-module-level-imports
"T20", # ban print
"B904", # raise-without-from-inside-except
"N804", # invalid-first-argument-name-for-class-method
"N805", # invalid-first-argument-name-for-method
]

ignore = [
Expand Down
14 changes: 7 additions & 7 deletions source/tests/tf/test_adjust_sel.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ def _init_models():

class TestDeepPotAAdjustSel(unittest.TestCase):
@classmethod
def setUpClass(self):
def setUpClass(cls):
INPUT, FROZEN_MODEL, DECREASED_MODEL, INCREASED_MODEL = _init_models()
self.dp_original = DeepPot(FROZEN_MODEL)
self.dp_decreased = DeepPot(DECREASED_MODEL)
self.dp_increased = DeepPot(INCREASED_MODEL)
self.coords = np.array(
cls.dp_original = DeepPot(FROZEN_MODEL)
cls.dp_decreased = DeepPot(DECREASED_MODEL)
cls.dp_increased = DeepPot(INCREASED_MODEL)
cls.coords = np.array(
[
12.83,
2.56,
Expand All @@ -99,8 +99,8 @@ def setUpClass(self):
1.56,
]
)
self.atype = [0, 1, 1, 0, 1, 1]
self.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
cls.atype = [0, 1, 1, 0, 1, 1]
cls.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])

def test_attrs(self):
self.assertEqual(self.dp_original.get_ntypes(), 2)
Expand Down
16 changes: 8 additions & 8 deletions source/tests/tf/test_finetune_se_atten.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ def compressible_model(jdata):
cls.VALID_DATAS = VALID_DATAS

@classmethod
def tearDownClass(self):
for i in range(len(self.INPUT_PRES)):
_file_delete(self.INPUT_PRES[i])
_file_delete(self.INPUT_FINETUNES[i])
_file_delete(self.INPUT_FINETUNE_MIXS[i])
_file_delete(self.PRE_MODELS[i])
_file_delete(self.FINETUNED_MODELS[i])
_file_delete(self.FINETUNED_MODEL_MIXS[i])
def tearDownClass(cls):
for i in range(len(cls.INPUT_PRES)):
_file_delete(cls.INPUT_PRES[i])
_file_delete(cls.INPUT_FINETUNES[i])
_file_delete(cls.INPUT_FINETUNE_MIXS[i])
_file_delete(cls.PRE_MODELS[i])
_file_delete(cls.FINETUNED_MODELS[i])
_file_delete(cls.FINETUNED_MODEL_MIXS[i])
_file_delete("out.json")
_file_delete("model.ckpt.meta")
_file_delete("model.ckpt.index")
Expand Down
50 changes: 25 additions & 25 deletions source/tests/tf/test_model_compression_se_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ def setUpModule():

class TestDeepPotAPBC(unittest.TestCase):
@classmethod
def setUpClass(self):
self.dp_original = DeepPot(FROZEN_MODEL)
self.dp_compressed = DeepPot(COMPRESSED_MODEL)
self.coords = np.array(
def setUpClass(cls):
cls.dp_original = DeepPot(FROZEN_MODEL)
cls.dp_compressed = DeepPot(COMPRESSED_MODEL)
cls.coords = np.array(
[
12.83,
2.56,
Expand All @@ -112,8 +112,8 @@ def setUpClass(self):
1.56,
]
)
self.atype = [0, 1, 1, 0, 1, 1]
self.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
cls.atype = [0, 1, 1, 0, 1, 1]
cls.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])

def test_attrs(self):
self.assertEqual(self.dp_original.get_ntypes(), 2)
Expand Down Expand Up @@ -211,10 +211,10 @@ def test_2frame_atm(self):

class TestDeepPotANoPBC(unittest.TestCase):
@classmethod
def setUpClass(self):
self.dp_original = DeepPot(FROZEN_MODEL)
self.dp_compressed = DeepPot(COMPRESSED_MODEL)
self.coords = np.array(
def setUpClass(cls):
cls.dp_original = DeepPot(FROZEN_MODEL)
cls.dp_compressed = DeepPot(COMPRESSED_MODEL)
cls.coords = np.array(
[
12.83,
2.56,
Expand All @@ -236,8 +236,8 @@ def setUpClass(self):
1.56,
]
)
self.atype = [0, 1, 1, 0, 1, 1]
self.box = None
cls.atype = [0, 1, 1, 0, 1, 1]
cls.box = None

def test_1frame(self):
ee0, ff0, vv0 = self.dp_original.eval(
Expand Down Expand Up @@ -319,10 +319,10 @@ def test_2frame_atm(self):

class TestDeepPotALargeBoxNoPBC(unittest.TestCase):
@classmethod
def setUpClass(self):
self.dp_original = DeepPot(FROZEN_MODEL)
self.dp_compressed = DeepPot(COMPRESSED_MODEL)
self.coords = np.array(
def setUpClass(cls):
cls.dp_original = DeepPot(FROZEN_MODEL)
cls.dp_compressed = DeepPot(COMPRESSED_MODEL)
cls.coords = np.array(
[
12.83,
2.56,
Expand All @@ -344,8 +344,8 @@ def setUpClass(self):
1.56,
]
)
self.atype = [0, 1, 1, 0, 1, 1]
self.box = np.array([19.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
cls.atype = [0, 1, 1, 0, 1, 1]
cls.box = np.array([19.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])

def test_1frame(self):
ee0, ff0, vv0 = self.dp_original.eval(
Expand Down Expand Up @@ -427,10 +427,10 @@ def test_ase(self):

class TestDeepPotAPBCExcludeTypes(unittest.TestCase):
@classmethod
def setUpClass(self):
self.dp_original = DeepPot(FROZEN_MODEL_ET)
self.dp_compressed = DeepPot(COMPRESSED_MODEL_ET)
self.coords = np.array(
def setUpClass(cls):
cls.dp_original = DeepPot(FROZEN_MODEL_ET)
cls.dp_compressed = DeepPot(COMPRESSED_MODEL_ET)
cls.coords = np.array(
[
12.83,
2.56,
Expand All @@ -452,11 +452,11 @@ def setUpClass(self):
1.56,
]
)
self.atype = [0, 1, 1, 0, 1, 1]
self.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
cls.atype = [0, 1, 1, 0, 1, 1]
cls.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])

@classmethod
def tearDownClass(self):
def tearDownClass(cls):
_file_delete(INPUT_ET)
_file_delete(FROZEN_MODEL_ET)
_file_delete(COMPRESSED_MODEL_ET)
Expand Down
50 changes: 25 additions & 25 deletions source/tests/tf/test_model_compression_se_a_ebd.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ def setUpModule():

class TestDeepPotAPBC(unittest.TestCase):
@classmethod
def setUpClass(self):
self.dp_original = DeepPot(FROZEN_MODEL)
self.dp_compressed = DeepPot(COMPRESSED_MODEL)
self.coords = np.array(
def setUpClass(cls):
cls.dp_original = DeepPot(FROZEN_MODEL)
cls.dp_compressed = DeepPot(COMPRESSED_MODEL)
cls.coords = np.array(
[
12.83,
2.56,
Expand All @@ -124,8 +124,8 @@ def setUpClass(self):
1.56,
]
)
self.atype = [0, 1, 1, 0, 1, 1]
self.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
cls.atype = [0, 1, 1, 0, 1, 1]
cls.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])

def test_attrs(self):
self.assertEqual(self.dp_original.get_ntypes(), 2)
Expand Down Expand Up @@ -223,10 +223,10 @@ def test_2frame_atm(self):

class TestDeepPotANoPBC(unittest.TestCase):
@classmethod
def setUpClass(self):
self.dp_original = DeepPot(FROZEN_MODEL)
self.dp_compressed = DeepPot(COMPRESSED_MODEL)
self.coords = np.array(
def setUpClass(cls):
cls.dp_original = DeepPot(FROZEN_MODEL)
cls.dp_compressed = DeepPot(COMPRESSED_MODEL)
cls.coords = np.array(
[
12.83,
2.56,
Expand All @@ -248,8 +248,8 @@ def setUpClass(self):
1.56,
]
)
self.atype = [0, 1, 1, 0, 1, 1]
self.box = None
cls.atype = [0, 1, 1, 0, 1, 1]
cls.box = None

def test_1frame(self):
ee0, ff0, vv0 = self.dp_original.eval(
Expand Down Expand Up @@ -331,10 +331,10 @@ def test_2frame_atm(self):

class TestDeepPotALargeBoxNoPBC(unittest.TestCase):
@classmethod
def setUpClass(self):
self.dp_original = DeepPot(FROZEN_MODEL)
self.dp_compressed = DeepPot(COMPRESSED_MODEL)
self.coords = np.array(
def setUpClass(cls):
cls.dp_original = DeepPot(FROZEN_MODEL)
cls.dp_compressed = DeepPot(COMPRESSED_MODEL)
cls.coords = np.array(
[
12.83,
2.56,
Expand All @@ -356,8 +356,8 @@ def setUpClass(self):
1.56,
]
)
self.atype = [0, 1, 1, 0, 1, 1]
self.box = np.array([19.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
cls.atype = [0, 1, 1, 0, 1, 1]
cls.box = np.array([19.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])

def test_1frame(self):
ee0, ff0, vv0 = self.dp_original.eval(
Expand Down Expand Up @@ -439,10 +439,10 @@ def test_ase(self):

class TestDeepPotAPBCExcludeTypes(unittest.TestCase):
@classmethod
def setUpClass(self):
self.dp_original = DeepPot(FROZEN_MODEL_ET)
self.dp_compressed = DeepPot(COMPRESSED_MODEL_ET)
self.coords = np.array(
def setUpClass(cls):
cls.dp_original = DeepPot(FROZEN_MODEL_ET)
cls.dp_compressed = DeepPot(COMPRESSED_MODEL_ET)
cls.coords = np.array(
[
12.83,
2.56,
Expand All @@ -464,11 +464,11 @@ def setUpClass(self):
1.56,
]
)
self.atype = [0, 1, 1, 0, 1, 1]
self.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
cls.atype = [0, 1, 1, 0, 1, 1]
cls.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])

@classmethod
def tearDownClass(self):
def tearDownClass(cls):
_file_delete(INPUT_ET)
_file_delete(FROZEN_MODEL_ET)
_file_delete(COMPRESSED_MODEL_ET)
Expand Down
Loading