Skip to content

Commit

Permalink
type safety
Browse files Browse the repository at this point in the history
  • Loading branch information
tjlane committed Oct 26, 2024
1 parent db429f4 commit 6df9b10
Show file tree
Hide file tree
Showing 5 changed files with 2,554 additions and 7 deletions.
4 changes: 2 additions & 2 deletions meteor/scripts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
"--structure",
type=Path,
required=True,
help="Specify CIF or PDB file path to compute phases from (usually a native model).",
help="Specify CIF or PDB file path, for phases (usually a native model). Required.",
)

self.add_argument(
Expand All @@ -136,7 +136,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
type=WeightMode,
default=WeightMode.optimize,
choices=list(WeightMode),
help="Choose the k-weighting behavior.",
help="How to pick the k-parameter. Optimize means max negentropy. Default: `optimize`.",
)

self.add_argument(
Expand Down
5 changes: 4 additions & 1 deletion meteor/scripts/compute_difference_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
type=WeightMode,
default=WeightMode.optimize,
choices=list(WeightMode),
help="Choose how to find a TV denoising regularization weight (lambda) parameter.",
help=(
"How to find a TV regularization weight (lambda). Optimize means pick maximum "
"negentropy. Default: `optimize`."
)

Check failure on line 39 in meteor/scripts/compute_difference_map.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (W291)

meteor/scripts/compute_difference_map.py:39:14: W291 Trailing whitespace
)
self.add_argument(
"-l",
Expand Down
4 changes: 2 additions & 2 deletions meteor/tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def json(self) -> dict:
json_payload.pop("negentropy_at_weights")
json_payload[self._scan_name] = [
{
self._weight_name: self.weights_scanned[idx],
self._negentropy_name: self.negentropy_at_weights[idx],
self._weight_name: float(self.weights_scanned[idx]),
self._negentropy_name: float(self.negentropy_at_weights[idx]),
}
for idx in range(len(self.weights_scanned))
]
Expand Down
5 changes: 3 additions & 2 deletions meteor/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def negentropy(samples: np.ndarray, tolerance: float = 0.1) -> float:
)
raise ValueError(msg)

return neg_e
return float(neg_e)


class ScalarMaximizer:
Expand Down Expand Up @@ -103,7 +103,7 @@ def _update_optima(self, argument_test_value: float) -> float:
if objective_value > self.objective_maximum:
self.argument_optimum = argument_test_value
self.objective_maximum = objective_value
return objective_value
return float(objective_value)

def optimize_over_explicit_values(
self, *, arguments_to_scan: Sequence[float] | np.ndarray
Expand All @@ -117,6 +117,7 @@ def optimize_over_explicit_values(
A list or array of argument values to evaluate.
"""
for argument_test_value in arguments_to_scan:
argument_test_value = float(argument_test_value)

Check failure on line 120 in meteor/validate.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (PLW2901)

meteor/validate.py:120:13: PLW2901 `for` loop variable `argument_test_value` overwritten by assignment target
objective_value = self._update_optima(argument_test_value)
self.values_evaluated.append(argument_test_value)
self.objective_at_values.append(objective_value)
Expand Down
Loading

0 comments on commit 6df9b10

Please sign in to comment.