-
Notifications
You must be signed in to change notification settings - Fork 525
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 (#4275)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced support for the JAX backend in the hybrid descriptor framework. - Added a new `DescrptHybrid` class with specialized attribute handling. - Enhanced testing framework to support additional backends, including JAX and strict array API. - **Bug Fixes** - Improved attribute handling in multiple descriptor classes to ensure proper deserialization and registration. - **Documentation** - Updated documentation to reflect the addition of JAX as a supported backend for hybrid descriptors. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
- Loading branch information
Showing
11 changed files
with
144 additions
and
7 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
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