Skip to content

Commit d2c6f5e

Browse files
Balandatfacebook-github-bot
authored andcommitted
Switch code formatter to ruff (#2582)
Summary: Pull Request resolved: #2582 Use the ruff code formatter. This diff - Changes the Meta-internal config to use ruff. - Updates `pyproject.toml` to use ruff as the code formatter. - Applies the new formatting across the codebase. This does NOT change the code sorting engine (that is still usort). We can update that in a next step. Reviewed By: saitcakmak Differential Revision: D64517061 fbshipit-source-id: bf9a4ed258b9489fc757c810fe8bbff0a5d018c4
1 parent b672626 commit d2c6f5e

File tree

67 files changed

+40
-119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+40
-119
lines changed

botorch/acquisition/cached_cholesky.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
Abstract class for acquisition functions leveraging a cached Cholesky
99
decomposition of the posterior covariance over f(X_baseline).
1010
"""
11+
1112
from __future__ import annotations
1213

1314
import warnings

botorch/acquisition/fixed_feature.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ def __init__(
9393
if isinstance(values, Tensor):
9494
new_values = values.detach().clone()
9595
else:
96-
9796
dtype = get_dtype_of_sequence(values)
9897
device = get_device_of_sequence(values)
9998

botorch/acquisition/input_constructors.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,6 @@ def construct_inputs_qKG(
12581258
}
12591259

12601260
if with_current_value:
1261-
12621261
X = _get_dataset_field(training_data, "X", first_only=True)
12631262
_bounds = torch.as_tensor(bounds, dtype=X.dtype, device=X.device)
12641263

@@ -1868,7 +1867,6 @@ def _get_ref_point(
18681867
objective_thresholds: Tensor,
18691868
objective: MCMultiOutputObjective | None = None,
18701869
) -> Tensor:
1871-
18721870
if objective is None:
18731871
ref_point = objective_thresholds
18741872
elif isinstance(objective, RiskMeasureMCObjective):

botorch/acquisition/multi_objective/analytic.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
1717
"""
1818

19-
2019
from __future__ import annotations
2120

2221
from itertools import product

botorch/acquisition/multi_objective/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
Base classes for multi-objective acquisition functions.
99
"""
1010

11-
1211
from __future__ import annotations
1312

1413
from abc import ABC, abstractmethod

botorch/acquisition/multi_objective/joint_entropy_search.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
2022.
1616
1717
"""
18+
1819
from __future__ import annotations
1920

2021
from abc import abstractmethod

botorch/acquisition/multi_objective/logei.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
class qLogExpectedHypervolumeImprovement(
4949
MultiObjectiveMCAcquisitionFunction, SubsetIndexCachingMixin
5050
):
51-
5251
_log: bool = True
5352

5453
def __init__(
@@ -321,7 +320,6 @@ class qLogNoisyExpectedHypervolumeImprovement(
321320
NoisyExpectedHypervolumeMixin,
322321
qLogExpectedHypervolumeImprovement,
323322
):
324-
325323
_log: bool = True
326324

327325
def __init__(

botorch/acquisition/prior_guided.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
Augmenting Acquisition Functions with User Beliefs for Bayesian Optimization.
1616
ICLR 2022.
1717
"""
18+
1819
from __future__ import annotations
1920

2021
from botorch.acquisition.acquisition import AcquisitionFunction

botorch/exceptions/warnings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
r"""
88
Botorch Warnings.
99
"""
10+
1011
import warnings
1112

1213

botorch/generation/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
def _convert_nonlinear_inequality_constraints(
24-
nonlinear_inequality_constraints: list[Callable | tuple[Callable, bool]]
24+
nonlinear_inequality_constraints: list[Callable | tuple[Callable, bool]],
2525
) -> list[tuple[Callable, bool]]:
2626
"""Convert legacy defintions of nonlinear inequality constraints into the new
2727
format. Assumes intra-point constraints.

botorch/models/fully_bayesian.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
Seventh Conference on Uncertainty in Artificial Intelligence, 2021.
3131
"""
3232

33-
3433
import math
3534
from abc import abstractmethod
3635
from collections.abc import Mapping

botorch/models/fully_bayesian_multitask.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
# LICENSE file in the root directory of this source tree.
55

66

7-
r"""Multi-task Gaussian Process Regression models with fully Bayesian inference.
8-
"""
9-
7+
r"""Multi-task Gaussian Process Regression models with fully Bayesian inference."""
108

119
from collections.abc import Mapping
1210
from typing import Any, NoReturn

botorch/models/gp_regression_mixed.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ def __init__(
6464
train_Y: Tensor,
6565
cat_dims: list[int],
6666
train_Yvar: Tensor | None = None,
67-
cont_kernel_factory: None | (
68-
Callable[[torch.Size, int, list[int]], Kernel]
69-
) = None,
67+
cont_kernel_factory: None
68+
| (Callable[[torch.Size, int, list[int]], Kernel]) = None,
7069
likelihood: Likelihood | None = None,
7170
outcome_transform: OutcomeTransform | _DefaultType | None = DEFAULT,
7271
input_transform: InputTransform | None = None, # TODO

botorch/models/kernels/contextual_lcea.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ def _eval_context_covar(self) -> Tensor:
291291
else:
292292
context_outputscales = self.outputscale_list * self.context_weight
293293
context_covar = (
294-
(context_outputscales.unsqueeze(-2)) # (ns) x 1 x num_contexts
294+
(context_outputscales.unsqueeze(-2))
295+
# (ns) x 1 x num_contexts
295296
.mul(context_covar)
296297
.mul(context_outputscales.unsqueeze(-1)) # (ns) x num_contexts x 1
297298
)

botorch/models/transforms/input.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
is typically part of a Model and applied within the model.forward()
1414
method.
1515
"""
16+
1617
from __future__ import annotations
1718

1819
from abc import ABC, abstractmethod

botorch/optim/initializers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
surrogates and dynamic coordinate search in high-dimensional
1313
expensive black-box optimization, Engineering Optimization, 2013.
1414
"""
15+
1516
from __future__ import annotations
1617

1718
import warnings

botorch/optim/parameter_constraints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ def _generate_unfixed_nonlin_constraints(
396396
values = torch.tensor(list(fixed_features.values()), dtype=torch.double)
397397

398398
def _wrap_nonlin_constraint(
399-
constraint: Callable[[Tensor], Tensor]
399+
constraint: Callable[[Tensor], Tensor],
400400
) -> Callable[[Tensor], Tensor]:
401401
def new_nonlin_constraint(X: Tensor) -> Tensor:
402402
ivalues = values.to(X).expand(*X.shape[:-1], len(fixed_features))

botorch/optim/utils/timeout.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def minimize_with_timeout(
4242
track of the runtime and the optimization variables at the current iteration.
4343
"""
4444
if timeout_sec is not None:
45-
4645
start_time = time.monotonic()
4746
callback_data = {"num_iterations": 0} # update from withing callback below
4847

botorch/posteriors/ensemble.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ def variance(self) -> Tensor:
6868
return self.values.var(dim=-3)
6969

7070
def _extended_shape(
71-
self, sample_shape: torch.Size = torch.Size() # noqa: B008
71+
self,
72+
sample_shape: torch.Size = torch.Size(), # noqa: B008
7273
) -> torch.Size:
7374
r"""Returns the shape of the samples produced by the posterior with
7475
the given `sample_shape`.

botorch/posteriors/gpytorch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ def batch_range(self) -> tuple[int, int]:
7272
return (0, -1)
7373

7474
def _extended_shape(
75-
self, sample_shape: torch.Size = torch.Size() # noqa: B008
75+
self,
76+
sample_shape: torch.Size = torch.Size(), # noqa: B008
7677
) -> torch.Size:
7778
r"""Returns the shape of the samples produced by the posterior with
7879
the given `sample_shape`.

botorch/posteriors/higher_order.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ def batch_range(self) -> tuple[int, int]:
8787
return (0, -1)
8888

8989
def _extended_shape(
90-
self, sample_shape: torch.Size = torch.Size() # noqa: B008
90+
self,
91+
sample_shape: torch.Size = torch.Size(), # noqa: B008
9192
) -> torch.Size:
9293
r"""Returns the shape of the samples produced by the posterior with
9394
the given `sample_shape`.

botorch/posteriors/posterior.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ def density(self, value: Tensor) -> Tensor:
108108
) # pragma: no cover
109109

110110
def _extended_shape(
111-
self, sample_shape: torch.Size = torch.Size() # noqa: B008
111+
self,
112+
sample_shape: torch.Size = torch.Size(), # noqa: B008
112113
) -> torch.Size:
113114
r"""Returns the shape of the samples produced by the posterior with
114115
the given `sample_shape`.

botorch/posteriors/posterior_list.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ def dtype(self) -> torch.dtype:
108108
return next(iter(dtypes))
109109

110110
def _extended_shape(
111-
self, sample_shape: torch.Size = torch.Size() # noqa: B008
111+
self,
112+
sample_shape: torch.Size = torch.Size(), # noqa: B008
112113
) -> torch.Size:
113114
r"""Returns the shape of the samples produced by the posterior with
114115
the given `sample_shape`.

botorch/posteriors/torch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ def density(self, value: Tensor) -> Tensor:
113113
return self.log_prob(value).exp()
114114

115115
def _extended_shape(
116-
self, sample_shape: torch.Size = torch.Size() # noqa: B008
116+
self,
117+
sample_shape: torch.Size = torch.Size(), # noqa: B008
117118
) -> torch.Size:
118119
r"""Returns the shape of the samples produced by the distribution with
119120
the given `sample_shape`.

botorch/posteriors/transformed.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ def dtype(self) -> torch.dtype:
7070
return self._posterior.dtype
7171

7272
def _extended_shape(
73-
self, sample_shape: torch.Size = torch.Size() # noqa: B008
73+
self,
74+
sample_shape: torch.Size = torch.Size(), # noqa: B008
7475
) -> torch.Size:
7576
r"""Returns the shape of the samples produced by the posterior with
7677
the given `sample_shape`.

botorch/sampling/pathwise/prior_samplers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def _draw_kernel_feature_paths_fallback(
6262
output_transform: TOutputTransform | None = None,
6363
weight_generator: Callable[[Size], Tensor] | None = None,
6464
) -> GeneralizedLinearPath:
65-
6665
# Generate a kernel feature map
6766
feature_map = map_generator(
6867
kernel=covar_module,

botorch/test_functions/multi_objective.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,6 @@ def evaluate_slack_true(self, X: Tensor) -> Tensor:
12671267

12681268

12691269
class C2DTLZ2(DTLZ2, ConstrainedBaseTestProblem):
1270-
12711270
num_constraints = 1
12721271
_r = 0.2
12731272
# approximate from nsga-ii, TODO: replace with analytic

botorch/test_functions/synthetic.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ def evaluate_true(self, X: Tensor) -> Tensor:
163163

164164

165165
class Beale(SyntheticTestFunction):
166-
167166
dim = 2
168167
_optimal_value = 0.0
169168
_bounds = [(-4.5, 4.5), (-4.5, 4.5)]
@@ -207,7 +206,6 @@ def evaluate_true(self, X: Tensor) -> Tensor:
207206

208207

209208
class Bukin(SyntheticTestFunction):
210-
211209
dim = 2
212210
_bounds = [(-15.0, -5.0), (-3.0, 3.0)]
213211
_optimal_value = 0.0
@@ -241,7 +239,6 @@ def evaluate_true(self, X: Tensor) -> Tensor:
241239

242240

243241
class DropWave(SyntheticTestFunction):
244-
245242
dim = 2
246243
_bounds = [(-5.12, 5.12), (-5.12, 5.12)]
247244
_optimal_value = -1.0
@@ -256,7 +253,6 @@ def evaluate_true(self, X: Tensor) -> Tensor:
256253

257254

258255
class DixonPrice(SyntheticTestFunction):
259-
260256
_optimal_value = 0.0
261257

262258
def __init__(
@@ -639,7 +635,6 @@ def evaluate_true(self, X: Tensor) -> Tensor:
639635

640636

641637
class Rastrigin(SyntheticTestFunction):
642-
643638
_optimal_value = 0.0
644639

645640
def __init__(
@@ -764,7 +759,6 @@ def evaluate_true(self, X: Tensor) -> Tensor:
764759

765760

766761
class SixHumpCamel(SyntheticTestFunction):
767-
768762
dim = 2
769763
_bounds = [(-3.0, 3.0), (-2.0, 2.0)]
770764
_optimal_value = -1.0316
@@ -815,7 +809,6 @@ def evaluate_true(self, X: Tensor) -> Tensor:
815809

816810

817811
class ThreeHumpCamel(SyntheticTestFunction):
818-
819812
dim = 2
820813
_bounds = [(-5.0, 5.0), (-5.0, 5.0)]
821814
_optimal_value = 0.0

botorch/test_utils/mock.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
Utilities for speeding up optimization in tests.
99
1010
"""
11+
1112
from __future__ import annotations
1213

1314
from collections.abc import Generator

botorch/utils/constraints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
def get_outcome_constraint_transforms(
22-
outcome_constraints: tuple[Tensor, Tensor] | None
22+
outcome_constraints: tuple[Tensor, Tensor] | None,
2323
) -> list[Callable[[Tensor], Tensor]] | None:
2424
r"""Create outcome constraint callables from outcome constraint tensors.
2525

botorch/utils/multi_objective/box_decompositions/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
r"""Utilities for box decomposition algorithms."""
88

9-
109
import torch
1110
from botorch.exceptions.errors import BotorchTensorDimensionError, UnsupportedError
1211
from botorch.utils.multi_objective.pareto import is_non_dominated

botorch/utils/multi_objective/scalarization.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
for expensive multiobjective optimization problems," in IEEE Transactions
1515
on Evolutionary Computation, vol. 10, no. 1, pp. 50-66, Feb. 2006.
1616
"""
17+
1718
from __future__ import annotations
1819

1920
from collections.abc import Callable

botorch/utils/test_helpers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040

4141

4242
def _get_mcmc_samples(num_samples: int, dim: int, infer_noise: bool, **tkwargs):
43-
4443
mcmc_samples = {
4544
"lengthscale": 1 + torch.rand(num_samples, 1, dim, **tkwargs),
4645
"outputscale": 1 + torch.rand(num_samples, **tkwargs),

botorch/utils/testing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ def batch_shape(self) -> torch.Size:
277277
raise NotImplementedError # pragma: no cover
278278

279279
def _extended_shape(
280-
self, sample_shape: torch.Size = torch.Size() # noqa: B008
280+
self,
281+
sample_shape: torch.Size = torch.Size(), # noqa: B008
281282
) -> torch.Size:
282283
return sample_shape + self.base_sample_shape
283284

botorch/utils/transforms.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ def decorator(
269269
def decorated(
270270
acqf: AcquisitionFunction, X: Any, *args: Any, **kwargs: Any
271271
) -> Any:
272-
273272
# Allow using acquisition functions for other inputs (e.g. lists of strings)
274273
if not isinstance(X, Tensor):
275274
return method(acqf, X, *args, **kwargs)
@@ -311,7 +310,7 @@ def decorated(
311310

312311

313312
def concatenate_pending_points(
314-
method: Callable[[Any, Tensor], Any]
313+
method: Callable[[Any, Tensor], Any],
315314
) -> Callable[[Any, Tensor], Any]:
316315
r"""Decorator concatenating X_pending into an acquisition function's argument.
317316

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ write_to = "./botorch/version.py"
88

99
[tool.usort]
1010
first_party_detection = false
11+
12+
[tool.ufmt]
13+
formatter = "ruff-api"

test/acquisition/multi_objective/test_hypervolume_knowledge_gradient.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,7 @@ def test_evaluate_q_hvkg(self):
370370
ModelListGP, "fantasize", return_value=mfm
371371
) as patch_f, mock.patch(
372372
NO, new_callable=mock.PropertyMock
373-
) as mock_num_outputs, warnings.catch_warnings(
374-
record=True
375-
) as ws:
373+
) as mock_num_outputs, warnings.catch_warnings(record=True) as ws:
376374
mock_num_outputs.return_value = 3
377375
qHVKG = acqf_class(
378376
model=model,

0 commit comments

Comments
 (0)