-
Notifications
You must be signed in to change notification settings - Fork 575
feat(jax): energy, dos, dipole, polar, property atomic model & model #4384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 deepmd.dpmodel.atomic_model.dipole_atomic_model import ( | ||
| DPDipoleAtomicModel as DPAtomicModelDipoleDP, | ||
| ) | ||
| from deepmd.jax.atomic_model.dp_atomic_model import ( | ||
| make_jax_dp_atomic_model_from_dpmodel, | ||
| ) | ||
|
|
||
|
|
||
| class DPAtomicModelDipole(make_jax_dp_atomic_model_from_dpmodel(DPAtomicModelDipoleDP)): | ||
| pass |
This file contains hidden or 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 deepmd.dpmodel.atomic_model.dos_atomic_model import ( | ||
| DPDOSAtomicModel as DPAtomicModelDOSDP, | ||
| ) | ||
| from deepmd.jax.atomic_model.dp_atomic_model import ( | ||
| make_jax_dp_atomic_model_from_dpmodel, | ||
| ) | ||
|
|
||
|
|
||
| class DPAtomicModelDOS(make_jax_dp_atomic_model_from_dpmodel(DPAtomicModelDOSDP)): | ||
| pass | ||
njzjz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or 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 hidden or 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 deepmd.dpmodel.atomic_model.energy_atomic_model import ( | ||
| DPEnergyAtomicModel as DPAtomicModelEnergyDP, | ||
| ) | ||
| from deepmd.jax.atomic_model.dp_atomic_model import ( | ||
| make_jax_dp_atomic_model_from_dpmodel, | ||
| ) | ||
|
|
||
|
|
||
| class DPAtomicModelEnergy(make_jax_dp_atomic_model_from_dpmodel(DPAtomicModelEnergyDP)): | ||
| pass | ||
njzjz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or 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 deepmd.dpmodel.atomic_model.polar_atomic_model import ( | ||
| DPPolarAtomicModel as DPAtomicModelPolarDP, | ||
| ) | ||
| from deepmd.jax.atomic_model.dp_atomic_model import ( | ||
| make_jax_dp_atomic_model_from_dpmodel, | ||
| ) | ||
|
|
||
|
|
||
| class DPAtomicModelPolar(make_jax_dp_atomic_model_from_dpmodel(DPAtomicModelPolarDP)): | ||
| pass |
This file contains hidden or 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,13 @@ | ||
| # SPDX-License-Identifier: LGPL-3.0-or-later | ||
| from deepmd.dpmodel.atomic_model.property_atomic_model import ( | ||
| DPPropertyAtomicModel as DPAtomicModelPropertyDP, | ||
| ) | ||
| from deepmd.jax.atomic_model.dp_atomic_model import ( | ||
| make_jax_dp_atomic_model_from_dpmodel, | ||
| ) | ||
|
|
||
|
|
||
| class DPAtomicModelProperty( | ||
| make_jax_dp_atomic_model_from_dpmodel(DPAtomicModelPropertyDP) | ||
| ): | ||
| pass |
This file contains hidden or 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,12 +1,28 @@ | ||
| # SPDX-License-Identifier: LGPL-3.0-or-later | ||
| from .dipole_model import ( | ||
| DipoleModel, | ||
| ) | ||
| from .dos_model import ( | ||
| DOSModel, | ||
| ) | ||
| from .dp_zbl_model import ( | ||
| DPZBLLinearEnergyAtomicModel, | ||
| ) | ||
| from .ener_model import ( | ||
| EnergyModel, | ||
| ) | ||
| from .polar_model import ( | ||
| PolarModel, | ||
| ) | ||
| from .property_model import ( | ||
| PropertyModel, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "EnergyModel", | ||
| "DPZBLLinearEnergyAtomicModel", | ||
| "DOSModel", | ||
| "DipoleModel", | ||
| "PolarModel", | ||
| "PropertyModel", | ||
| ] |
This file contains hidden or 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,17 @@ | ||
| # SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
|
||
| from deepmd.dpmodel.model.dipole_model import DipoleModel as DipoleModelDP | ||
| from deepmd.jax.atomic_model.dipole_atomic_model import ( | ||
| DPAtomicModelDipole, | ||
| ) | ||
| from deepmd.jax.model.base_model import ( | ||
| BaseModel, | ||
| ) | ||
| from deepmd.jax.model.dp_model import ( | ||
| make_jax_dp_model_from_dpmodel, | ||
| ) | ||
|
|
||
|
|
||
| @BaseModel.register("dipole") | ||
| class DipoleModel(make_jax_dp_model_from_dpmodel(DipoleModelDP, DPAtomicModelDipole)): | ||
| pass |
This file contains hidden or 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,16 @@ | ||
| # SPDX-License-Identifier: LGPL-3.0-or-later | ||
| from deepmd.dpmodel.model.dos_model import DOSModel as DOSModelDP | ||
| from deepmd.jax.atomic_model.dos_atomic_model import ( | ||
| DPAtomicModelDOS, | ||
| ) | ||
| from deepmd.jax.model.base_model import ( | ||
| BaseModel, | ||
| ) | ||
| from deepmd.jax.model.dp_model import ( | ||
| make_jax_dp_model_from_dpmodel, | ||
| ) | ||
|
|
||
|
|
||
| @BaseModel.register("dos") | ||
| class DOSModel(make_jax_dp_model_from_dpmodel(DOSModelDP, DPAtomicModelDOS)): | ||
| pass |
This file contains hidden or 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,86 @@ | ||
| # SPDX-License-Identifier: LGPL-3.0-or-later | ||
| from typing import ( | ||
| Any, | ||
| Optional, | ||
| ) | ||
|
|
||
| from deepmd.dpmodel.model import ( | ||
| DPModelCommon, | ||
| ) | ||
| from deepmd.jax.atomic_model.dp_atomic_model import ( | ||
| DPAtomicModel, | ||
| ) | ||
| from deepmd.jax.common import ( | ||
| flax_module, | ||
| ) | ||
| from deepmd.jax.env import ( | ||
| jax, | ||
| jnp, | ||
| ) | ||
| from deepmd.jax.model.base_model import ( | ||
| forward_common_atomic, | ||
| ) | ||
|
|
||
|
|
||
| def make_jax_dp_model_from_dpmodel( | ||
| dpmodel_model: type[DPModelCommon], jax_atomicmodel: type[DPAtomicModel] | ||
| ) -> type[DPModelCommon]: | ||
| """Make a JAX backend DP model from a DPModel backend DP model. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| dpmodel_model : type[DPModelCommon] | ||
| The DPModel backend DP model. | ||
| jax_atomicmodel : type[DPAtomicModel] | ||
| The JAX backend DP atomic model. | ||
|
|
||
| Returns | ||
| ------- | ||
| type[DPModelCommon] | ||
| The JAX backend DP model. | ||
| """ | ||
|
|
||
| @flax_module | ||
| class jax_model(dpmodel_model): | ||
| def __setattr__(self, name: str, value: Any) -> None: | ||
| if name == "atomic_model": | ||
| value = jax_atomicmodel.deserialize(value.serialize()) | ||
| return super().__setattr__(name, value) | ||
|
|
||
| def forward_common_atomic( | ||
| self, | ||
| extended_coord: jnp.ndarray, | ||
| extended_atype: jnp.ndarray, | ||
| nlist: jnp.ndarray, | ||
| mapping: Optional[jnp.ndarray] = None, | ||
| fparam: Optional[jnp.ndarray] = None, | ||
| aparam: Optional[jnp.ndarray] = None, | ||
| do_atomic_virial: bool = False, | ||
| ): | ||
| return forward_common_atomic( | ||
| self, | ||
| extended_coord, | ||
| extended_atype, | ||
| nlist, | ||
| mapping=mapping, | ||
| fparam=fparam, | ||
| aparam=aparam, | ||
| do_atomic_virial=do_atomic_virial, | ||
| ) | ||
|
|
||
| def format_nlist( | ||
| self, | ||
| extended_coord: jnp.ndarray, | ||
| extended_atype: jnp.ndarray, | ||
| nlist: jnp.ndarray, | ||
| extra_nlist_sort: bool = False, | ||
| ): | ||
| return dpmodel_model.format_nlist( | ||
| self, | ||
| jax.lax.stop_gradient(extended_coord), | ||
| extended_atype, | ||
| nlist, | ||
| extra_nlist_sort=extra_nlist_sort, | ||
| ) | ||
|
|
||
| return jax_model |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.