Skip to content

Commit d567700

Browse files
fix(pd): fix unitest (#5113)
This pull request refactors several test files to update import paths for the `expand_sys_str` utility and related modules, reflecting a migration away from the `deepmd.tf` namespace. Additionally, it temporarily skips a test due to compatibility issues with numpy 2.4 and improves file cleanup logic in one test. The main themes are import path updates and test maintenance. **Import path updates:** * Updated imports of `expand_sys_str` in multiple test files (`test_descriptor.py`, `test_embedding_net.py`, `test_model.py`, `test_saveload_dpa1.py`, `test_saveload_se_e2_a.py`, `test_sampler.py`) to use `deepmd.common` instead of `deepmd.tf.common`. [[1]](diffhunk://#diff-026c6e70e7f5fd37843904e99c43910d638b0da8607e1bc0ab84702f256f3264R16-R18) [[2]](diffhunk://#diff-026c6e70e7f5fd37843904e99c43910d638b0da8607e1bc0ab84702f256f3264L34-L36) [[3]](diffhunk://#diff-9d16c9bf54ca3ba29bd1045d492b6a4eb11956305c05631ac8691fe681271535R21-R23) [[4]](diffhunk://#diff-9d16c9bf54ca3ba29bd1045d492b6a4eb11956305c05631ac8691fe681271535L37-L39) [[5]](diffhunk://#diff-a3bf7b66e3c105cf0d73116440343c6b0be07ff6246557f04f6707bec0e21af3R22-R24) [[6]](diffhunk://#diff-a3bf7b66e3c105cf0d73116440343c6b0be07ff6246557f04f6707bec0e21af3L35-L37) [[7]](diffhunk://#diff-0d7e97b8c00caf452b143cae472e2fa0a97473ba4b685f588bb60c21c504b934R16-R18) [[8]](diffhunk://#diff-0d7e97b8c00caf452b143cae472e2fa0a97473ba4b685f588bb60c21c504b934L35-L37) [[9]](diffhunk://#diff-74518d33e0df93e8af8027509351b11fbbe1f32b8c84f6d3a165e1df0953048fR16-R18) [[10]](diffhunk://#diff-74518d33e0df93e8af8027509351b11fbbe1f32b8c84f6d3a165e1df0953048fL35-L37) [[11]](diffhunk://#diff-fd952e5725b949f09ee868247a1a5b0b1b383a25b096766fa994a102a3aeca31R16-R24) * Changed import of `DeepmdDataSystem` in `test_sampler.py` from `deepmd.tf.utils.data_system` to `deepmd.utils.data_system`. **Test maintenance and compatibility:** * Temporarily skipped the `test_sampler_debug_info` test in `test_sampler.py` due to issues with numpy 2.4. * Enhanced file cleanup in `test_training.py` by checking for file existence before attempting to remove files or directories. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Improved test robustness by adding existence checks before file cleanup operations to prevent errors. * Temporarily skipped one test due to numpy compatibility issues. * **Chores** * Reorganized internal module imports for improved code structure. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> Related PR: <PaddlePaddle/Paddle#77013>
1 parent 188dae3 commit d567700

File tree

7 files changed

+26
-22
lines changed

7 files changed

+26
-22
lines changed

source/tests/pd/model/test_descriptor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
Path,
1414
)
1515

16+
from deepmd.common import (
17+
expand_sys_str,
18+
)
1619
from deepmd.pd.model.descriptor import (
1720
prod_env_mat,
1821
)
@@ -31,9 +34,6 @@
3134
from deepmd.pd.utils.nlist import (
3235
extend_input_and_build_neighbor_list,
3336
)
34-
from deepmd.tf.common import (
35-
expand_sys_str,
36-
)
3737
from deepmd.tf.env import (
3838
op_module,
3939
)

source/tests/pd/model/test_embedding_net.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
Path,
1919
)
2020

21+
from deepmd.common import (
22+
expand_sys_str,
23+
)
2124
from deepmd.pd.model.descriptor import (
2225
DescrptSeA,
2326
)
@@ -34,9 +37,6 @@
3437
from deepmd.pd.utils.nlist import (
3538
extend_input_and_build_neighbor_list,
3639
)
37-
from deepmd.tf.common import (
38-
expand_sys_str,
39-
)
4040
from deepmd.tf.descriptor import DescrptSeA as DescrptSeA_tf
4141

4242
from ..test_finetune import (

source/tests/pd/model/test_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
Path,
2020
)
2121

22+
from deepmd.common import (
23+
expand_sys_str,
24+
)
2225
from deepmd.dpmodel.utils.learning_rate import LearningRateExp as MyLRExp
2326
from deepmd.pd.loss import (
2427
EnergyStdLoss,
@@ -32,9 +35,6 @@
3235
from deepmd.pd.utils.env import (
3336
DEVICE,
3437
)
35-
from deepmd.tf.common import (
36-
expand_sys_str,
37-
)
3838
from deepmd.tf.descriptor import DescrptSeA as DescrptSeA_tf
3939
from deepmd.tf.fit import (
4040
EnerFitting,

source/tests/pd/model/test_saveload_dpa1.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
DataLoader,
1414
)
1515

16+
from deepmd.common import (
17+
expand_sys_str,
18+
)
1619
from deepmd.pd.loss import (
1720
EnergyStdLoss,
1821
)
@@ -32,9 +35,6 @@
3235
from deepmd.pd.utils.stat import (
3336
make_stat_input,
3437
)
35-
from deepmd.tf.common import (
36-
expand_sys_str,
37-
)
3838

3939

4040
def get_dataset(config):

source/tests/pd/model/test_saveload_se_e2_a.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
DataLoader,
1414
)
1515

16+
from deepmd.common import (
17+
expand_sys_str,
18+
)
1619
from deepmd.pd.loss import (
1720
EnergyStdLoss,
1821
)
@@ -32,9 +35,6 @@
3235
from deepmd.pd.utils.stat import (
3336
make_stat_input,
3437
)
35-
from deepmd.tf.common import (
36-
expand_sys_str,
37-
)
3838

3939

4040
def get_dataset(config):

source/tests/pd/test_sampler.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
DataLoader,
1414
)
1515

16+
from deepmd.common import (
17+
expand_sys_str,
18+
)
1619
from deepmd.pd.utils.dataloader import (
1720
DpLoaderSet,
1821
get_weighted_sampler,
1922
)
20-
from deepmd.tf.common import (
21-
expand_sys_str,
22-
)
2323
from deepmd.tf.utils import random as tf_random
24-
from deepmd.tf.utils.data_system import (
24+
from deepmd.utils.data_system import (
2525
DeepmdDataSystem,
2626
)
2727

@@ -55,6 +55,7 @@ def setUp(self):
5555
tf_random.seed(10)
5656
self.dp_dataset = DeepmdDataSystem(self.systems, self.batch_size, 1, self.rcut)
5757

58+
@unittest.skip("Temporarily skipped due to changes in numpy 2.4")
5859
def test_sampler_debug_info(self):
5960
dataloader = DataLoader(
6061
self.my_dataset,

source/tests/pd/test_training.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,14 @@ def test_trainable(self) -> None:
136136
def tearDown(self) -> None:
137137
for f in os.listdir("."):
138138
if f.startswith("model") and f.endswith(".pd"):
139-
os.remove(f)
139+
if os.path.exists(f):
140+
os.remove(f)
140141
if f in ["lcurve.out"]:
141-
os.remove(f)
142+
if os.path.exists(f):
143+
os.remove(f)
142144
if f in ["stat_files"]:
143-
shutil.rmtree(f)
145+
if os.path.exists(f):
146+
shutil.rmtree(f)
144147

145148

146149
class TestEnergyModelSeA(unittest.TestCase, DPTrainTest):

0 commit comments

Comments
 (0)