diff --git a/ax/analysis/old/helpers/cross_validation_helpers.py b/ax/analysis/old/helpers/cross_validation_helpers.py index a40bd358586..c8d9328c8e5 100644 --- a/ax/analysis/old/helpers/cross_validation_helpers.py +++ b/ax/analysis/old/helpers/cross_validation_helpers.py @@ -78,7 +78,6 @@ def cv_results_to_df( records = [] for i in range(len(arm_names)): - records.append( { "arm_name": arm_names[i], diff --git a/ax/analysis/old/helpers/tests/test_cross_validation_helpers.py b/ax/analysis/old/helpers/tests/test_cross_validation_helpers.py index c3de7a59679..3b615aa2ae0 100644 --- a/ax/analysis/old/helpers/tests/test_cross_validation_helpers.py +++ b/ax/analysis/old/helpers/tests/test_cross_validation_helpers.py @@ -60,7 +60,6 @@ def test_get_min_max_with_errors(self) -> None: self.assertAlmostEqual(max_, expected_max, delta=1e-4) def test_obs_vs_pred_dropdown_plot(self) -> None: - cross_validation_plot = CrossValidationPlot( experiment=self.exp, model=self.model ) diff --git a/ax/analysis/old/helpers/tests/test_cv_consistency_checks.py b/ax/analysis/old/helpers/tests/test_cv_consistency_checks.py index 91d71a2ff5d..d36b4c8ab9d 100644 --- a/ax/analysis/old/helpers/tests/test_cv_consistency_checks.py +++ b/ax/analysis/old/helpers/tests/test_cv_consistency_checks.py @@ -109,7 +109,6 @@ def test_error_scatter_trace_branin(self) -> None: self.assertEqual(result_analysis, result_plot) def test_obs_vs_pred_dropdown_plot_branin(self) -> None: - label_dict = {"branin": "BrAnIn"} cross_validation_plot = CrossValidationPlot( diff --git a/ax/analysis/old/tests/test_analysis_report.py b/ax/analysis/old/tests/test_analysis_report.py index fcd7c9efb0e..919baf8aaa6 100644 --- a/ax/analysis/old/tests/test_analysis_report.py +++ b/ax/analysis/old/tests/test_analysis_report.py @@ -22,7 +22,6 @@ class TestCrossValidationPlot(TestCase): - class TestAnalysis(BaseAnalysis): def get_df(self) -> pd.DataFrame: return pd.DataFrame() diff --git a/ax/analysis/plotly/parallel_coordinates.py b/ax/analysis/plotly/parallel_coordinates.py index 1c66f657392..a861ebf6685 100644 --- a/ax/analysis/plotly/parallel_coordinates.py +++ b/ax/analysis/plotly/parallel_coordinates.py @@ -85,7 +85,6 @@ def _prepare_data(experiment: Experiment, metric: str) -> pd.DataFrame: def _prepare_plot(df: pd.DataFrame, metric_name: str) -> go.Figure: - # ParCoords requires that the dimensions are specified on continuous scales, so # ChoiceParameters and FixedParameters must be preprocessed to allow for # appropriate plotting. diff --git a/ax/analysis/plotly/tests/test_insample_effects.py b/ax/analysis/plotly/tests/test_insample_effects.py index 25fa6de3702..48562a9588a 100644 --- a/ax/analysis/plotly/tests/test_insample_effects.py +++ b/ax/analysis/plotly/tests/test_insample_effects.py @@ -29,7 +29,6 @@ class TestInsampleEffectsPlot(TestCase): - def setUp(self) -> None: super().setUp() self.generation_strategy = GenerationStrategy( @@ -93,9 +92,7 @@ def test_compute_uses_gs_model_if_possible(self) -> None: ) ).set_status_quo_with_weight( status_quo=experiment.status_quo, weight=1.0 - ).mark_completed( - unsafe=True - ) + ).mark_completed(unsafe=True) experiment.fetch_data() generation_strategy.gen_with_multiple_nodes(experiment=experiment, n=10) # Ensure the current model is Botorch @@ -323,9 +320,7 @@ def test_compute_requires_data_for_the_metric_on_the_trial_with_a_model( ) ).set_status_quo_with_weight( status_quo=experiment.status_quo, weight=1.0 - ).mark_completed( - unsafe=True - ) + ).mark_completed(unsafe=True) experiment.fetch_data() # AND GIVEN the experiment has a trial with no data empty_trial = experiment.new_batch_trial( diff --git a/ax/analysis/plotly/tests/test_predicted_effects.py b/ax/analysis/plotly/tests/test_predicted_effects.py index b63d0677a8a..2a9d72fa7d7 100644 --- a/ax/analysis/plotly/tests/test_predicted_effects.py +++ b/ax/analysis/plotly/tests/test_predicted_effects.py @@ -131,9 +131,7 @@ def test_compute(self) -> None: ) ).set_status_quo_with_weight( status_quo=experiment.status_quo, weight=1.0 - ).mark_completed( - unsafe=True - ) + ).mark_completed(unsafe=True) experiment.fetch_data() experiment.new_batch_trial( generator_runs=generation_strategy.gen_with_multiple_nodes( @@ -200,17 +198,13 @@ def test_compute_multitask(self) -> None: generator_run=generation_strategy.gen(experiment=experiment, n=10) ).set_status_quo_with_weight( status_quo=experiment.status_quo, weight=1 - ).mark_completed( - unsafe=True - ) + ).mark_completed(unsafe=True) experiment.fetch_data() experiment.new_batch_trial( generator_run=generation_strategy.gen(experiment=experiment, n=10) ).set_status_quo_with_weight( status_quo=experiment.status_quo, weight=1 - ).mark_completed( - unsafe=True - ) + ).mark_completed(unsafe=True) experiment.fetch_data() # leave as a candidate experiment.new_batch_trial( diff --git a/ax/analysis/plotly/utils.py b/ax/analysis/plotly/utils.py index 5d37a1fdd78..5cd3377095b 100644 --- a/ax/analysis/plotly/utils.py +++ b/ax/analysis/plotly/utils.py @@ -95,7 +95,7 @@ def get_constraint_violated_probabilities( def format_constraint_violated_probabilities( - constraints_violated: dict[str, float] + constraints_violated: dict[str, float], ) -> str: """Format the constraints violated for the tooltip.""" max_metric_length = 70 diff --git a/ax/benchmark/benchmark_problem.py b/ax/benchmark/benchmark_problem.py index b3cd547115a..bf720aa385b 100644 --- a/ax/benchmark/benchmark_problem.py +++ b/ax/benchmark/benchmark_problem.py @@ -217,7 +217,6 @@ def get_soo_config_and_outcome_names( observe_noise_sd: bool, objective_name: str, ) -> tuple[OptimizationConfig, list[str]]: - objective = Objective( metric=BenchmarkMetric( name=objective_name, diff --git a/ax/benchmark/problems/registry.py b/ax/benchmark/problems/registry.py index 4e70723e186..d833da74354 100644 --- a/ax/benchmark/problems/registry.py +++ b/ax/benchmark/problems/registry.py @@ -239,7 +239,7 @@ class BenchmarkProblemRegistryEntry: def get_problem( problem_key: str, registry: Mapping[str, BenchmarkProblemRegistryEntry] | None = None, - **additional_kwargs: Any + **additional_kwargs: Any, ) -> BenchmarkProblem: """ Generate a benchmark problem from a key, registry, and additional arguments. diff --git a/ax/benchmark/runners/base.py b/ax/benchmark/runners/base.py index 6666260c7ac..dfd55e814e1 100644 --- a/ax/benchmark/runners/base.py +++ b/ax/benchmark/runners/base.py @@ -47,7 +47,7 @@ def __init__( self, *, outcome_names: list[str], - search_space_digest: SearchSpaceDigest | None = None + search_space_digest: SearchSpaceDigest | None = None, ) -> None: """ Args: diff --git a/ax/benchmark/runners/surrogate.py b/ax/benchmark/runners/surrogate.py index 3a602e11289..d864706efed 100644 --- a/ax/benchmark/runners/surrogate.py +++ b/ax/benchmark/runners/surrogate.py @@ -32,9 +32,8 @@ def __init__( surrogate: TorchModelBridge | None = None, datasets: list[SupervisedDataset] | None = None, noise_stds: float | dict[str, float] = 0.0, - get_surrogate_and_datasets: None | ( - Callable[[], tuple[TorchModelBridge, list[SupervisedDataset]]] - ) = None, + get_surrogate_and_datasets: None + | (Callable[[], tuple[TorchModelBridge, list[SupervisedDataset]]]) = None, search_space_digest: SearchSpaceDigest | None = None, ) -> None: """Runner for surrogate benchmark problems. diff --git a/ax/benchmark/tests/problems/hpo/test_torchvision.py b/ax/benchmark/tests/problems/hpo/test_torchvision.py index 21b46249654..dcb4c124b61 100644 --- a/ax/benchmark/tests/problems/hpo/test_torchvision.py +++ b/ax/benchmark/tests/problems/hpo/test_torchvision.py @@ -36,7 +36,6 @@ def test_problem_properties(self) -> None: "ax.benchmark.problems.hpo.torchvision._REGISTRY", {"MNIST": TestDataset, "FashionMNIST": TestDataset}, ): - self.assertEqual( get_problem(problem_key="hpo_pytorch_cnn_MNIST").name, "HPO_PyTorchCNN_Torchvision::MNIST", diff --git a/ax/benchmark/tests/problems/synthetic/hss/test_jenatton.py b/ax/benchmark/tests/problems/synthetic/hss/test_jenatton.py index 0bd3863bc66..2ef8e71eed9 100644 --- a/ax/benchmark/tests/problems/synthetic/hss/test_jenatton.py +++ b/ax/benchmark/tests/problems/synthetic/hss/test_jenatton.py @@ -25,7 +25,6 @@ class JenattonTest(TestCase): - def test_jenatton_test_function(self) -> None: benchmark_problem = get_jenatton_benchmark_problem() diff --git a/ax/benchmark/tests/problems/test_mixed_integer_problems.py b/ax/benchmark/tests/problems/test_mixed_integer_problems.py index 975f775df73..4000fde134b 100644 --- a/ax/benchmark/tests/problems/test_mixed_integer_problems.py +++ b/ax/benchmark/tests/problems/test_mixed_integer_problems.py @@ -103,7 +103,6 @@ def test_problems(self) -> None: ] for problem, params, expected_arg in cases: - runner = checked_cast(BotorchTestProblemRunner, problem.runner) trial = Trial(experiment=MagicMock()) # pyre-fixme: Incompatible parameter type [6]: In call diff --git a/ax/benchmark/tests/problems/test_problems.py b/ax/benchmark/tests/problems/test_problems.py index fd34e37939d..dcc83584644 100644 --- a/ax/benchmark/tests/problems/test_problems.py +++ b/ax/benchmark/tests/problems/test_problems.py @@ -11,7 +11,6 @@ class TestProblems(TestCase): def test_load_problems(self) -> None: - # Make sure problem construction succeeds for name in BENCHMARK_PROBLEM_REGISTRY.keys(): if "MNIST" in name: diff --git a/ax/benchmark/tests/runners/test_botorch_test_problem.py b/ax/benchmark/tests/runners/test_botorch_test_problem.py index 6b3b5b9fe8f..aa9cb983b06 100644 --- a/ax/benchmark/tests/runners/test_botorch_test_problem.py +++ b/ax/benchmark/tests/runners/test_botorch_test_problem.py @@ -61,9 +61,7 @@ def test_synthetic_runner(self) -> None: test_problem_kwargs, modified_bounds, noise_std, - ) in ( - botorch_cases + param_based_cases - ): + ) in botorch_cases + param_based_cases: if noise_std is not None: # pyre-fixme[6]: Incompatible parameter type: Expected int, got float test_problem_kwargs["noise_std"] = noise_std diff --git a/ax/benchmark/tests/runners/test_surrogate_runner.py b/ax/benchmark/tests/runners/test_surrogate_runner.py index b7a1decca7e..5c84c471e85 100644 --- a/ax/benchmark/tests/runners/test_surrogate_runner.py +++ b/ax/benchmark/tests/runners/test_surrogate_runner.py @@ -84,7 +84,6 @@ def test_instantiation_raises_with_missing_args(self) -> None: ) def test_equality(self) -> None: - def _construct_runner(name: str) -> SurrogateRunner: return SurrogateRunner( name=name, diff --git a/ax/benchmark/tests/test_benchmark_metric.py b/ax/benchmark/tests/test_benchmark_metric.py index ed0dd34fb42..136e15f5681 100644 --- a/ax/benchmark/tests/test_benchmark_metric.py +++ b/ax/benchmark/tests/test_benchmark_metric.py @@ -47,7 +47,6 @@ def get_test_batch_trial() -> BatchTrial: class BenchmarkMetricTest(TestCase): - def test_fetch_trial_data(self) -> None: metric1 = BenchmarkMetric(name="test_metric1", lower_is_better=True) metric2 = BenchmarkMetric(name="test_metric2", lower_is_better=True) diff --git a/ax/core/experiment.py b/ax/core/experiment.py index 1ce3c730857..856f5e59032 100644 --- a/ax/core/experiment.py +++ b/ax/core/experiment.py @@ -86,9 +86,8 @@ def __init__( experiment_type: str | None = None, properties: dict[str, Any] | None = None, default_data_type: DataType | None = None, - auxiliary_experiments_by_purpose: None | ( - dict[AuxiliaryExperimentPurpose, list[AuxiliaryExperiment]] - ) = None, + auxiliary_experiments_by_purpose: None + | (dict[AuxiliaryExperimentPurpose, list[AuxiliaryExperiment]]) = None, ) -> None: """Inits Experiment. @@ -141,7 +140,7 @@ def __init__( self.auxiliary_experiments_by_purpose: dict[ AuxiliaryExperimentPurpose, list[AuxiliaryExperiment] - ] = (auxiliary_experiments_by_purpose or {}) + ] = auxiliary_experiments_by_purpose or {} self.add_tracking_metrics(tracking_metrics or []) @@ -852,9 +851,7 @@ def _get_last_data_without_similar_rows( last_data_type = type(last_data) merge_keys = ["trial_index", "metric_name", "arm_name"] + ( # pyre-ignore[16] - last_data.map_keys - if issubclass(last_data_type, MapData) - else [] + last_data.map_keys if issubclass(last_data_type, MapData) else [] ) # this merge is like a SQL left join on merge keys # it will return a dataframe with the columns in merge_keys @@ -1742,14 +1739,14 @@ def metric_config_summary_df(self) -> pd.DataFrame: for constraint in opt_config.all_constraints: if not isinstance(constraint, ObjectiveThreshold): - records[constraint.metric.name][ - METRIC_DF_COLNAMES["goal"] - ] = "constrain" + records[constraint.metric.name][METRIC_DF_COLNAMES["goal"]] = ( + "constrain" + ) op = ">= " if constraint.op == ComparisonOp.GEQ else "<= " relative = "%" if constraint.relative else "" - records[constraint.metric.name][ - METRIC_DF_COLNAMES["bound"] - ] = f"{op}{constraint.bound}{relative}" + records[constraint.metric.name][METRIC_DF_COLNAMES["bound"]] = ( + f"{op}{constraint.bound}{relative}" + ) for metric in self.tracking_metrics or []: records[metric.name][METRIC_DF_COLNAMES["goal"]] = "track" diff --git a/ax/core/generator_run.py b/ax/core/generator_run.py index ef9d8de838e..ed08febbdbf 100644 --- a/ax/core/generator_run.py +++ b/ax/core/generator_run.py @@ -103,9 +103,8 @@ def __init__( gen_metadata: TGenMetadata | None = None, model_state_after_gen: dict[str, Any] | None = None, generation_step_index: int | None = None, - candidate_metadata_by_arm_signature: None | ( - dict[str, TCandidateMetadata] - ) = None, + candidate_metadata_by_arm_signature: None + | (dict[str, TCandidateMetadata]) = None, generation_node_name: str | None = None, ) -> None: """ diff --git a/ax/core/map_data.py b/ax/core/map_data.py index c3439c4a243..d06a3b7ec30 100644 --- a/ax/core/map_data.py +++ b/ax/core/map_data.py @@ -295,7 +295,6 @@ def filter( trial_indices: Iterable[int] | None = None, metric_names: Iterable[str] | None = None, ) -> MapData: - return MapData( df=self._filter_df( df=self.map_df, trial_indices=trial_indices, metric_names=metric_names diff --git a/ax/core/optimization_config.py b/ax/core/optimization_config.py index 68ed22534ee..da1ece3e315 100644 --- a/ax/core/optimization_config.py +++ b/ax/core/optimization_config.py @@ -298,9 +298,8 @@ def clone_with_args( self, objective: MultiObjective | ScalarizedObjective | None = None, outcome_constraints: None | (list[OutcomeConstraint]) = _NO_OUTCOME_CONSTRAINTS, - objective_thresholds: None | ( - list[ObjectiveThreshold] - ) = _NO_OBJECTIVE_THRESHOLDS, + objective_thresholds: None + | (list[ObjectiveThreshold]) = _NO_OBJECTIVE_THRESHOLDS, risk_measure: RiskMeasure | None = _NO_RISK_MEASURE, ) -> "MultiObjectiveOptimizationConfig": """Make a copy of this optimization config.""" diff --git a/ax/core/parameter.py b/ax/core/parameter.py index 91556b00bcc..d766d47460b 100644 --- a/ax/core/parameter.py +++ b/ax/core/parameter.py @@ -190,7 +190,6 @@ def available_flags(self) -> list[str]: def summary_dict( self, ) -> dict[str, TParamValueList | TParamValue | str | list[str]]: - # Assemble dict. summary_dict = { "name": self.name, diff --git a/ax/core/tests/test_multi_type_experiment.py b/ax/core/tests/test_multi_type_experiment.py index d6b01407bce..8776e4cac19 100644 --- a/ax/core/tests/test_multi_type_experiment.py +++ b/ax/core/tests/test_multi_type_experiment.py @@ -180,7 +180,6 @@ def setUp(self) -> None: self.experiment.new_batch_trial(trial_type="type2") def test_filter_trials_by_type(self) -> None: - trials = self.experiment.trials.values() self.assertEqual(len(trials), 2) filtered = filter_trials_by_type(trials, trial_type="type1") diff --git a/ax/core/tests/test_objective.py b/ax/core/tests/test_objective.py index 13fa0f6d29c..14f741b1fbf 100644 --- a/ax/core/tests/test_objective.py +++ b/ax/core/tests/test_objective.py @@ -39,7 +39,7 @@ def setUp(self) -> None: def test_Init(self) -> None: with self.assertRaisesRegex(UserInputError, "does not specify"): - Objective(metric=self.metrics["m1"]), + (Objective(metric=self.metrics["m1"]),) with self.assertRaisesRegex( UserInputError, "doesn't match the specified optimization direction" ): diff --git a/ax/core/tests/test_outcome_constraint.py b/ax/core/tests/test_outcome_constraint.py index b3f3a6fe033..df6f07e3948 100644 --- a/ax/core/tests/test_outcome_constraint.py +++ b/ax/core/tests/test_outcome_constraint.py @@ -82,7 +82,6 @@ def test_Sortable(self) -> None: self.assertTrue(constraint1 < constraint2) def test_validate_constraint(self) -> None: - metric = Metric(name="metric0", lower_is_better=False) oc = OutcomeConstraint(metric, bound=-3, relative=True, op=ComparisonOp.GEQ) self.assertTrue(oc._validate_constraint()[0]) diff --git a/ax/early_stopping/strategies/logical.py b/ax/early_stopping/strategies/logical.py index 3eddefede43..b76ceca0ad5 100644 --- a/ax/early_stopping/strategies/logical.py +++ b/ax/early_stopping/strategies/logical.py @@ -36,7 +36,6 @@ def should_stop_trials_early( experiment: Experiment, **kwargs: dict[str, Any], ) -> dict[int, str | None]: - left = self.left.should_stop_trials_early( trial_indices=trial_indices, experiment=experiment, **kwargs ) diff --git a/ax/metrics/branin_map.py b/ax/metrics/branin_map.py index afa3765e83b..d65960c5b2f 100644 --- a/ax/metrics/branin_map.py +++ b/ax/metrics/branin_map.py @@ -131,7 +131,6 @@ def f(self, x: np.ndarray, timestamp: int) -> Mapping[str, Any]: class BraninFidelityMapMetric(NoisyFunctionMapMetric): - map_key_info: MapKeyInfo[float] = MapKeyInfo(key="fidelity", default_value=0.0) def __init__( diff --git a/ax/modelbridge/dispatch_utils.py b/ax/modelbridge/dispatch_utils.py index ae58bd92908..99b3340160c 100644 --- a/ax/modelbridge/dispatch_utils.py +++ b/ax/modelbridge/dispatch_utils.py @@ -73,9 +73,8 @@ def _make_botorch_step( max_parallelism: int | None = None, model: ModelRegistryBase = Models.BOTORCH_MODULAR, model_kwargs: dict[str, Any] | None = None, - winsorization_config: None | ( - WinsorizationConfig | dict[str, WinsorizationConfig] - ) = None, + winsorization_config: None + | (WinsorizationConfig | dict[str, WinsorizationConfig]) = None, no_winsorization: bool = False, should_deduplicate: bool = False, verbose: bool | None = None, @@ -97,9 +96,9 @@ def _make_botorch_step( "use_raw_status_quo": derelativize_with_raw_status_quo } model_kwargs["transform_configs"] = model_kwargs.get("transform_configs", {}) - model_kwargs["transform_configs"][ - "Derelativize" - ] = derelativization_transform_config + model_kwargs["transform_configs"]["Derelativize"] = ( + derelativization_transform_config + ) model_kwargs["fit_out_of_design"] = fit_out_of_design if not no_winsorization: @@ -108,9 +107,9 @@ def _make_botorch_step( transforms = model_kwargs.get("transforms", default_transforms) model_kwargs["transforms"] = [cast(type[Transform], Winsorize)] + transforms if winsorization_transform_config is not None: - model_kwargs["transform_configs"][ - "Winsorize" - ] = winsorization_transform_config + model_kwargs["transform_configs"]["Winsorize"] = ( + winsorization_transform_config + ) if MODEL_KEY_TO_MODEL_SETUP[model.value].model_class != ModularBoTorchModel: if verbose is not None: @@ -292,9 +291,8 @@ def choose_generation_strategy( random_seed: int | None = None, torch_device: torch.device | None = None, no_winsorization: bool = False, - winsorization_config: None | ( - WinsorizationConfig | dict[str, WinsorizationConfig] - ) = None, + winsorization_config: None + | (WinsorizationConfig | dict[str, WinsorizationConfig]) = None, derelativize_with_raw_status_quo: bool = False, no_bayesian_optimization: bool | None = None, force_random_search: bool = False, diff --git a/ax/modelbridge/generation_node.py b/ax/modelbridge/generation_node.py index 9aaeee7413a..3310822f3c6 100644 --- a/ax/modelbridge/generation_node.py +++ b/ax/modelbridge/generation_node.py @@ -132,7 +132,8 @@ def __init__( best_model_selector: BestModelSelector | None = None, should_deduplicate: bool = False, transition_criteria: Sequence[TransitionCriterion] | None = None, - input_constructors: None | ( + input_constructors: None + | ( dict[ modelbridge.generation_node_input_constructors.InputConstructorPurpose, modelbridge.generation_node_input_constructors.NodeInputConstructors, diff --git a/ax/modelbridge/pairwise.py b/ax/modelbridge/pairwise.py index ad76c92f844..c5b0e409963 100644 --- a/ax/modelbridge/pairwise.py +++ b/ax/modelbridge/pairwise.py @@ -22,7 +22,6 @@ class PairwiseModelBridge(TorchModelBridge): - def _convert_observations( self, observation_data: list[ObservationData], diff --git a/ax/modelbridge/registry.py b/ax/modelbridge/registry.py index 74e2a79d046..309b8af9b11 100644 --- a/ax/modelbridge/registry.py +++ b/ax/modelbridge/registry.py @@ -15,7 +15,6 @@ from generator run, use `get_model_from_generator_run` utility from this module. """ - from __future__ import annotations import warnings diff --git a/ax/modelbridge/tests/test_torch_modelbridge.py b/ax/modelbridge/tests/test_torch_modelbridge.py index e8bfc7dfdbf..bac4e749cdc 100644 --- a/ax/modelbridge/tests/test_torch_modelbridge.py +++ b/ax/modelbridge/tests/test_torch_modelbridge.py @@ -138,7 +138,8 @@ def test_TorchModelBridge( ] observations = recombine_observations(observation_features, observation_data) ssd = SearchSpaceDigest( - feature_names=feature_names, bounds=[(0, 1)] * 3 # pyre-ignore + feature_names=feature_names, + bounds=[(0, 1)] * 3, # pyre-ignore ) with mock.patch( diff --git a/ax/modelbridge/tests/test_torch_moo_modelbridge.py b/ax/modelbridge/tests/test_torch_moo_modelbridge.py index 968737c33ce..4a1d22fdf55 100644 --- a/ax/modelbridge/tests/test_torch_moo_modelbridge.py +++ b/ax/modelbridge/tests/test_torch_moo_modelbridge.py @@ -249,7 +249,6 @@ def test_pareto_frontier(self) -> None: @fast_botorch_optimize def test_get_pareto_frontier_and_configs_input_validation(self) -> None: - exp = get_branin_experiment_with_multi_objective( has_optimization_config=True, with_batch=True ) diff --git a/ax/modelbridge/transforms/power_transform_y.py b/ax/modelbridge/transforms/power_transform_y.py index 71591a5dc53..dca4ac63e3a 100644 --- a/ax/modelbridge/transforms/power_transform_y.py +++ b/ax/modelbridge/transforms/power_transform_y.py @@ -161,7 +161,7 @@ def untransform_outcome_constraints( def _compute_power_transforms( - Ys: dict[str, list[float]] + Ys: dict[str, list[float]], ) -> dict[str, PowerTransformer]: """Compute power transforms.""" power_transforms = {} diff --git a/ax/modelbridge/transforms/standardize_y.py b/ax/modelbridge/transforms/standardize_y.py index ce7fc936601..88261c672cb 100644 --- a/ax/modelbridge/transforms/standardize_y.py +++ b/ax/modelbridge/transforms/standardize_y.py @@ -147,7 +147,7 @@ def untransform_outcome_constraints( def compute_standardization_parameters( - Ys: defaultdict[str | tuple[str, TParamValue], list[float]] + Ys: defaultdict[str | tuple[str, TParamValue], list[float]], ) -> tuple[dict[str | tuple[str, str], float], dict[str | tuple[str, str], float]]: """Compute mean and std. dev of Ys.""" Ymean = {k: np.mean(y) for k, y in Ys.items()} diff --git a/ax/modelbridge/transforms/tests/test_centered_unit_x_transform.py b/ax/modelbridge/transforms/tests/test_centered_unit_x_transform.py index af79001345a..681188459d2 100644 --- a/ax/modelbridge/transforms/tests/test_centered_unit_x_transform.py +++ b/ax/modelbridge/transforms/tests/test_centered_unit_x_transform.py @@ -11,7 +11,6 @@ class CenteredUnitXTransformTest(UnitXTransformTest): - transform_class = CenteredUnitX # pyre-fixme[4]: Attribute must be annotated. expected_c_dicts = [{"x": -0.5, "y": 0.5}, {"x": -0.5, "a": 1.0}] diff --git a/ax/modelbridge/transforms/tests/test_metrics_as_task_transform.py b/ax/modelbridge/transforms/tests/test_metrics_as_task_transform.py index 256c9ddedd2..b11d0aa7e64 100644 --- a/ax/modelbridge/transforms/tests/test_metrics_as_task_transform.py +++ b/ax/modelbridge/transforms/tests/test_metrics_as_task_transform.py @@ -129,7 +129,9 @@ def test_TransformSearchSpace(self) -> None: new_param = new_ss.parameters["METRIC_TASK"] self.assertIsInstance(new_param, ChoiceParameter) self.assertEqual( - new_param.values, ["TARGET", "metric1", "metric2"] # pyre-ignore + # pyre-fixme[16]: `Parameter` has no attribute `values`. + new_param.values, + ["TARGET", "metric1", "metric2"], ) self.assertTrue(new_param.is_task) # pyre-ignore self.assertEqual(new_param.target_value, "TARGET") diff --git a/ax/modelbridge/transforms/tests/test_unit_x_transform.py b/ax/modelbridge/transforms/tests/test_unit_x_transform.py index 451ca671b86..4b938e88076 100644 --- a/ax/modelbridge/transforms/tests/test_unit_x_transform.py +++ b/ax/modelbridge/transforms/tests/test_unit_x_transform.py @@ -21,7 +21,6 @@ class UnitXTransformTest(TestCase): - transform_class = UnitX # pyre-fixme[4]: Attribute must be annotated. expected_c_dicts = [{"x": -1.0, "y": 1.0}, {"x": -1.0, "a": 1.0}] diff --git a/ax/modelbridge/transforms/tests/test_winsorize_transform.py b/ax/modelbridge/transforms/tests/test_winsorize_transform.py index 62a18484720..5a23e0f5049 100644 --- a/ax/modelbridge/transforms/tests/test_winsorize_transform.py +++ b/ax/modelbridge/transforms/tests/test_winsorize_transform.py @@ -572,7 +572,6 @@ def test_relative_constraints( self, mock_observations_from_data: mock.Mock, ) -> None: - # ModelBridge with in-design status quo search_space = SearchSpace( parameters=[ diff --git a/ax/modelbridge/transforms/unit_x.py b/ax/modelbridge/transforms/unit_x.py index 43b24025b12..8ce91d91b32 100644 --- a/ax/modelbridge/transforms/unit_x.py +++ b/ax/modelbridge/transforms/unit_x.py @@ -77,7 +77,10 @@ def _transform_search_space(self, search_space: SearchSpace) -> SearchSpace: ) if p.target_value is not None: p._target_value = self._normalize_value( - value=p.target_value, bounds=p_bounds # pyre-ignore [6] + # pyre-fixme[6]: For 1st argument expected `float` but got + # `Union[bool, float, int, str]`. + value=p.target_value, + bounds=p_bounds, ) new_constraints: list[ParameterConstraint] = [] for c in search_space.parameter_constraints: diff --git a/ax/models/tests/test_botorch_defaults.py b/ax/models/tests/test_botorch_defaults.py index fcd4f17ef1c..e111667f34c 100644 --- a/ax/models/tests/test_botorch_defaults.py +++ b/ax/models/tests/test_botorch_defaults.py @@ -190,7 +190,11 @@ def test_get_model(self) -> None: LKJCovariancePrior, ) model = _get_model( - X=x, Y=y, Yvar=var, task_feature=1, **deepcopy(kwargs6) # pyre-ignore + X=x, + Y=y, + Yvar=var, + task_feature=1, + **deepcopy(kwargs6), # pyre-ignore ) self.assertIsInstance(model, MultiTaskGP) self.assertIsInstance(model.likelihood, FixedNoiseGaussianLikelihood) @@ -213,7 +217,11 @@ def test_get_model(self) -> None: lengthscale_prior=GammaPrior(6.0, 6.0), ) model = _get_model( - X=x, Y=y, Yvar=var, covar_module=covar_module, **kwargs7 # pyre-ignore + X=x, + Y=y, + Yvar=var, + covar_module=covar_module, + **kwargs7, # pyre-ignore ) self.assertIsInstance(model, SingleTaskGP) self.assertIsInstance(model.likelihood, FixedNoiseGaussianLikelihood) diff --git a/ax/models/torch/botorch.py b/ax/models/torch/botorch.py index 087f286df9f..3186550e329 100644 --- a/ax/models/torch/botorch.py +++ b/ax/models/torch/botorch.py @@ -524,7 +524,7 @@ def model(self, model: Model) -> None: def get_rounding_func( - rounding_func: Callable[[Tensor], Tensor] | None + rounding_func: Callable[[Tensor], Tensor] | None, ) -> Callable[[Tensor], Tensor] | None: if rounding_func is None: botorch_rounding_func = rounding_func diff --git a/ax/models/torch/botorch_defaults.py b/ax/models/torch/botorch_defaults.py index b6faa4b817a..4c6af8e61e6 100644 --- a/ax/models/torch/botorch_defaults.py +++ b/ax/models/torch/botorch_defaults.py @@ -347,9 +347,8 @@ def _get_acquisition_func( X_observed: Tensor | None = None, X_pending: Tensor | None = None, mc_objective: type[GenericMCObjective] = GenericMCObjective, - constrained_mc_objective: None | ( - type[ConstrainedMCObjective] - ) = ConstrainedMCObjective, + constrained_mc_objective: None + | (type[ConstrainedMCObjective]) = ConstrainedMCObjective, # pyre-fixme[24]: Generic type `dict` expects 2 type parameters, use # `typing.Dict` to avoid runtime subscripting errors. mc_objective_kwargs: dict | None = None, diff --git a/ax/models/torch/botorch_modular/utils.py b/ax/models/torch/botorch_modular/utils.py index cf8b80f1442..207c5c700cd 100644 --- a/ax/models/torch/botorch_modular/utils.py +++ b/ax/models/torch/botorch_modular/utils.py @@ -47,7 +47,6 @@ def use_model_list( botorch_model_class: type[Model], allow_batched_models: bool = True, ) -> bool: - if issubclass(botorch_model_class, MultiTaskGP): # We currently always wrap multi-task models into `ModelListGP`. return True @@ -142,8 +141,7 @@ def choose_botorch_acqf_class( # using objective_weights is a less-than-ideal fix given its ambiguity, # the real fix would be to revisit the infomration passed down via # the modelbridge (and be explicit about whether we scalarize or perform MOO) - objective_weights is not None - and objective_weights.nonzero().numel() > 1 + objective_weights is not None and objective_weights.nonzero().numel() > 1 ): acqf_class = qLogNoisyExpectedHypervolumeImprovement else: diff --git a/ax/models/torch/tests/test_covar_modules_argparse.py b/ax/models/torch/tests/test_covar_modules_argparse.py index fc41d3631a4..b5a19170ecc 100644 --- a/ax/models/torch/tests/test_covar_modules_argparse.py +++ b/ax/models/torch/tests/test_covar_modules_argparse.py @@ -54,7 +54,6 @@ def _argparse(kernel: DummyKernel) -> None: self.assertEqual(covar_module_argparse[DummyKernel], _argparse) def test_fallback(self) -> None: - with patch.dict(covar_module_argparse.funcs, {}): @covar_module_argparse.register(Kernel) @@ -105,7 +104,6 @@ def test_argparse_scalematern_kernel(self) -> None: ] for i, botorch_model_class in enumerate([SingleTaskGP, MultiTaskGP]): - covar_module_kwargs = covar_module_argparse( ScaleMaternKernel, botorch_model_class=botorch_model_class, diff --git a/ax/models/torch/tests/test_input_transform_argparse.py b/ax/models/torch/tests/test_input_transform_argparse.py index ed24edc46c7..69e4f1e93b6 100644 --- a/ax/models/torch/tests/test_input_transform_argparse.py +++ b/ax/models/torch/tests/test_input_transform_argparse.py @@ -70,7 +70,6 @@ def _argparse(input_transform: DummyInputTransform) -> None: self.assertEqual(input_transform_argparse[DummyInputTransform], _argparse) def test_fallback(self) -> None: - with patch.dict(input_transform_argparse.funcs, {}): @input_transform_argparse.register(InputTransform) @@ -80,7 +79,6 @@ def _argparse(input_transform_class: InputTransform) -> None: self.assertEqual(input_transform_argparse[InputTransform], _argparse) def test_argparse_input_transform(self) -> None: - input_transform_kwargs = input_transform_argparse( InputTransform, dataset=self.dataset, @@ -185,7 +183,6 @@ def test_argparse_warp(self) -> None: self.assertEqual(input_transform_kwargs, {"indices": [0, 1]}) def test_argparse_input_perturbation(self) -> None: - self.search_space_digest.robust_digest = RobustSearchSpaceDigest( sample_param_perturbations=lambda: np.zeros((2, 2)), ) diff --git a/ax/models/torch/tests/test_surrogate.py b/ax/models/torch/tests/test_surrogate.py index e8630cd4c86..e65fdf5f810 100644 --- a/ax/models/torch/tests/test_surrogate.py +++ b/ax/models/torch/tests/test_surrogate.py @@ -438,9 +438,7 @@ def test_construct_model(self) -> None: wraps=botorch_model_class.construct_inputs, ) as mock_construct_inputs, patch.object( botorch_model_class, "__init__", return_value=None - ) as mock_init, patch( - f"{SURROGATE_PATH}.fit_botorch_model" - ) as mock_fit: + ) as mock_init, patch(f"{SURROGATE_PATH}.fit_botorch_model") as mock_fit: model = surrogate._construct_model( dataset=self.training_data[0], search_space_digest=self.search_space_digest, diff --git a/ax/models/torch/tests/test_utils.py b/ax/models/torch/tests/test_utils.py index 735f63ff61d..e23fac4eef1 100644 --- a/ax/models/torch/tests/test_utils.py +++ b/ax/models/torch/tests/test_utils.py @@ -57,7 +57,8 @@ def setUp(self) -> None: self.metric_names, ) = get_torch_test_data(dtype=self.dtype) self.Xs2, self.Ys2, self.Yvars2, _, _, _, _ = get_torch_test_data( - dtype=self.dtype, offset=1.0 # Making this data different. + dtype=self.dtype, + offset=1.0, # Making this data different. ) self.fixed_noise_datasets = [ SupervisedDataset( diff --git a/ax/models/torch/utils.py b/ax/models/torch/utils.py index 0d29ca27f3d..8b2f90dee1c 100644 --- a/ax/models/torch/utils.py +++ b/ax/models/torch/utils.py @@ -345,7 +345,7 @@ def subset_model( def _to_inequality_constraints( - linear_constraints: tuple[Tensor, Tensor] | None = None + linear_constraints: tuple[Tensor, Tensor] | None = None, ) -> list[tuple[Tensor, Tensor, float]] | None: if linear_constraints is not None: A, b = linear_constraints diff --git a/ax/plot/feature_importances.py b/ax/plot/feature_importances.py index 2c4253d80ca..3193b0882bc 100644 --- a/ax/plot/feature_importances.py +++ b/ax/plot/feature_importances.py @@ -262,9 +262,7 @@ def plot_feature_importance_by_feature_plotly( height=200 + len(features) * 20, width=10 * longest_label + max(10 * longest_metric, 400), hovermode="closest", - margin=go.layout.Margin( - l=8 * min(max(len(idx) for idx in features), 75) - ), # noqa E741 + margin=go.layout.Margin(l=8 * min(max(len(idx) for idx in features), 75)), # noqa E741 title=title, updatemenus=updatemenus, annotations=compose_annotation(caption=caption), diff --git a/ax/service/ax_client.py b/ax/service/ax_client.py index 284acbca1d2..9590ae86583 100644 --- a/ax/service/ax_client.py +++ b/ax/service/ax_client.py @@ -1380,9 +1380,8 @@ def to_json_snapshot( # pyre-fixme[2]: Parameter annotation cannot contain `Any`. # pyre-fixme[24]: Generic type `type` expects 1 type parameter, use # `typing.Type` to avoid runtime subscripting errors. - class_encoder_registry: None | ( - dict[type, Callable[[Any], dict[str, Any]]] - ) = None, + class_encoder_registry: None + | (dict[type, Callable[[Any], dict[str, Any]]]) = None, ) -> dict[str, Any]: """Serialize this `AxClient` to JSON to be able to interrupt and restart optimization and save it to file by the provided path. @@ -1417,9 +1416,8 @@ def from_json_snapshot( serialized: dict[str, Any], decoder_registry: TDecoderRegistry | None = None, # pyre-fixme[2]: Parameter annotation cannot contain `Any`. - class_decoder_registry: None | ( - dict[str, Callable[[dict[str, Any]], Any]] - ) = None, + class_decoder_registry: None + | (dict[str, Callable[[dict[str, Any]], Any]]) = None, # pyre-fixme[2]: Parameter must be annotated. **kwargs, ) -> AxClientSubclass: diff --git a/ax/service/tests/scheduler_test_utils.py b/ax/service/tests/scheduler_test_utils.py index 65ff1307015..42466418b3c 100644 --- a/ax/service/tests/scheduler_test_utils.py +++ b/ax/service/tests/scheduler_test_utils.py @@ -145,7 +145,6 @@ def report_results(self, force_refit: bool = False) -> dict[str, Any]: class RunnerWithFrequentFailedTrials(SyntheticRunner): - poll_failed_next_time = True def poll_trial_status( @@ -161,14 +160,12 @@ def poll_trial_status( class RunnerWithFailedAndAbandonedTrials(SyntheticRunner): - poll_failed_next_time = True status_idx = 0 def poll_trial_status( self, trials: Iterable[BaseTrial] ) -> dict[TrialStatus, set[int]]: - trial_statuses_dummy = { 0: TrialStatus.ABANDONED, 1: TrialStatus.FAILED, @@ -228,7 +225,6 @@ def poll_trial_status( class BrokenRunnerValueError(SyntheticRunnerWithStatusPolling): - run_trial_call_count = 0 def run_multiple(self, trials: Iterable[BaseTrial]) -> dict[int, dict[str, Any]]: @@ -237,7 +233,6 @@ def run_multiple(self, trials: Iterable[BaseTrial]) -> dict[int, dict[str, Any]] class BrokenRunnerRuntimeError(SyntheticRunnerWithStatusPolling): - run_trial_call_count = 0 def run_multiple(self, trials: Iterable[BaseTrial]) -> dict[int, dict[str, Any]]: @@ -1887,9 +1882,7 @@ def test_fetch_and_process_trials_data_results_failed_objective_available_while_ {TrialStatus.RUNNING: {0}}, {TrialStatus.COMPLETED: {0}}, ], - ), self.assertLogs( - logger="ax.service.scheduler", level="INFO" - ) as lg: + ), self.assertLogs(logger="ax.service.scheduler", level="INFO") as lg: scheduler = Scheduler( experiment=self.branin_timestamp_map_metric_experiment, generation_strategy=gs, @@ -1950,9 +1943,7 @@ def test_fetch_and_process_trials_data_results_failed_objective(self) -> None: ), patch( f"{BraninMetric.__module__}.BraninMetric.is_available_while_running", return_value=False, - ), self.assertLogs( - logger="ax.service.scheduler" - ) as lg: + ), self.assertLogs(logger="ax.service.scheduler") as lg: scheduler = Scheduler( experiment=self.branin_experiment, generation_strategy=gs, @@ -2637,7 +2628,6 @@ def test_compute_analyses(self) -> None: ) with self.assertLogs(logger="ax.analysis", level="ERROR") as lg: - cards = scheduler.compute_analyses(analyses=[ParallelCoordinatesPlot()]) self.assertEqual(len(cards), 0) diff --git a/ax/service/tests/test_ax_client.py b/ax/service/tests/test_ax_client.py index 9439f23a05e..54c8c167b7d 100644 --- a/ax/service/tests/test_ax_client.py +++ b/ax/service/tests/test_ax_client.py @@ -211,7 +211,6 @@ def get_client_with_simple_discrete_moo_problem( use_y0_threshold: bool, use_y2_constraint: bool, ) -> AxClient: - gs = GenerationStrategy( steps=[ GenerationStep(model=Models.SOBOL, num_trials=3), @@ -2545,7 +2544,7 @@ def helper_test_get_pareto_optimal_parameters_simple( """ def _get_parameterizations_from_pareto_frontier( - pareto: dict[int, tuple[TParameterization, TModelPredictArm]] + pareto: dict[int, tuple[TParameterization, TModelPredictArm]], ) -> set[TParamValue]: return {tup[0]["x"] for tup in pareto.values()} diff --git a/ax/service/tests/test_interactive_loop.py b/ax/service/tests/test_interactive_loop.py index 843411f05dc..b1432b60375 100644 --- a/ax/service/tests/test_interactive_loop.py +++ b/ax/service/tests/test_interactive_loop.py @@ -27,7 +27,7 @@ class TestInteractiveLoop(TestCase): @fast_botorch_optimize def test_interactive_loop(self) -> None: def _elicit( - parameterization_with_trial_index: tuple[TParameterization, int] + parameterization_with_trial_index: tuple[TParameterization, int], ) -> tuple[int, TEvaluationOutcome] | None: parameterization, trial_index = parameterization_with_trial_index x = np.array([parameterization.get(f"x{i+1}") for i in range(6)]) @@ -41,7 +41,7 @@ def _elicit( ) def _aborted_elicit( - parameterization_with_trial_index: tuple[TParameterization, int] + parameterization_with_trial_index: tuple[TParameterization, int], ) -> tuple[int, TEvaluationOutcome] | None: return None @@ -84,7 +84,7 @@ def _aborted_elicit( def test_candidate_pregeneration_errors_raised(self) -> None: def _elicit( - parameterization_with_trial_index: tuple[TParameterization, int] + parameterization_with_trial_index: tuple[TParameterization, int], ) -> tuple[int, TEvaluationOutcome]: parameterization, trial_index = parameterization_with_trial_index time.sleep(0.15) # Sleep to induce MaxParallelismException in loop diff --git a/ax/service/tests/test_managed_loop.py b/ax/service/tests/test_managed_loop.py index a6bfa320737..435d9c95d15 100644 --- a/ax/service/tests/test_managed_loop.py +++ b/ax/service/tests/test_managed_loop.py @@ -20,7 +20,9 @@ def _branin_evaluation_function( - parameterization, weight=None # pyre-fixme[2]: Parameter must be annotated. + # pyre-fixme[2]: Parameter must be annotated. + parameterization, + weight=None, # pyre-fixme[2]: Parameter must be annotated. ) -> dict[str, tuple[float | ndarray, float]]: if any(param_name not in parameterization.keys() for param_name in ["x1", "x2"]): raise ValueError("Parametrization does not contain x1 or x2") @@ -32,7 +34,9 @@ def _branin_evaluation_function( def _branin_evaluation_function_v2( - parameterization, weight=None # pyre-fixme[2]: Parameter must be annotated. + # pyre-fixme[2]: Parameter must be annotated. + parameterization, + weight=None, # pyre-fixme[2]: Parameter must be annotated. ) -> tuple[float | ndarray, float]: if any(param_name not in parameterization.keys() for param_name in ["x1", "x2"]): raise ValueError("Parametrization does not contain x1 or x2") @@ -41,7 +45,9 @@ def _branin_evaluation_function_v2( def _branin_evaluation_function_with_unknown_sem( - parameterization, weight=None # pyre-fixme[2]: Parameter must be annotated. + # pyre-fixme[2]: Parameter must be annotated. + parameterization, + weight=None, # pyre-fixme[2]: Parameter must be annotated. ) -> tuple[float | ndarray, None]: if any(param_name not in parameterization.keys() for param_name in ["x1", "x2"]): raise ValueError("Parametrization does not contain x1 or x2") diff --git a/ax/service/tests/test_with_db_settings_base.py b/ax/service/tests/test_with_db_settings_base.py index 8c6034c9d0d..1dcda0457a9 100644 --- a/ax/service/tests/test_with_db_settings_base.py +++ b/ax/service/tests/test_with_db_settings_base.py @@ -100,7 +100,6 @@ def init_experiment_and_generation_strategy( return experiment, generation_strategy def test_get_experiment_and_generation_strategy_db_id(self) -> None: - ( exp_id, gen_id, diff --git a/ax/service/utils/best_point.py b/ax/service/utils/best_point.py index 7f19765cdd1..508d6d4235a 100644 --- a/ax/service/utils/best_point.py +++ b/ax/service/utils/best_point.py @@ -141,7 +141,6 @@ def get_best_raw_objective_point( optimization_config: OptimizationConfig | None = None, trial_indices: Iterable[int] | None = None, ) -> tuple[TParameterization, dict[str, tuple[float, float]]]: - _, parameterization, vals = get_best_raw_objective_point_with_trial_index( experiment=experiment, optimization_config=optimization_config, @@ -165,7 +164,7 @@ def _gr_to_prediction_with_trial_index( def _raw_values_to_model_predict_arm( - values: dict[str, tuple[float, float]] + values: dict[str, tuple[float, float]], ) -> TModelPredictArm: return ( {k: v[0] for k, v in values.items()}, # v[0] is mean diff --git a/ax/service/utils/instantiation.py b/ax/service/utils/instantiation.py index aebf8aeaa17..b51ff0eae7a 100644 --- a/ax/service/utils/instantiation.py +++ b/ax/service/utils/instantiation.py @@ -559,7 +559,6 @@ def make_outcome_constraints( status_quo_defined: bool, metric_definitions: dict[str, dict[str, Any]] | None = None, ) -> list[OutcomeConstraint]: - typed_outcome_constraints = [ cls.outcome_constraint_from_str(c, metric_definitions=metric_definitions) for c in outcome_constraints @@ -581,7 +580,6 @@ def make_objective_thresholds( status_quo_defined: bool, metric_definitions: dict[str, dict[str, Any]] | None = None, ) -> list[ObjectiveThreshold]: - typed_objective_thresholds = ( [ cls.objective_threshold_constraint_from_str( @@ -649,7 +647,6 @@ def make_optimization_config( status_quo_defined: bool, metric_definitions: dict[str, dict[str, Any]] | None = None, ) -> OptimizationConfig: - return cls.optimization_config_from_objectives( cls.make_objectives(objectives, metric_definitions=metric_definitions), cls.make_objective_thresholds( @@ -790,9 +787,8 @@ def make_experiment( objective_thresholds: list[str] | None = None, support_intermediate_data: bool = False, immutable_search_space_and_opt_config: bool = True, - auxiliary_experiments_by_purpose: None | ( - dict[AuxiliaryExperimentPurpose, list[AuxiliaryExperiment]] - ) = None, + auxiliary_experiments_by_purpose: None + | (dict[AuxiliaryExperimentPurpose, list[AuxiliaryExperiment]]) = None, is_test: bool = False, ) -> Experiment: """Instantiation wrapper that allows for Ax `Experiment` creation diff --git a/ax/service/utils/report_utils.py b/ax/service/utils/report_utils.py index 15144546bca..499372bb39f 100644 --- a/ax/service/utils/report_utils.py +++ b/ax/service/utils/report_utils.py @@ -148,9 +148,8 @@ def _get_objective_trace_plot( def _get_objective_v_param_plots( experiment: Experiment, model: ModelBridge, - importance: None | ( - dict[str, dict[str, np.ndarray]] | dict[str, dict[str, float]] - ) = None, + importance: None + | (dict[str, dict[str, np.ndarray]] | dict[str, dict[str, float]]) = None, # Chosen to take ~1min on local benchmarks. max_num_slice_plots: int = 200, # Chosen to take ~2min on local benchmarks. @@ -789,9 +788,8 @@ def exp_to_df( run_metadata_fields: list[str] | None = None, trial_properties_fields: list[str] | None = None, trial_attribute_fields: list[str] | None = None, - additional_fields_callables: None | ( - dict[str, Callable[[Experiment], dict[int, str | float]]] - ) = None, + additional_fields_callables: None + | (dict[str, Callable[[Experiment], dict[int, str | float]]]) = None, always_include_field_columns: bool = False, show_relative_metrics: bool = False, **kwargs: Any, @@ -1120,7 +1118,6 @@ def _pareto_frontier_scatter_2d_plotly( reference_point: tuple[float, float] | None = None, minimize: bool | tuple[bool, bool] | None = None, ) -> go.Figure: - # Determine defaults for unspecified inputs using `optimization_config` metric_names, reference_point, minimize = _pareto_frontier_plot_input_processing( experiment=experiment, @@ -1140,7 +1137,6 @@ def pareto_frontier_scatter_2d_plotly( reference_point: tuple[float, float] | None = None, minimize: bool | tuple[bool, bool] | None = None, ) -> go.Figure: - df = exp_to_df(experiment) Y = df[list(metric_names)].to_numpy() Y_pareto = ( @@ -1188,7 +1184,7 @@ def _objective_vs_true_objective_scatter( # TODO: may want to have a way to do this with a plot_fn # that returns a list of plots, such as get_standard_plots def get_figure_and_callback( - plot_fn: Callable[["Scheduler"], go.Figure] + plot_fn: Callable[["Scheduler"], go.Figure], ) -> tuple[go.Figure, Callable[["Scheduler"], None]]: """ Produce a figure and a callback for updating the figure in place. @@ -1473,7 +1469,7 @@ def maybe_extract_baseline_comparison_values( def compare_to_baseline_impl( - comparison_list: list[tuple[str, bool, str, float, str, float]] + comparison_list: list[tuple[str, bool, str, float, str, float]], ) -> str | None: """Implementation of compare_to_baseline, taking in a list of arm comparisons. diff --git a/ax/storage/json_store/decoder.py b/ax/storage/json_store/decoder.py index 40f2044b577..051c48b64af 100644 --- a/ax/storage/json_store/decoder.py +++ b/ax/storage/json_store/decoder.py @@ -634,7 +634,7 @@ def _load_experiment_info( def _convert_generation_step_keys_for_backwards_compatibility( - object_json: dict[str, Any] + object_json: dict[str, Any], ) -> dict[str, Any]: """If necessary, converts keys in a JSON dict representing a `GenerationStep` for backwards compatibility. diff --git a/ax/storage/json_store/decoders.py b/ax/storage/json_store/decoders.py index 811df051022..83836a684be 100644 --- a/ax/storage/json_store/decoders.py +++ b/ax/storage/json_store/decoders.py @@ -184,7 +184,7 @@ def input_transform_type_from_json(object_json: dict[str, Any]) -> type[InputTra def outcome_transform_type_from_json( - object_json: dict[str, Any] + object_json: dict[str, Any], ) -> type[OutcomeTransform]: outcome_transform_type = object_json.pop("index") if outcome_transform_type not in REVERSE_OUTCOME_TRANSFORM_REGISTRY: diff --git a/ax/storage/json_store/encoder.py b/ax/storage/json_store/encoder.py index 7e47be23bfa..a49e53c2223 100644 --- a/ax/storage/json_store/encoder.py +++ b/ax/storage/json_store/encoder.py @@ -66,7 +66,6 @@ def object_to_json( # noqa C901 if isclass(obj): for class_type in class_encoder_registry: if issubclass(obj, class_type): - obj_dict = class_encoder_registry[class_type](obj) return { k: object_to_json( diff --git a/ax/storage/sqa_store/load.py b/ax/storage/sqa_store/load.py index 089f2cdbae2..635aa2b31e4 100644 --- a/ax/storage/sqa_store/load.py +++ b/ax/storage/sqa_store/load.py @@ -187,7 +187,8 @@ def _get_experiment_sqa( """Obtains SQLAlchemy experiment object from DB.""" with session_scope() as session: query = ( - session.query(exp_sqa_class).filter_by(name=experiment_name) + session.query(exp_sqa_class) + .filter_by(name=experiment_name) # Delay loading trials to a separate call to `_get_trials_sqa` below .options(noload("trials")) ) diff --git a/ax/utils/common/docutils.py b/ax/utils/common/docutils.py index cac882d14c2..671d65a7d13 100644 --- a/ax/utils/common/docutils.py +++ b/ax/utils/common/docutils.py @@ -6,9 +6,7 @@ # pyre-strict -"""Support functions for sphinx et. al -""" - +"""Support functions for sphinx et. al""" from collections.abc import Callable from typing import Any, TypeVar diff --git a/ax/utils/common/testutils.py b/ax/utils/common/testutils.py index 32fbd899c0e..8e5b68e344c 100644 --- a/ax/utils/common/testutils.py +++ b/ax/utils/common/testutils.py @@ -6,8 +6,7 @@ # pyre-strict -"""Support functions for tests -""" +"""Support functions for tests""" import builtins import contextlib diff --git a/ax/utils/measurement/synthetic_functions.py b/ax/utils/measurement/synthetic_functions.py index a52bdce7597..08a06f5f3c9 100644 --- a/ax/utils/measurement/synthetic_functions.py +++ b/ax/utils/measurement/synthetic_functions.py @@ -20,7 +20,6 @@ class SyntheticFunction(ABC): - _required_dimensionality: int _domain: list[tuple[float, float]] _minimums: list[tuple[float, ...]] | None = None diff --git a/ax/utils/report/render.py b/ax/utils/report/render.py index 293b4476894..108286891d8 100644 --- a/ax/utils/report/render.py +++ b/ax/utils/report/render.py @@ -16,7 +16,6 @@ def _load_css_resource() -> str: - resource = pkgutil.get_data( REPORT_MODULE_NAME, os.path.join("resources", "report.css") ) @@ -137,7 +136,6 @@ def render_report_elements( def _load_html_template(name: str) -> str: - resource = pkgutil.get_data(REPORT_MODULE_NAME, os.path.join("resources", name)) assert resource is not None return resource.decode("utf8") diff --git a/ax/utils/sensitivity/derivative_measures.py b/ax/utils/sensitivity/derivative_measures.py index 4209c5946ac..78c8426b4da 100644 --- a/ax/utils/sensitivity/derivative_measures.py +++ b/ax/utils/sensitivity/derivative_measures.py @@ -51,7 +51,6 @@ def sample_discrete_parameters( class GpDGSMGpMean: - mean_gradients: torch.Tensor | None = None bootstrap_indices: torch.Tensor | None = None mean_gradients_btsp: list[torch.Tensor] | None = None @@ -237,7 +236,6 @@ def gradients_square_measure(self) -> torch.Tensor: class GpDGSMGpSampling(GpDGSMGpMean): - samples_gradients: torch.Tensor | None = None samples_gradients_btsp: list[torch.Tensor] | None = None diff --git a/ax/utils/sensitivity/sobol_measures.py b/ax/utils/sensitivity/sobol_measures.py index 8a8116ad6fc..eb11b94a296 100644 --- a/ax/utils/sensitivity/sobol_measures.py +++ b/ax/utils/sensitivity/sobol_measures.py @@ -194,7 +194,9 @@ def evalute_function(self, f_A_B_ABi: torch.Tensor | None = None) -> None: self.f_total_var_btsp = [ torch.var( torch.cat( - (self.f_A_btsp[i], self.f_B_btsp[i]), dim=0 # pyre-ignore + # pyre-fixme[16]: Optional type has no attribute `__getitem__`. + (self.f_A_btsp[i], self.f_B_btsp[i]), + dim=0, ) ) for i in range(self.num_bootstrap_samples) @@ -205,8 +207,7 @@ def evalute_function(self, f_A_B_ABi: torch.Tensor | None = None) -> None: # the ablations of each other self.f_BAis = [ f_A_B_ABi[ - self.num_mc_samples - * (i + 2 + self.dim) : self.num_mc_samples + self.num_mc_samples * (i + 2 + self.dim) : self.num_mc_samples * (i + 3 + self.dim) ] for i in range(self.dim) diff --git a/ax/utils/testing/core_stubs.py b/ax/utils/testing/core_stubs.py index 47243e46130..2aebc0c0d93 100644 --- a/ax/utils/testing/core_stubs.py +++ b/ax/utils/testing/core_stubs.py @@ -1127,7 +1127,6 @@ def get_robust_search_space( use_discrete: bool = False, num_samples: int = 4, # dummy ) -> RobustSearchSpace: - parameters = [ RangeParameter("x", ParameterType.FLOAT, lb, ub), RangeParameter("y", ParameterType.FLOAT, lb, ub), @@ -1658,7 +1657,6 @@ def get_multi_objective_optimization_config( relative: bool = True, outcome_constraint: bool = True, ) -> MultiObjectiveOptimizationConfig: - objective = get_custom_multi_objective() if custom_metric else get_multi_objective() outcome_constraints = ( [get_outcome_constraint(relative=relative)] if outcome_constraint else [] diff --git a/ax/utils/testing/modeling_stubs.py b/ax/utils/testing/modeling_stubs.py index 027837743c5..b75c75ac860 100644 --- a/ax/utils/testing/modeling_stubs.py +++ b/ax/utils/testing/modeling_stubs.py @@ -197,9 +197,9 @@ def get_generation_strategy( if with_callable_model_kwarg: # pyre-ignore[16]: testing hack to test serialization of callable kwargs # in generation steps. - gs._nodes[0]._model_spec_to_gen_from.model_kwargs[ - "model_constructor" - ] = get_sobol + gs._nodes[0]._model_spec_to_gen_from.model_kwargs["model_constructor"] = ( + get_sobol + ) else: gs = choose_generation_strategy( search_space=get_search_space(), should_deduplicate=True diff --git a/tutorials/early_stopping/mnist_train_nas.py b/tutorials/early_stopping/mnist_train_nas.py index c977b9a6264..957685a357a 100644 --- a/tutorials/early_stopping/mnist_train_nas.py +++ b/tutorials/early_stopping/mnist_train_nas.py @@ -136,7 +136,6 @@ def val_dataloader(self): def run_training_job(): - mnist_model = MnistModel() # Initialize a trainer