|
19 | 19 | ) |
20 | 20 |
|
21 | 21 | from ..common import ( |
| 22 | + INSTALLED_ARRAY_API_STRICT, |
22 | 23 | INSTALLED_PT, |
23 | 24 | INSTALLED_PT_EXPT, |
24 | 25 | CommonTest, |
|
28 | 29 | DescriptorTest, |
29 | 30 | ) |
30 | 31 |
|
31 | | -if INSTALLED_PT: |
32 | | - from deepmd.pt.model.descriptor.sezm import DescrptSeZM as DescrptDPA4PT |
33 | | -else: |
34 | | - DescrptDPA4PT = None |
35 | | -if INSTALLED_PT_EXPT: |
36 | | - from deepmd.pt_expt.descriptor.dpa4 import DescrptDPA4 as DescrptDPA4PTExpt |
| 32 | +DescrptDPA4PT = None |
| 33 | +DescrptDPA4PTExpt = None |
| 34 | + |
| 35 | + |
| 36 | +def _get_descrpt_dpa4_pt() -> type | None: |
| 37 | + global DescrptDPA4PT |
| 38 | + if not INSTALLED_PT: |
| 39 | + return None |
| 40 | + if DescrptDPA4PT is None: |
| 41 | + from deepmd.pt.model.descriptor.sezm import ( |
| 42 | + DescrptSeZM, |
| 43 | + ) |
| 44 | + |
| 45 | + DescrptDPA4PT = DescrptSeZM |
| 46 | + return DescrptDPA4PT |
| 47 | + |
| 48 | + |
| 49 | +def _get_descrpt_dpa4_pt_expt() -> type | None: |
| 50 | + global DescrptDPA4PTExpt |
| 51 | + if not INSTALLED_PT_EXPT: |
| 52 | + return None |
| 53 | + if DescrptDPA4PTExpt is None: |
| 54 | + from deepmd.pt_expt.descriptor.dpa4 import ( |
| 55 | + DescrptDPA4, |
| 56 | + ) |
| 57 | + |
| 58 | + DescrptDPA4PTExpt = DescrptDPA4 |
| 59 | + return DescrptDPA4PTExpt |
| 60 | + |
| 61 | + |
| 62 | +if INSTALLED_ARRAY_API_STRICT: |
| 63 | + from ...array_api_strict.descriptor.dpa4 import DescrptDPA4 as DescrptDPA4Strict |
37 | 64 | else: |
38 | | - DescrptDPA4PTExpt = None |
| 65 | + DescrptDPA4Strict = None |
39 | 66 |
|
40 | 67 | # not implemented |
41 | 68 | DescrptDPA4TF = None |
@@ -146,22 +173,31 @@ def data(self) -> dict: |
146 | 173 |
|
147 | 174 | @property |
148 | 175 | def skip_pt(self) -> bool: |
149 | | - return CommonTest.skip_pt |
| 176 | + return CommonTest.skip_pt or _get_descrpt_dpa4_pt() is None |
| 177 | + |
| 178 | + @property |
| 179 | + def skip_pt_expt(self) -> bool: |
| 180 | + return not INSTALLED_PT_EXPT or _get_descrpt_dpa4_pt_expt() is None |
| 181 | + |
| 182 | + @property |
| 183 | + def pt_class(self) -> type | None: |
| 184 | + return _get_descrpt_dpa4_pt() |
| 185 | + |
| 186 | + @property |
| 187 | + def pt_expt_class(self) -> type | None: |
| 188 | + return _get_descrpt_dpa4_pt_expt() |
150 | 189 |
|
151 | 190 | skip_dp = False |
152 | 191 | skip_tf = True |
153 | 192 | skip_jax = True |
154 | 193 | skip_pd = True |
155 | | - skip_pt_expt = not INSTALLED_PT_EXPT |
156 | | - skip_array_api_strict = True |
| 194 | + skip_array_api_strict = not INSTALLED_ARRAY_API_STRICT |
157 | 195 |
|
158 | 196 | tf_class = DescrptDPA4TF |
159 | 197 | dp_class = DescrptDPA4DP |
160 | | - pt_class = DescrptDPA4PT |
161 | | - pt_expt_class = DescrptDPA4PTExpt |
162 | 198 | jax_class = None |
163 | 199 | pd_class = None |
164 | | - array_api_strict_class = None |
| 200 | + array_api_strict_class = DescrptDPA4Strict |
165 | 201 | args: ClassVar[list] = [ |
166 | 202 | *descrpt_se_zm_args(), |
167 | 203 | Argument("ntypes", int, optional=False), |
@@ -234,6 +270,16 @@ def eval_pt_expt(self, pt_expt_obj: Any) -> Any: |
234 | 270 | mixed_types=True, |
235 | 271 | ) |
236 | 272 |
|
| 273 | + def eval_array_api_strict(self, array_api_strict_obj: Any) -> Any: |
| 274 | + return self.eval_array_api_strict_descriptor( |
| 275 | + array_api_strict_obj, |
| 276 | + self.natoms, |
| 277 | + self.coords, |
| 278 | + self.atype, |
| 279 | + self.box, |
| 280 | + mixed_types=True, |
| 281 | + ) |
| 282 | + |
237 | 283 | def extract_ret(self, ret: Any, backend) -> tuple[np.ndarray, ...]: |
238 | 284 | return (ret[0],) |
239 | 285 |
|
|
0 commit comments