Skip to content

Commit

Permalink
Apply PEP585 (use native types for type annotations) (#2461)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #2461

PEP585 (implemented with Python 3.9) allows subscripting built-in and standard library types directly, to use them in typing annotations, rather than importing new classes from the typing module. This applies these changes throughout the codebase (excluding tutorials).

Reviewed By: esantorella

Differential Revision: D60967000

fbshipit-source-id: 66909aec9645b50c6c4b5d6050701878be630ed7
  • Loading branch information
Balandat authored and facebook-github-bot committed Aug 8, 2024
1 parent c1b73b8 commit 5ffa491
Show file tree
Hide file tree
Showing 133 changed files with 930 additions and 935 deletions.
10 changes: 5 additions & 5 deletions botorch/acquisition/analytic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from abc import ABC
from contextlib import nullcontext
from copy import deepcopy
from typing import Dict, Optional, Tuple, Union
from typing import Optional, Union

import torch
from botorch.acquisition.acquisition import AcquisitionFunction
Expand Down Expand Up @@ -83,7 +83,7 @@ def set_X_pending(self, X_pending: Optional[Tensor] = None) -> None:

def _mean_and_sigma(
self, X: Tensor, compute_sigma: bool = True, min_var: float = 1e-12
) -> Tuple[Tensor, Optional[Tensor]]:
) -> tuple[Tensor, Optional[Tensor]]:
"""Computes the first and second moments of the model posterior.
Args:
Expand Down Expand Up @@ -449,7 +449,7 @@ def __init__(
model: Model,
best_f: Union[float, Tensor],
objective_index: int,
constraints: Dict[int, Tuple[Optional[float], Optional[float]]],
constraints: dict[int, tuple[Optional[float], Optional[float]]],
maximize: bool = True,
) -> None:
r"""Analytic Log Constrained Expected Improvement.
Expand Down Expand Up @@ -527,7 +527,7 @@ def __init__(
model: Model,
best_f: Union[float, Tensor],
objective_index: int,
constraints: Dict[int, Tuple[Optional[float], Optional[float]]],
constraints: dict[int, tuple[Optional[float], Optional[float]]],
maximize: bool = True,
) -> None:
r"""Analytic Constrained Expected Improvement.
Expand Down Expand Up @@ -1134,7 +1134,7 @@ def _get_noiseless_fantasy_model(

def _preprocess_constraint_bounds(
acqf: Union[LogConstrainedExpectedImprovement, ConstrainedExpectedImprovement],
constraints: Dict[int, Tuple[Optional[float], Optional[float]]],
constraints: dict[int, tuple[Optional[float], Optional[float]]],
) -> None:
r"""Set up constraint bounds.
Expand Down
6 changes: 3 additions & 3 deletions botorch/acquisition/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from __future__ import annotations

from typing import Callable, List, Optional, Union
from typing import Callable, Optional, Union

import torch

Expand All @@ -37,7 +37,7 @@ def get_acquisition_function(
X_observed: Tensor,
posterior_transform: Optional[PosteriorTransform] = None,
X_pending: Optional[Tensor] = None,
constraints: Optional[List[Callable[[Tensor], Tensor]]] = None,
constraints: Optional[list[Callable[[Tensor], Tensor]]] = None,
eta: Optional[Union[Tensor, float]] = 1e-3,
mc_samples: int = 512,
seed: Optional[int] = None,
Expand All @@ -48,7 +48,7 @@ def get_acquisition_function(
marginalize_dim: Optional[int] = None,
cache_root: bool = True,
beta: Optional[float] = None,
ref_point: Union[None, List[float], Tensor] = None,
ref_point: Union[None, list[float], Tensor] = None,
Y: Optional[Tensor] = None,
alpha: float = 0.0,
) -> monte_carlo.MCAcquisitionFunction:
Expand Down
6 changes: 4 additions & 2 deletions botorch/acquisition/fixed_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

from __future__ import annotations

from collections.abc import Sequence

from numbers import Number
from typing import List, Optional, Sequence, Union
from typing import Optional, Union

import torch
from botorch.acquisition.acquisition import AcquisitionFunction
Expand Down Expand Up @@ -65,7 +67,7 @@ def __init__(
self,
acq_function: AcquisitionFunction,
d: int,
columns: List[int],
columns: list[int],
values: Union[Tensor, Sequence[Union[Tensor, float]]],
) -> None:
r"""Derived Acquisition Function by fixing a subset of input features.
Expand Down
Loading

0 comments on commit 5ffa491

Please sign in to comment.