Skip to content

Commit 3c8e20d

Browse files
Lena Kashtelyanfacebook-github-bot
authored andcommitted
Deprecate nearly all internal SQA classes (now that legacy PTS is reaped) (#4200)
Summary: Pull Request resolved: #4200 Differential Revision: D80175881
1 parent 2336bb6 commit 3c8e20d

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

ax/adapter/tests/test_torch_adapter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,7 @@ def test_candidate_metadata_propagation(self) -> None:
483483
exp = get_branin_experiment(with_status_quo=True, with_completed_batch=True)
484484
# Check that the metadata is correctly re-added to observation
485485
# features during `fit`.
486-
# pyre-fixme[16]: `BaseTrial` has no attribute `_generator_run_structs`.
487-
preexisting_batch_gr = exp.trials[0]._generator_runs[0]
486+
preexisting_batch_gr = exp.trials[0].generator_runs[0]
488487
preexisting_batch_gr._candidate_metadata_by_arm_signature = {
489488
preexisting_batch_gr.arms[0].signature: {
490489
"preexisting_batch_cand_metadata": "some_value"

ax/storage/sqa_store/encoder.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,8 +1043,16 @@ def trial_to_sqa(
10431043
)
10441044
return trial_sqa
10451045

1046-
def experiment_data_to_sqa(self, experiment: Experiment) -> list[SQAData]:
1047-
"""Convert Ax experiment data to SQLAlchemy."""
1046+
def experiment_data_to_sqa(
1047+
self,
1048+
experiment: Experiment,
1049+
) -> list[SQAData]:
1050+
if (
1051+
experiment.experiment_type
1052+
in self.config.EXPERIMENT_TYPES_WITH_NO_DATA_STORAGE
1053+
):
1054+
return []
1055+
10481056
return [
10491057
self.data_to_sqa(data=data, trial_index=trial_index, timestamp=timestamp)
10501058
for trial_index, data_by_timestamp in experiment.data_by_trial.items()

ax/storage/sqa_store/sqa_config.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from collections.abc import Callable
1010
from dataclasses import dataclass, field
1111
from enum import Enum
12-
from typing import Any
12+
from typing import Any, cast
1313

1414
from ax.analysis.analysis import AnalysisCard
1515

@@ -67,9 +67,10 @@ class SQAConfig:
6767
serialization function.
6868
"""
6969

70+
EXPERIMENT_TYPES_WITH_NO_DATA_STORAGE: set[str] = field(default_factory=set)
71+
7072
def _default_class_to_sqa_class(self=None) -> dict[type[Base], type[SQABase]]:
71-
# pyre-fixme[7]
72-
return {
73+
ax_cls_to_sqa_cls = {
7374
AbandonedArm: SQAAbandonedArm,
7475
AnalysisCard: SQAAnalysisCard,
7576
Arm: SQAArm,
@@ -84,6 +85,10 @@ def _default_class_to_sqa_class(self=None) -> dict[type[Base], type[SQABase]]:
8485
Trial: SQATrial,
8586
AuxiliaryExperiment: SQAAuxiliaryExperiment,
8687
}
88+
return {
89+
cast(type[Base], k): cast(type[SQABase], v)
90+
for k, v in ax_cls_to_sqa_cls.items()
91+
}
8792

8893
class_to_sqa_class: dict[type[Base], type[SQABase]] = field(
8994
default_factory=_default_class_to_sqa_class
@@ -92,27 +97,21 @@ def _default_class_to_sqa_class(self=None) -> dict[type[Base], type[SQABase]]:
9297
generator_run_type_enum: Enum | type[Enum] | None = GeneratorRunType
9398
auxiliary_experiment_purpose_enum: type[Enum] = AuxiliaryExperimentPurpose
9499

95-
# pyre-fixme[4]: Attribute annotation cannot contain `Any`.
96-
# pyre-fixme[24]: Generic type `type` expects 1 type parameter, use
97-
# `typing.Type` to avoid runtime subscripting errors.
98-
json_encoder_registry: dict[type, Callable[[Any], dict[str, Any]]] = field(
100+
# Encoding and decoding registries:
101+
json_encoder_registry: dict[type[Any], Callable[[Any], dict[str, Any]]] = field(
99102
default_factory=lambda: CORE_ENCODER_REGISTRY
100103
)
101-
# pyre-fixme[4]: Attribute annotation cannot contain `Any`.
102-
# pyre-fixme[24]: Generic type `type` expects 1 type parameter, use
103-
# `typing.Type` to avoid runtime subscripting errors.
104-
json_class_encoder_registry: dict[type, Callable[[Any], dict[str, Any]]] = field(
105-
default_factory=lambda: CORE_CLASS_ENCODER_REGISTRY
104+
json_class_encoder_registry: dict[type[Any], Callable[[Any], dict[str, Any]]] = (
105+
field(default_factory=lambda: CORE_CLASS_ENCODER_REGISTRY)
106106
)
107-
108107
json_decoder_registry: TDecoderRegistry = field(
109108
default_factory=lambda: CORE_DECODER_REGISTRY
110109
)
111-
# pyre-fixme[4]: Attribute annotation cannot contain `Any`.
112110
json_class_decoder_registry: dict[str, Callable[[dict[str, Any]], Any]] = field(
113111
default_factory=lambda: CORE_CLASS_DECODER_REGISTRY
114112
)
115113

114+
# Metric and runner class registries:
116115
metric_registry: dict[type[Metric], int] = field(
117116
default_factory=lambda: CORE_METRIC_REGISTRY
118117
)

ax/storage/sqa_store/tests/test_sqa_store.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ def creator() -> Mock:
218218

219219
def test_GeneratorRunTypeValidation(self) -> None:
220220
experiment = get_experiment_with_batch_trial()
221-
# pyre-fixme[16]: `BaseTrial` has no attribute `generator_run_structs`.
222221
generator_run = experiment.trials[0].generator_runs[0]
223222
generator_run._generator_run_type = "foobar"
224223
with self.assertRaises(SQAEncodeError):

0 commit comments

Comments
 (0)