From 4d98cab00435bfb18577bc8ee85b2301eaef5843 Mon Sep 17 00:00:00 2001 From: "Pyre Bot Jr." Date: Wed, 7 Oct 2026 15:16:27 -0700 Subject: [PATCH] Suppress type errors for Pyre upgrade (landing group 4) (#5298) Summary: X-link: https://github.com/pytorch/FBGEMM/pull/6417 X-link: https://github.com/facebookresearch/FBGEMM/pull/3278 This diff was automatically generated by the Pyre per-target upgrade tool. It adds `# pyrefly: ignore` comments for type errors that an upcoming Pyrefly version will report. It changes comments only; it does not change Python runtime behavior. Landing group: `e5cd8bb1932882651ede8b1556fb5d4edfc7db11f903fed396e610d810c715d8` (attempt 1, 20 batches, 54 files) Merged patch SHA-256: `4d1b81b93caadf1bc3a3bdf05e1317ce2186abe77754c5a430539a158db52e59` Full fbcode Pyrefly per-target upgrade using D123902372 typed Buck uquery scheduler; target commit af8bbadc839ed3725786ccbc573c25769d4a144b. #pyreupgrade Differential Revision: D123975487 --- .../problems/synthetic/from_botorch.py | 2 ++ ax/core/utils.py | 7 +++++-- ax/generators/discrete/ashr_utils.py | 11 +++++++++- ax/generators/discrete/eb_thompson.py | 1 + ax/generators/torch/tests/test_kernels.py | 16 +++++++-------- ax/plot/contour.py | 20 ++++++++++++++++--- ax/utils/stats/math_utils.py | 1 + 7 files changed, 44 insertions(+), 14 deletions(-) diff --git a/ax/benchmark/problems/synthetic/from_botorch.py b/ax/benchmark/problems/synthetic/from_botorch.py index 3d5a648a873..58335d58328 100644 --- a/ax/benchmark/problems/synthetic/from_botorch.py +++ b/ax/benchmark/problems/synthetic/from_botorch.py @@ -190,6 +190,7 @@ def create_problem_from_botorch( if isinstance(test_problem_class, str): test_problem_class = getattr(synthetic, test_problem_class) + # pyrefly: ignore [not-callable] test_problem = test_problem_class(**test_problem_kwargs) is_constrained = isinstance(test_problem, ConstrainedBaseTestProblem) @@ -264,6 +265,7 @@ def create_problem_from_botorch( else: worst_feasible_value = None # Not needed for unconstrained problems baseline_value = ( + # pyrefly: ignore [missing-attribute] BOTORCH_BASELINE_VALUES[(test_problem_class.__name__, dim)] if baseline_value is None else baseline_value diff --git a/ax/core/utils.py b/ax/core/utils.py index 41c0639895a..b370667a5fe 100644 --- a/ax/core/utils.py +++ b/ax/core/utils.py @@ -733,12 +733,15 @@ def _sort_trials( ( # if the trial is running, we set end time to now for sorting ease ( - _time_trial_completed_safe(trial=t).timestamp() + _time_trial_completed_safe( + trial=t # pyrefly: ignore [bad-argument-type] + ).timestamp() # pyrefly: ignore [bad-argument-type] if not trials_are_running else default_time_run_started.timestamp() ) - _time_trial_started_safe( - trial=t, default_time_run_started=default_time_run_started + trial=t, # pyrefly: ignore [bad-argument-type] + default_time_run_started=default_time_run_started, # pyrefly: ignore [bad-argument-type] ).timestamp() ) // twelve_hours_in_secs diff --git a/ax/generators/discrete/ashr_utils.py b/ax/generators/discrete/ashr_utils.py index 7753a41ad7d..da2134c1058 100644 --- a/ax/generators/discrete/ashr_utils.py +++ b/ax/generators/discrete/ashr_utils.py @@ -52,7 +52,9 @@ def __init__( if prior_vars is None: prior_stds = prior_grid(Y=Y, Yvar=Yvar, grid_param=eb_grid_param) prior_vars = prior_stds**2 + # pyrefly: ignore [bad-assignment] self.prior_vars: npt.NDArray = prior_vars + # pyrefly: ignore [bad-argument-type] self.ll: npt.NDArray = marginal_densities(Y=Y, Yvar=Yvar, prior_vars=prior_vars) def posterior(self, w: npt.NDArray) -> GaussianMixture: @@ -115,15 +117,22 @@ def fit( k = len(self.prior_vars) # total number of classes if lambdas is None: lambdas = np.ones(k) # no penalty + # pyrefly: ignore [bad-argument-type] if len(lambdas) != k: raise ValueError( "The length of the penalty sequence should be the number of " "prior classes." ) + # pyrefly: ignore [missing-attribute] lambdas = lambdas.astype(np.float64) results = fit_ashr_em( - ll=self.ll, lambdas=lambdas, threshold=threshold, nsteps=nsteps + # pyrefly: ignore [bad-argument-type] + ll=self.ll, + # pyrefly: ignore [bad-argument-type] + lambdas=lambdas, + threshold=threshold, + nsteps=nsteps, ) return results diff --git a/ax/generators/discrete/eb_thompson.py b/ax/generators/discrete/eb_thompson.py index 75d0b3cd495..193992efde0 100644 --- a/ax/generators/discrete/eb_thompson.py +++ b/ax/generators/discrete/eb_thompson.py @@ -61,4 +61,5 @@ def _apply_shrinkage( Y = npY.tolist() npYvar = npYsem**2 Yvar = npYvar.tolist() + # pyrefly: ignore [bad-return] return Y, Yvar diff --git a/ax/generators/torch/tests/test_kernels.py b/ax/generators/torch/tests/test_kernels.py index 94463830642..9bc6d466668 100644 --- a/ax/generators/torch/tests/test_kernels.py +++ b/ax/generators/torch/tests/test_kernels.py @@ -63,9 +63,9 @@ def test_scalematern_kernel_active_dims(self) -> None: base_kernel = assert_is_instance(covar.base_kernel, MaternKernel) # active_dims lands on the inner MaternKernel, and the ScaleKernel # inherits it (so subsetting happens exactly once at the wrapper level). - # pyrefly: ignore [not-callable] + # pyrefly: ignore [missing-attribute, not-callable] self.assertEqual(covar.active_dims.tolist(), active_dims) - # pyrefly: ignore [not-callable] + # pyrefly: ignore [missing-attribute, not-callable] self.assertEqual(base_kernel.active_dims.tolist(), active_dims) self.assertEqual(base_kernel.ard_num_dims, len(active_dims)) # The kernel only consumes the active columns: perturbing an inactive @@ -121,11 +121,11 @@ def test_scale_rbf_linear_kernel_active_dims(self) -> None: rbf = assert_is_instance(scale_rbf.base_kernel, RBFKernel) # active_dims lands on both leaves, and the ScaleKernel inherits it # from the wrapped RBF kernel (so subsetting happens exactly once). - # pyrefly: ignore [not-callable] + # pyrefly: ignore [missing-attribute, not-callable] self.assertEqual(scale_rbf.active_dims.tolist(), active_dims) - # pyrefly: ignore [not-callable] + # pyrefly: ignore [missing-attribute, not-callable] self.assertEqual(rbf.active_dims.tolist(), active_dims) - # pyrefly: ignore [not-callable] + # pyrefly: ignore [missing-attribute, not-callable] self.assertEqual(linear.active_dims.tolist(), active_dims) # ard_num_dims matches the number of active dims. self.assertEqual(rbf.ard_num_dims, len(active_dims)) @@ -283,9 +283,9 @@ def test_default_kernel(self) -> None: self.assertIsNone(botorch_kernel.active_dims) else: self.assertEqual( - # pyrefly: ignore [not-callable] + # pyrefly: ignore [missing-attribute, not-callable] ax_kernel.active_dims.tolist(), - # pyrefly: ignore [not-callable] + # pyrefly: ignore [missing-attribute, not-callable] botorch_kernel.active_dims.tolist(), ) @@ -301,5 +301,5 @@ def test_default_mle(self) -> None: self.assertTrue((kernel.lengthscale == sqrt(2) / 10).all()) self.assertEqual(kernel.lengthscale.shape, torch.Size([3, 1, 2])) self.assertFalse(hasattr(kernel, "lengthscale_prior")) - # pyrefly: ignore [not-callable] + # pyrefly: ignore [missing-attribute, not-callable] self.assertEqual(kernel.active_dims.tolist(), active_dims) diff --git a/ax/plot/contour.py b/ax/plot/contour.py index 98806ab4b47..ec77888d914 100644 --- a/ax/plot/contour.py +++ b/ax/plot/contour.py @@ -580,7 +580,13 @@ def interact_contour_plotly( xbutton_data_args = {"x": [], "y": [], "z": []} for yvar in param_names: res = relativize_data( - f_dict[xvar][yvar], sd_dict[xvar][yvar], rel, arm_data, metric + # pyrefly: ignore [bad-argument-type] + f_dict[xvar][yvar], + # pyrefly: ignore [bad-argument-type] + sd_dict[xvar][yvar], + rel, + arm_data, + metric, ) f_final = res[0] sd_final = res[1] @@ -624,7 +630,9 @@ def interact_contour_plotly( { "xaxis.title": short_name(xvar), "xaxis2.title": short_name(xvar), + # pyrefly: ignore [bad-argument-type] "xaxis.range": axis_range(grid_dict[xvar], is_log_dict[xvar]), + # pyrefly: ignore [bad-argument-type] "xaxis2.range": axis_range(grid_dict[xvar], is_log_dict[xvar]), "xaxis.type": "log" if is_log_dict[xvar] else "linear", "xaxis2.type": "log" if is_log_dict[xvar] else "linear", @@ -649,10 +657,14 @@ def interact_contour_plotly( { "yaxis.title": short_name(y_param), "yaxis.range": axis_range( - grid_dict[y_param], is_log_dict[y_param] + # pyrefly: ignore [bad-argument-type] + grid_dict[y_param], + is_log_dict[y_param], ), "yaxis2.range": axis_range( - grid_dict[y_param], is_log_dict[y_param] + # pyrefly: ignore [bad-argument-type] + grid_dict[y_param], + is_log_dict[y_param], ), "yaxis.type": "log" if is_log_dict[y_param] else "linear", "yaxis2.type": "log" if is_log_dict[y_param] else "linear", @@ -785,7 +797,9 @@ def interact_contour_plotly( # Initially visible yvar yvar = param_names[1] + # pyrefly: ignore [bad-argument-type] xrange = axis_range(grid_dict[xvar], is_log_dict[xvar]) + # pyrefly: ignore [bad-argument-type] yrange = axis_range(grid_dict[yvar], is_log_dict[yvar]) xtype = "log" if is_log_dict[xvar] else "linear" diff --git a/ax/utils/stats/math_utils.py b/ax/utils/stats/math_utils.py index 6d8c6e44c6d..546aff4a918 100644 --- a/ax/utils/stats/math_utils.py +++ b/ax/utils/stats/math_utils.py @@ -165,6 +165,7 @@ def unrelativize( if bias_correction: m_t = m_t / (1 - (sem_c / abs_mean_c) ** 2) + # pyrefly: ignore [unsupported-operation] var = sems_t**2 c = m_t / mean_c s_t2 = var * (mean_c**2) + 2 * c * cov_means - (c**2) * (sem_c**2)