Skip to content

Commit

Permalink
Consistently annotate Scheduler._timeout_hours as float | None (faceb…
Browse files Browse the repository at this point in the history
…ook#2951)

Summary:

Context:
* `Scheduler._timeout_hours`, `ScheduleOptions.timeout_hours`, and `timeout_hours` arguments are variously annotated as `int | None`, `float | None`, or `int | float | None`, even though ints and floats are both consistently supported.
* PEP 484 states that `float` is an acceptable annotation where `int | float` is accepted; an int can be treated as a subtype of a float for typing purposes.

Note: Before finding out that int can be considered a subtype of float, I tried to use the ABCs from `numbers` as a nicer way of annotating `int | float`, but then found out that `numbers.Real` does not support post-multiplication by an int, and floats are not covered by `numbers.Rational`, so that didn't work.


This PR:
* Changes all these annotations to `float | None`

Differential Revision: D64897260
  • Loading branch information
esantorella authored and facebook-github-bot committed Oct 24, 2024
1 parent 37441f7 commit e192620
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ax/service/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def run_n_trials(
self,
max_trials: int,
ignore_global_stopping_strategy: bool = False,
timeout_hours: int | None = None,
timeout_hours: float | None = None,
# pyre-fixme[2]: Parameter annotation cannot contain `Any`.
idle_callback: Callable[[Scheduler], Any] | None = None,
) -> OptimizationResult:
Expand Down Expand Up @@ -574,7 +574,7 @@ def run_n_trials(

def run_all_trials(
self,
timeout_hours: int | None = None,
timeout_hours: float | None = None,
# pyre-fixme[2]: Parameter annotation cannot contain `Any`.
idle_callback: Callable[[Scheduler], Any] | None = None,
) -> OptimizationResult:
Expand Down Expand Up @@ -658,7 +658,7 @@ def run_trials_and_yield_results(
self,
max_trials: int,
ignore_global_stopping_strategy: bool = False,
timeout_hours: int | float | None = None,
timeout_hours: float | None = None,
idle_callback: Callable[[Scheduler], None] | None = None,
) -> Generator[dict[str, Any], None, None]:
"""Make continuous calls to `run` and `process_results` to run up to
Expand Down

0 comments on commit e192620

Please sign in to comment.