Skip to content

Commit 8358e8a

Browse files
lyskovlyskov-ai
andcommitted
Bring rfd3 2-error-tier modules under strict mypy
Second models/rfd3 direction-(b) slice. Clears the five modules with two untyped-def errors each (model.RFD3, model.cfg_utils, transforms.ncaa_transforms, transforms.ppi_transforms, utils.io) with honest annotations verified against bodies, call sites, and sibling conventions. Tightening strip_X's f_stripped param to dict[str, torch.Tensor] surfaced a real arg-type at its sole caller in model.inference_sampler; resolved with a parallel 'assert f_ref is not None' in the CFG branch (which already asserts the sibling ref_initializer_outputs). Annotation-only otherwise; 527 strict errors across 43 modules remain. Co-authored-by: lyskov-ai <277346777+lyskov-ai@users.noreply.github.com>
1 parent af1a5d2 commit 8358e8a

7 files changed

Lines changed: 25 additions & 15 deletions

File tree

models/rfd3/src/rfd3/model/RFD3.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from typing import Any
23

34
import hydra
45
import torch
@@ -36,7 +37,7 @@ def __init__(
3637
token_initializer: DictConfig | dict,
3738
diffusion_module: DictConfig | dict,
3839
inference_sampler: DictConfig | dict,
39-
**_,
40+
**_: Any,
4041
):
4142
super().__init__()
4243
# Check for chunked P_LL mode via environment variable
@@ -74,8 +75,8 @@ def forward(
7475
self,
7576
input: dict,
7677
coord_atom_lvl_to_be_noised: torch.Tensor | None = None,
77-
n_cycle=None,
78-
**_,
78+
n_cycle: int | None = None,
79+
**_: Any,
7980
) -> dict:
8081
initializer_outputs = self.token_initializer(input["f"])
8182

models/rfd3/src/rfd3/model/cfg_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33

44
def strip_f(
5-
f,
6-
cfg_features,
7-
):
5+
f: dict[str, torch.Tensor],
6+
cfg_features: list[str],
7+
) -> dict[str, torch.Tensor]:
88
"""
99
Strips conditioning features from 'f' for classifier-free guidance.
1010
@@ -67,7 +67,7 @@ def strip_f(
6767
return f_stripped
6868

6969

70-
def strip_X(X_L, f_stripped):
70+
def strip_X(X_L: torch.Tensor, f_stripped: dict[str, torch.Tensor]) -> torch.Tensor:
7171
"""
7272
Strips X_L unindexed atoms from X_L
7373

models/rfd3/src/rfd3/model/inference_sampler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,10 @@ def sample_diffusion_like_af3(
278278
if self.use_classifier_free_guidance and (
279279
self.cfg_t_max is None or c_t > self.cfg_t_max
280280
):
281-
# CFG mode requires the reference (unconditional) initializer outputs.
281+
# CFG mode requires the reference (unconditional) features and
282+
# initializer outputs; RFD3.forward provides both only when CFG is on.
282283
assert ref_initializer_outputs is not None
284+
assert f_ref is not None
283285
X_noisy_L_stripped = strip_X(X_noisy_L, f_ref)
284286

285287
# unconditional forward pass

models/rfd3/src/rfd3/transforms/ncaa_transforms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class AddIsDAminoAcidFeat(Transform):
111111
Adds an annotation to the atom array indicating whether each residue is a D-amino acid.
112112
"""
113113

114-
def check_input(self, data) -> None:
114+
def check_input(self, data: dict) -> None:
115115
check_contains_keys(data, ["atom_array", "feats"])
116116

117117
def forward(self, data: dict) -> dict:
@@ -144,7 +144,7 @@ def forward(self, data: dict) -> dict:
144144

145145

146146
class StrtoBoolforIsDAminoAcidFeature(Transform):
147-
def forward(self, data):
147+
def forward(self, data: dict) -> dict:
148148
atom_array = data["atom_array"]
149149
convert_existing_annotations_to_bool(
150150
atom_array, annotations=["is_d_amino_acid"]

models/rfd3/src/rfd3/transforms/ppi_transforms.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
# Future hotspot subsampling schemes might want to avoid giving redundant information via (say) bonded atoms
4242

4343

44-
def get_hotspot_atoms(atom_array, binder_pn_unit_iid, distance_cutoff=4.5):
44+
def get_hotspot_atoms(
45+
atom_array: AtomArray, binder_pn_unit_iid: str, distance_cutoff: float = 4.5
46+
) -> np.ndarray:
4547
"""Get hotspot atoms for a given distance cutoff.
4648
4749
Args:
@@ -335,7 +337,7 @@ def __init__(
335337
self.force_crop = force_crop
336338
self.max_atoms_in_crop = max_atoms_in_crop
337339

338-
def check_input(self, data: dict):
340+
def check_input(self, data: dict) -> None:
339341
check_contains_keys(data, ["atom_array"])
340342
check_is_instance(data, "atom_array", AtomArray)
341343
check_atom_array_annotation(data, ["pn_unit_iid", "atomize", "atom_id"])

models/rfd3/src/rfd3/utils/io.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import numpy as np
77
import torch
88
from atomworks.io.utils.io_utils import to_cif_file
9-
from beartype.typing import Callable, Literal, cast
9+
from beartype.typing import Any, Callable, Literal, cast
1010
from biotite.structure import AtomArray, AtomArrayStack, stack
1111

1212
from foundry.utils.alignment import weighted_rigid_align
@@ -20,7 +20,7 @@ def dump_structures(
2020
base_path: PathLike,
2121
one_model_per_file: bool,
2222
extra_fields: list[str] | Literal["all"] = [],
23-
**kwargs,
23+
**kwargs: Any,
2424
) -> None:
2525
"""Dump structures to CIF files, given the coordinates and input AtomArray.
2626
@@ -64,7 +64,7 @@ def dump_metadata(
6464
prediction_metadata: dict,
6565
base_path: PathLike,
6666
one_model_per_file: bool,
67-
):
67+
) -> None:
6868
"""
6969
Dump JSONs of prediction metadata to disk.
7070

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ module = [
282282
"rfd3.model.layers.chunked_pairwise",
283283
"rfd3.trainer.rfd3",
284284
"rfd3.utils.vizualize",
285+
"rfd3.model.RFD3",
286+
"rfd3.model.cfg_utils",
287+
"rfd3.transforms.ncaa_transforms",
288+
"rfd3.transforms.ppi_transforms",
289+
"rfd3.utils.io",
285290
]
286291
disallow_untyped_defs = true
287292
check_untyped_defs = true

0 commit comments

Comments
 (0)