Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace list[SupervisedDataset] hints with Sequence[SupervisedDataset] in Generator.fit & cross_validate #3413

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ax/models/torch/botorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from __future__ import annotations

import warnings
from collections.abc import Callable
from collections.abc import Callable, Sequence
from copy import deepcopy
from logging import Logger
from typing import Any, Optional
Expand Down Expand Up @@ -292,7 +292,7 @@ def __init__(
@copy_doc(TorchGenerator.fit)
def fit(
self,
datasets: list[SupervisedDataset],
datasets: Sequence[SupervisedDataset],
search_space_digest: SearchSpaceDigest,
candidate_metadata: list[list[TCandidateMetadata]] | None = None,
) -> None:
Expand Down Expand Up @@ -470,7 +470,7 @@ def best_point(
@copy_doc(TorchGenerator.cross_validate)
def cross_validate(
self,
datasets: list[SupervisedDataset],
datasets: Sequence[SupervisedDataset],
X_test: Tensor,
search_space_digest: SearchSpaceDigest,
use_posterior_predictive: bool = False,
Expand Down
3 changes: 2 additions & 1 deletion ax/models/torch/cbo_lcea.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# pyre-strict

from collections.abc import Sequence
from logging import Logger
from typing import Any, cast, Union

Expand Down Expand Up @@ -117,7 +118,7 @@ def __init__(
@copy_doc(TorchGenerator.fit)
def fit(
self,
datasets: list[SupervisedDataset],
datasets: Sequence[SupervisedDataset],
search_space_digest: SearchSpaceDigest,
candidate_metadata: list[list[TCandidateMetadata]] | None = None,
) -> None:
Expand Down
3 changes: 2 additions & 1 deletion ax/models/torch/cbo_sac.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# pyre-strict

from collections.abc import Sequence
from logging import Logger
from typing import Any

Expand Down Expand Up @@ -51,7 +52,7 @@ def __init__(self, decomposition: dict[str, list[str]]) -> None:
@copy_doc(TorchGenerator.fit)
def fit(
self,
datasets: list[SupervisedDataset],
datasets: Sequence[SupervisedDataset],
search_space_digest: SearchSpaceDigest,
candidate_metadata: list[list[TCandidateMetadata]] | None = None,
) -> None:
Expand Down
6 changes: 4 additions & 2 deletions ax/models/torch/randomforest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from __future__ import annotations

from collections.abc import Sequence

import numpy as np
import numpy.typing as npt
import torch
Expand Down Expand Up @@ -45,7 +47,7 @@ def __init__(self, max_features: str | None = "sqrt", num_trees: int = 500) -> N
@copy_doc(TorchGenerator.fit)
def fit(
self,
datasets: list[SupervisedDataset],
datasets: Sequence[SupervisedDataset],
search_space_digest: SearchSpaceDigest,
candidate_metadata: list[list[TCandidateMetadata]] | None = None,
) -> None:
Expand All @@ -68,7 +70,7 @@ def predict(self, X: Tensor) -> tuple[Tensor, Tensor]:
@copy_doc(TorchGenerator.cross_validate)
def cross_validate(
self,
datasets: list[SupervisedDataset],
datasets: Sequence[SupervisedDataset],
X_test: Tensor,
search_space_digest: SearchSpaceDigest,
use_posterior_predictive: bool = False,
Expand Down
4 changes: 2 additions & 2 deletions ax/models/torch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# pyre-strict

from collections.abc import Callable
from collections.abc import Callable, Sequence
from dataclasses import dataclass
from logging import Logger
from typing import Any, cast
Expand Down Expand Up @@ -586,7 +586,7 @@ def randomize_objective_weights(


def _datasets_to_legacy_inputs(
datasets: list[SupervisedDataset],
datasets: Sequence[SupervisedDataset],
) -> tuple[list[Tensor], list[Tensor], list[Tensor]]:
"""Convert a dictionary of dataset containers to legacy X, Y, Yvar inputs"""
Xs, Ys, Yvars = [], [], []
Expand Down
5 changes: 2 additions & 3 deletions ax/models/torch_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from __future__ import annotations

from collections.abc import Callable, Mapping, Sequence

from dataclasses import dataclass, field
from typing import Any

Expand Down Expand Up @@ -123,7 +122,7 @@ class TorchGenerator(BaseGenerator):

def fit(
self,
datasets: list[SupervisedDataset],
datasets: Sequence[SupervisedDataset],
search_space_digest: SearchSpaceDigest,
candidate_metadata: list[list[TCandidateMetadata]] | None = None,
) -> None:
Expand Down Expand Up @@ -199,7 +198,7 @@ def best_point(

def cross_validate(
self,
datasets: list[SupervisedDataset],
datasets: Sequence[SupervisedDataset],
X_test: Tensor,
search_space_digest: SearchSpaceDigest,
use_posterior_predictive: bool = False,
Expand Down