11# SPDX-License-Identifier: LGPL-3.0-or-later
2- import sys
32import unittest
3+ from copy import (
4+ deepcopy ,
5+ )
46
57import numpy as np
68import torch
7- from copy import deepcopy
89
910from deepmd .dpmodel .common import (
1011 to_numpy_array ,
1112)
12-
1313from deepmd .pt .model .descriptor import (
1414 DescrptSeA ,
1515)
16- from deepmd .pt .model .task import (
17- PropertyFittingNet ,
18- )
1916from deepmd .pt .model .model import (
2017 PropertyModel ,
2118)
19+ from deepmd .pt .model .task import (
20+ PropertyFittingNet ,
21+ )
2222from deepmd .pt .utils .utils import (
2323 to_torch_tensor ,
2424)
@@ -40,13 +40,13 @@ def setUp(self) -> None:
4040 [1 , 0 , 1 ],
4141 [0 , 1 , 1 ],
4242 [1 , 1 , 0 ],
43- ]
43+ ],
4444 ],
4545 dtype = np .float64 ,
4646 )
47- self .atype = np .array ([[0 , 0 , 1 ],[1 , 1 , 0 ]], dtype = int ).reshape ([2 , self .nloc ])
47+ self .atype = np .array ([[0 , 0 , 1 ], [1 , 1 , 0 ]], dtype = int ).reshape ([2 , self .nloc ])
4848 self .cell = 2.0 * np .eye (3 ).reshape ([1 , 9 ])
49- self .cell = np .array ([self .cell ,self .cell ]).reshape (2 , 9 )
49+ self .cell = np .array ([self .cell , self .cell ]).reshape (2 , 9 )
5050 self .sel = [16 , 8 ]
5151 self .rcut = 2.2
5252 self .rcut_smth = 0.4
@@ -78,7 +78,7 @@ def test_padding_atoms_consistency(self):
7878 # test intensive
7979 np .testing .assert_allclose (
8080 to_numpy_array (result [var_name ].cpu ().detach ()),
81- np .mean (to_numpy_array (result [f"atom_{ var_name } " ].cpu ().detach ()),axis = 1 ),
81+ np .mean (to_numpy_array (result [f"atom_{ var_name } " ].cpu ().detach ()), axis = 1 ),
8282 atol = self .atol ,
8383 )
8484 # test padding atoms
@@ -89,17 +89,20 @@ def test_padding_atoms_consistency(self):
8989 atype_padding = np .pad (
9090 atype ,
9191 pad_width = ((0 , 0 ), (0 , padding_atoms )),
92- mode = ' constant' ,
93- constant_values = - 1
92+ mode = " constant" ,
93+ constant_values = - 1 ,
9494 )
9595 coord_padding = np .pad (
9696 coord ,
9797 pad_width = ((0 , 0 ), (0 , padding_atoms ), (0 , 0 )),
98- mode = ' constant' ,
99- constant_values = 0
98+ mode = " constant" ,
99+ constant_values = 0 ,
100100 )
101101 with torch .device ("cpu" ):
102- args = [to_torch_tensor (ii ) for ii in [coord_padding , atype_padding , self .cell ]]
102+ args = [
103+ to_torch_tensor (ii )
104+ for ii in [coord_padding , atype_padding , self .cell ]
105+ ]
103106 result_padding = model (* args )
104107 np .testing .assert_allclose (
105108 to_numpy_array (result [var_name ].cpu ().detach ()),
0 commit comments