Skip to content

Commit

Permalink
Use types.NoneType rather than defining NoneType in BoTorch (#2338)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #2338

- Rremove BoTorch `NoneType` and replace its usages with `types.NoneType`, since as of Python 3.10, types.NoneType (once again) exists.
- Use `None` or `Optional` for the purposes of type-hinting (and only for type-hinting) in place of `NoneType` since they are equivalent for type-hinting, although not in general.

Reviewed By: saitcakmak

Differential Revision: D57172472

fbshipit-source-id: b5be445caaf738ac8e227bd6595031c66f22d85e
  • Loading branch information
esantorella authored and facebook-github-bot committed May 10, 2024
1 parent 20db4d5 commit e2d90ac
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion botorch/optim/closures/model_closures.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
from __future__ import annotations

from itertools import chain, repeat
from types import NoneType
from typing import Any, Callable, Dict, Optional, Sequence, Tuple

from botorch.optim.closures.core import ForwardBackwardClosure
from botorch.utils.dispatcher import Dispatcher, type_bypassing_encoder
from botorch.utils.types import NoneType
from gpytorch.mlls import (
ExactMarginalLogLikelihood,
MarginalLogLikelihood,
Expand Down
3 changes: 1 addition & 2 deletions botorch/optim/utils/numpy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import numpy as np
import torch
from botorch.utils.types import NoneType
from numpy import ndarray
from torch import Tensor

Expand Down Expand Up @@ -137,7 +136,7 @@ def set_tensors_from_ndarray_1d(
def get_bounds_as_ndarray(
parameters: Dict[str, Tensor],
bounds: Dict[
str, Tuple[Union[float, Tensor, NoneType], Union[float, Tensor, NoneType]]
str, Tuple[Optional[Union[float, Tensor]], Optional[Union[float, Tensor]]]
],
) -> Optional[np.ndarray]:
r"""Helper method for converting bounds into an ndarray.
Expand Down
4 changes: 3 additions & 1 deletion botorch/sampling/pathwise/update_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from __future__ import annotations

from types import NoneType

from typing import Any, Callable, Optional, Union

import torch
Expand All @@ -20,7 +22,7 @@
TInputTransform,
)
from botorch.utils.dispatcher import Dispatcher
from botorch.utils.types import DEFAULT, NoneType
from botorch.utils.types import DEFAULT
from gpytorch.kernels.kernel import Kernel
from gpytorch.likelihoods import _GaussianLikelihoodBase, Likelihood
from gpytorch.models import ApproximateGP, ExactGP, GP
Expand Down
3 changes: 0 additions & 3 deletions botorch/utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
from __future__ import annotations


NoneType = type(None) # stop gap for the return of NoneType in 3.10


class _DefaultType(type):
r"""
Private class whose sole instance `DEFAULT` is as a special indicator
Expand Down

0 comments on commit e2d90ac

Please sign in to comment.