Skip to content

Commit

Permalink
chore: replace reduciable with reducible (deepmodeling#3888)
Browse files Browse the repository at this point in the history
Fix the spelling as suggested by
deepmodeling#3867 (comment).

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Corrected typos in attribute names from `reduciable` to `reducible`
across multiple files, enhancing the accuracy of parameter definitions
and improving code consistency.

- **Tests**
- Updated test cases to reflect the corrected attribute names, ensuring
that tests accurately validate the new `reducible` parameter.

These changes improve the clarity and correctness of the codebase,
ensuring that attribute names are consistent and accurately reflect
their intended functionality.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: Jinzhe Zeng <[email protected]>
  • Loading branch information
njzjz authored and Mathieu Taillefumier committed Sep 18, 2024
1 parent 590fa03 commit c6fd5ca
Show file tree
Hide file tree
Showing 29 changed files with 85 additions and 85 deletions.
2 changes: 1 addition & 1 deletion deepmd/dpmodel/atomic_model/base_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def atomic_output_def(self) -> FittingOutputDef:
OutputVariableDef(
name="mask",
shape=[1],
reduciable=False,
reducible=False,
r_differentiable=False,
c_differentiable=False,
)
Expand Down
2 changes: 1 addition & 1 deletion deepmd/dpmodel/atomic_model/linear_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def fitting_output_def(self) -> FittingOutputDef:
OutputVariableDef(
name="energy",
shape=[1],
reduciable=True,
reducible=True,
r_differentiable=True,
c_differentiable=True,
)
Expand Down
2 changes: 1 addition & 1 deletion deepmd/dpmodel/atomic_model/pairtab_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def fitting_output_def(self) -> FittingOutputDef:
OutputVariableDef(
name="energy",
shape=[1],
reduciable=True,
reducible=True,
r_differentiable=True,
c_differentiable=True,
)
Expand Down
6 changes: 3 additions & 3 deletions deepmd/dpmodel/fitting/dipole_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ class DipoleFitting(GeneralFitting):
Atomic contributions of the excluded atom types are set zero.
r_differentiable
If the variable is differentiated with respect to coordinates of atoms.
Only reduciable variable are differentiable.
Only reducible variable are differentiable.
c_differentiable
If the variable is differentiated with respect to the cell tensor (pbc case).
Only reduciable variable are differentiable.
Only reducible variable are differentiable.
type_map: List[str], Optional
A list of strings. Give the name to each type of atoms.
"""
Expand Down Expand Up @@ -173,7 +173,7 @@ def output_def(self):
OutputVariableDef(
self.var_name,
[3],
reduciable=True,
reducible=True,
r_differentiable=self.r_differentiable,
c_differentiable=self.c_differentiable,
),
Expand Down
2 changes: 1 addition & 1 deletion deepmd/dpmodel/fitting/invar_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def output_def(self):
OutputVariableDef(
self.var_name,
[self.dim_out],
reduciable=True,
reducible=True,
r_differentiable=True,
c_differentiable=True,
),
Expand Down
2 changes: 1 addition & 1 deletion deepmd/dpmodel/fitting/polarizability_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def output_def(self):
OutputVariableDef(
"polarizability",
[3, 3],
reduciable=True,
reducible=True,
r_differentiable=False,
c_differentiable=False,
),
Expand Down
4 changes: 2 additions & 2 deletions deepmd/dpmodel/model/transform_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def fit_output_to_model_output(
vdef = fit_output_def[kk]
shap = vdef.shape
atom_axis = -(len(shap) + 1)
if vdef.reduciable:
if vdef.reducible:
kk_redu = get_reduce_name(kk)
# cast to energy prec brefore reduction
model_ret[kk_redu] = np.sum(
Expand Down Expand Up @@ -63,7 +63,7 @@ def communicate_extended_output(
vv = model_ret[kk]
vdef = model_output_def[kk]
new_ret[kk] = vv
if vdef.reduciable:
if vdef.reducible:
kk_redu = get_reduce_name(kk)
new_ret[kk_redu] = model_ret[kk_redu]
if vdef.r_differentiable:
Expand Down
36 changes: 18 additions & 18 deletions deepmd/dpmodel/output_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __call__(
for kk in self.md.keys_outp():
dd = self.md[kk]
check_var(ret[kk], dd)
if dd.reduciable:
if dd.reducible:
rk = get_reduce_name(kk)
check_var(ret[rk], self.md[rk])
if dd.r_differentiable:
Expand Down Expand Up @@ -166,15 +166,15 @@ class OutputVariableDef:
shape
The shape of the variable. e.g. energy should be [1],
dipole should be [3], polarizabilty should be [3,3].
reduciable
reducible
If the variable is reduced.
r_differentiable
If the variable is differentiated with respect to coordinates
of atoms. Only reduciable variable are differentiable.
of atoms. Only reducible variable are differentiable.
Negative derivative w.r.t. coordinates will be calcualted. (e.g. force)
c_differentiable
If the variable is differentiated with respect to the
cell tensor (pbc case). Only reduciable variable
cell tensor (pbc case). Only reducible variable
are differentiable.
Virial, the transposed negative gradient with cell tensor times
cell tensor, will be calculated, see eq 40 JCP 159, 054801 (2023).
Expand All @@ -192,7 +192,7 @@ def __init__(
self,
name: str,
shape: List[int],
reduciable: bool = False,
reducible: bool = False,
r_differentiable: bool = False,
c_differentiable: bool = False,
atomic: bool = True,
Expand All @@ -208,19 +208,19 @@ def __init__(
for i in range(len_shape):
self.output_size *= self.shape[i]
self.atomic = atomic
self.reduciable = reduciable
self.reducible = reducible
self.r_differentiable = r_differentiable
self.c_differentiable = c_differentiable
if self.c_differentiable and not self.r_differentiable:
raise ValueError("c differentiable requires r_differentiable")
if self.reduciable and not self.atomic:
raise ValueError("a reduciable variable should be atomic")
if self.reducible and not self.atomic:
raise ValueError("a reducible variable should be atomic")
self.category = category
self.r_hessian = r_hessian
self.magnetic = magnetic
if self.r_hessian:
if not self.reduciable:
raise ValueError("only reduciable variable can calculate hessian")
if not self.reducible:
raise ValueError("only reducible variable can calculate hessian")
if not self.r_differentiable:
raise ValueError("only r_differentiable variable can calculate hessian")

Expand Down Expand Up @@ -407,12 +407,12 @@ def do_reduce(
) -> Dict[str, OutputVariableDef]:
def_redu: Dict[str, OutputVariableDef] = {}
for kk, vv in def_outp_data.items():
if vv.reduciable:
if vv.reducible:
rk = get_reduce_name(kk)
def_redu[rk] = OutputVariableDef(
rk,
vv.shape,
reduciable=False,
reducible=False,
r_differentiable=False,
c_differentiable=False,
atomic=False,
Expand All @@ -429,7 +429,7 @@ def do_mask(
def_mask["mask"] = OutputVariableDef(
name="mask",
shape=[1],
reduciable=False,
reducible=False,
r_differentiable=False,
c_differentiable=False,
)
Expand All @@ -439,7 +439,7 @@ def do_mask(
def_mask["mask_mag"] = OutputVariableDef(
name="mask_mag",
shape=[1],
reduciable=False,
reducible=False,
r_differentiable=False,
c_differentiable=False,
)
Expand All @@ -458,7 +458,7 @@ def do_derivative(
def_derv_r[rkr] = OutputVariableDef(
rkr,
vv.shape + [3], # noqa: RUF005
reduciable=False,
reducible=False,
r_differentiable=(
vv.r_hessian and vv.category == OutputVariableCategory.OUT.value
),
Expand All @@ -470,7 +470,7 @@ def do_derivative(
def_derv_r[rkrm] = OutputVariableDef(
rkrm,
vv.shape + [3], # noqa: RUF005
reduciable=False,
reducible=False,
r_differentiable=(
vv.r_hessian and vv.category == OutputVariableCategory.OUT.value
),
Expand All @@ -485,7 +485,7 @@ def do_derivative(
def_derv_c[rkc] = OutputVariableDef(
rkc,
vv.shape + [9], # noqa: RUF005
reduciable=True,
reducible=True,
r_differentiable=False,
c_differentiable=False,
atomic=True,
Expand All @@ -495,7 +495,7 @@ def do_derivative(
def_derv_r[rkcm] = OutputVariableDef(
rkcm,
vv.shape + [9], # noqa: RUF005
reduciable=True,
reducible=True,
r_differentiable=False,
c_differentiable=False,
atomic=True,
Expand Down
2 changes: 1 addition & 1 deletion deepmd/infer/deep_dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def output_def(self) -> ModelOutputDef:
OutputVariableDef(
"dos",
shape=[-1],
reduciable=True,
reducible=True,
atomic=True,
),
]
Expand Down
2 changes: 1 addition & 1 deletion deepmd/infer/deep_polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def output_def(self) -> ModelOutputDef:
OutputVariableDef(
self.output_tensor_name,
shape=[-1],
reduciable=False,
reducible=False,
r_differentiable=False,
c_differentiable=False,
atomic=False,
Expand Down
4 changes: 2 additions & 2 deletions deepmd/infer/deep_pot.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def output_def(self) -> ModelOutputDef:
OutputVariableDef(
"energy",
shape=[1],
reduciable=True,
reducible=True,
r_differentiable=True,
c_differentiable=True,
atomic=True,
Expand All @@ -80,7 +80,7 @@ def output_def_mag(self) -> ModelOutputDef:
OutputVariableDef(
"energy",
shape=[1],
reduciable=True,
reducible=True,
r_differentiable=True,
c_differentiable=True,
atomic=True,
Expand Down
2 changes: 1 addition & 1 deletion deepmd/infer/deep_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def output_def(self) -> ModelOutputDef:
OutputVariableDef(
self.output_tensor_name,
shape=[-1],
reduciable=True,
reducible=True,
r_differentiable=True,
c_differentiable=True,
atomic=True,
Expand Down
4 changes: 2 additions & 2 deletions deepmd/infer/deep_wfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ def output_tensor_name(self) -> str:
@property
def output_def(self) -> ModelOutputDef:
"""Get the output definition of this model."""
# no reduciable or differentiable output is defined
# no reducible or differentiable output is defined
return ModelOutputDef(
FittingOutputDef(
[
OutputVariableDef(
self.output_tensor_name,
shape=[-1],
reduciable=False,
reducible=False,
r_differentiable=False,
c_differentiable=False,
atomic=True,
Expand Down
2 changes: 1 addition & 1 deletion deepmd/pt/model/atomic_model/base_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def atomic_output_def(self) -> FittingOutputDef:
OutputVariableDef(
name="mask",
shape=[1],
reduciable=False,
reducible=False,
r_differentiable=False,
c_differentiable=False,
)
Expand Down
2 changes: 1 addition & 1 deletion deepmd/pt/model/atomic_model/linear_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def fitting_output_def(self) -> FittingOutputDef:
OutputVariableDef(
name="energy",
shape=[1],
reduciable=True,
reducible=True,
r_differentiable=True,
c_differentiable=True,
)
Expand Down
2 changes: 1 addition & 1 deletion deepmd/pt/model/atomic_model/pairtab_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def fitting_output_def(self) -> FittingOutputDef:
OutputVariableDef(
name="energy",
shape=[1],
reduciable=True,
reducible=True,
r_differentiable=True,
c_differentiable=True,
)
Expand Down
4 changes: 2 additions & 2 deletions deepmd/pt/model/model/transform_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def fit_output_to_model_output(
vdef = fit_output_def[kk]
shap = vdef.shape
atom_axis = -(len(shap) + 1)
if vdef.reduciable:
if vdef.reducible:
kk_redu = get_reduce_name(kk)
model_ret[kk_redu] = torch.sum(vv.to(redu_prec), dim=atom_axis)
if vdef.r_differentiable:
Expand Down Expand Up @@ -196,7 +196,7 @@ def communicate_extended_output(
vv = model_ret[kk]
vdef = model_output_def[kk]
new_ret[kk] = vv
if vdef.reduciable:
if vdef.reducible:
kk_redu = get_reduce_name(kk)
new_ret[kk_redu] = model_ret[kk_redu]
# nf x nloc
Expand Down
4 changes: 2 additions & 2 deletions deepmd/pt/model/task/denoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ def output_def(self):
OutputVariableDef(
"updated_coord",
[3],
reduciable=False,
reducible=False,
r_differentiable=False,
c_differentiable=False,
),
OutputVariableDef(
"logits",
[-1],
reduciable=False,
reducible=False,
r_differentiable=False,
c_differentiable=False,
),
Expand Down
6 changes: 3 additions & 3 deletions deepmd/pt/model/task/dipole.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ class DipoleFittingNet(GeneralFitting):
Random seed.
r_differentiable
If the variable is differentiated with respect to coordinates of atoms.
Only reduciable variable are differentiable.
Only reducible variable are differentiable.
c_differentiable
If the variable is differentiated with respect to the cell tensor (pbc case).
Only reduciable variable are differentiable.
Only reducible variable are differentiable.
type_map: List[str], Optional
A list of strings. Give the name to each type of atoms.
"""
Expand Down Expand Up @@ -142,7 +142,7 @@ def output_def(self) -> FittingOutputDef:
OutputVariableDef(
self.var_name,
[3],
reduciable=True,
reducible=True,
r_differentiable=self.r_differentiable,
c_differentiable=self.c_differentiable,
),
Expand Down
2 changes: 1 addition & 1 deletion deepmd/pt/model/task/dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def output_def(self) -> FittingOutputDef:
OutputVariableDef(
self.var_name,
[self.dim_out],
reduciable=True,
reducible=True,
r_differentiable=False,
c_differentiable=False,
),
Expand Down
4 changes: 2 additions & 2 deletions deepmd/pt/model/task/ener.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ def output_def(self):
OutputVariableDef(
"energy",
[1],
reduciable=True,
reducible=True,
r_differentiable=False,
c_differentiable=False,
),
OutputVariableDef(
"dforce",
[3],
reduciable=False,
reducible=False,
r_differentiable=False,
c_differentiable=False,
),
Expand Down
2 changes: 1 addition & 1 deletion deepmd/pt/model/task/invar_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def output_def(self) -> FittingOutputDef:
OutputVariableDef(
self.var_name,
[self.dim_out],
reduciable=True,
reducible=True,
r_differentiable=True,
c_differentiable=True,
),
Expand Down
Loading

0 comments on commit c6fd5ca

Please sign in to comment.