forked from deepmodeling/deepmd-kit
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jax/array-api): hybrid descriptor
Signed-off-by: Jinzhe Zeng <[email protected]>
- Loading branch information
Showing
10 changed files
with
142 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
from typing import ( | ||
Any, | ||
) | ||
|
||
from deepmd.dpmodel.descriptor.hybrid import DescrptHybrid as DescrptHybridDP | ||
from deepmd.jax.common import ( | ||
ArrayAPIVariable, | ||
flax_module, | ||
to_jax_array, | ||
) | ||
from deepmd.jax.descriptor.base_descriptor import ( | ||
BaseDescriptor, | ||
) | ||
|
||
|
||
@BaseDescriptor.register("hybrid") | ||
@flax_module | ||
class DescrptHybrid(DescrptHybridDP): | ||
def __setattr__(self, name: str, value: Any) -> None: | ||
if name in {"nlist_cut_idx"}: | ||
value = [ArrayAPIVariable(to_jax_array(vv)) for vv in value] | ||
elif name in {"descrpt_list"}: | ||
value = [BaseDescriptor.deserialize(vv.serialize()) for vv in value] | ||
|
||
return super().__setattr__(name, value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,20 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
from .dpa1 import ( | ||
DescrptDPA1, | ||
) | ||
from .hybrid import ( | ||
DescrptHybrid, | ||
) | ||
from .se_e2_a import ( | ||
DescrptSeA, | ||
) | ||
from .se_e2_r import ( | ||
DescrptSeR, | ||
) | ||
|
||
__all__ = [ | ||
"DescrptSeA", | ||
"DescrptSeR", | ||
"DescrptDPA1", | ||
"DescrptHybrid", | ||
] |
11 changes: 11 additions & 0 deletions
11
source/tests/array_api_strict/descriptor/base_descriptor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
from typing import ( | ||
Any, | ||
) | ||
|
||
from deepmd.dpmodel.descriptor.make_base_descriptor import ( | ||
make_base_descriptor, | ||
) | ||
|
||
# no type annotations standard in array api | ||
BaseDescriptor = make_base_descriptor(Any) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
from typing import ( | ||
Any, | ||
) | ||
|
||
from deepmd.dpmodel.descriptor.hybrid import DescrptHybrid as DescrptHybridDP | ||
|
||
from ..common import ( | ||
to_array_api_strict_array, | ||
) | ||
from .base_descriptor import ( | ||
BaseDescriptor, | ||
) | ||
|
||
|
||
@BaseDescriptor.register("hybrid") | ||
class DescrptHybrid(DescrptHybridDP): | ||
def __setattr__(self, name: str, value: Any) -> None: | ||
if name in {"nlist_cut_idx"}: | ||
value = [to_array_api_strict_array(vv) for vv in value] | ||
elif name in {"descrpt_list"}: | ||
value = [BaseDescriptor.deserialize(vv.serialize()) for vv in value] | ||
|
||
return super().__setattr__(name, value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters