Skip to content

Commit

Permalink
Resolve unsoundness caught by pytype --strict-none-binding.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 705638467
  • Loading branch information
vizier-team authored and copybara-github committed Dec 16, 2024
1 parent 1fc8537 commit 3427c3b
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class EagleStrategyUtils:
_n_parameters: int = attr.field(init=False)
_degrees_of_freedom: DefaultDict[vz.ParameterType, int] = attr.field(
init=False, factory=lambda: collections.defaultdict(int))
_original_metric_name: str = attr.field(init=False)
_original_metric_name: Optional[str] = attr.field(init=False)
_goal: vz.ObjectiveMetricGoal = attr.field(init=False)

def __attrs_post_init__(self):
Expand Down Expand Up @@ -359,6 +359,8 @@ def get_metric(self, trial: vz.Trial) -> float:
"""Returns the trial metric."""
if trial.infeasible:
return np.nan
if trial.final_measurement is None:
raise ValueError('Trial is not completed.')
return trial.final_measurement.metrics[OBJECTIVE_NAME] # pytype: disable=bad-return-type

def is_better_than(
Expand Down Expand Up @@ -408,6 +410,8 @@ def standardize_trial_metric_name(self, trial: vz.Trial) -> vz.Trial:
"""Creates a new trial with canonical metric name."""
if trial.infeasible:
return trial
if trial.final_measurement is None:
raise ValueError('Trial is not completed.')
value = trial.final_measurement.metrics[self._original_metric_name].value
new_trial = vz.Trial(parameters=trial.parameters, metadata=trial.metadata)
new_trial.complete(
Expand Down

0 comments on commit 3427c3b

Please sign in to comment.