-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jax): energy model (no grad support) (#4226)
Add JAX energy model without grad support. The grad support needs discussion. Array API is not supported in this PR as it needs more effort. (JAX has more APIs than Array API) This PR also fixes a `skip_tf` bug introduced in #3357. When no `@property` was added, `xx.skip_tf` is always cast to `True`. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Enhanced `BaseAtomicModel` and `DPAtomicModel` classes with improved array compatibility and new output definitions. - Introduced new classes and attributes for better model flexibility and customization. - Added `EnergyFittingNet` and `DOSFittingNet` for advanced fitting capabilities. - New functions `get_standard_model` and `get_model` for flexible model creation based on input data. - Added `BaseDescriptor` and `BaseFitting` classes to streamline descriptor and fitting processes. - Introduced `EnergyModel` class for improved atomic model handling. - **Bug Fixes** - Updated serialization logic for consistency across models. - **Tests** - Enhanced testing framework to support JAX operations and added methods for JAX model evaluation. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Jinzhe Zeng <[email protected]>
- Loading branch information
Showing
20 changed files
with
289 additions
and
30 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
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 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later |
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,18 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
from deepmd.jax.common import ( | ||
to_jax_array, | ||
) | ||
from deepmd.jax.utils.exclude_mask import ( | ||
AtomExcludeMask, | ||
PairExcludeMask, | ||
) | ||
|
||
|
||
def base_atomic_model_set_attr(name, value): | ||
if name in {"out_bias", "out_std"}: | ||
value = to_jax_array(value) | ||
elif name == "pair_excl" and value is not None: | ||
value = PairExcludeMask(value.ntypes, value.exclude_types) | ||
elif name == "atom_excl" and value is not None: | ||
value = AtomExcludeMask(value.ntypes, value.exclude_types) | ||
return 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
from typing import ( | ||
Any, | ||
) | ||
|
||
from deepmd.dpmodel.atomic_model.dp_atomic_model import DPAtomicModel as DPAtomicModelDP | ||
from deepmd.jax.atomic_model.base_atomic_model import ( | ||
base_atomic_model_set_attr, | ||
) | ||
from deepmd.jax.common import ( | ||
flax_module, | ||
) | ||
from deepmd.jax.descriptor.base_descriptor import ( | ||
BaseDescriptor, | ||
) | ||
from deepmd.jax.fitting.base_fitting import ( | ||
BaseFitting, | ||
) | ||
|
||
|
||
@flax_module | ||
class DPAtomicModel(DPAtomicModelDP): | ||
base_descriptor_cls = BaseDescriptor | ||
"""The base descriptor class.""" | ||
base_fitting_cls = BaseFitting | ||
"""The base fitting class.""" | ||
|
||
def __setattr__(self, name: str, value: Any) -> None: | ||
value = base_atomic_model_set_attr(name, 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,12 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
from deepmd.jax.descriptor.dpa1 import ( | ||
DescrptDPA1, | ||
) | ||
from deepmd.jax.descriptor.se_e2_a import ( | ||
DescrptSeA, | ||
) | ||
|
||
__all__ = [ | ||
"DescrptSeA", | ||
"DescrptDPA1", | ||
] |
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,9 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
from deepmd.dpmodel.descriptor.make_base_descriptor import ( | ||
make_base_descriptor, | ||
) | ||
from deepmd.jax.env import ( | ||
jnp, | ||
) | ||
|
||
BaseDescriptor = make_base_descriptor(jnp.ndarray) |
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 |
---|---|---|
@@ -1 +1,10 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
from deepmd.jax.fitting.fitting import ( | ||
DOSFittingNet, | ||
EnergyFittingNet, | ||
) | ||
|
||
__all__ = [ | ||
"EnergyFittingNet", | ||
"DOSFittingNet", | ||
] |
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,9 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
from deepmd.dpmodel.fitting.make_base_fitting import ( | ||
make_base_fitting, | ||
) | ||
from deepmd.jax.env import ( | ||
jnp, | ||
) | ||
|
||
BaseFitting = make_base_fitting(jnp.ndarray) |
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,6 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
from .ener_model import ( | ||
EnergyModel, | ||
) | ||
|
||
__all__ = ["EnergyModel"] |
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,6 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
from deepmd.dpmodel.model.base_model import ( | ||
make_base_model, | ||
) | ||
|
||
BaseModel = make_base_model() |
Oops, something went wrong.