Skip to content

Commit

Permalink
apply import merging for fbcode/pytorch/botorch (1 of 1) (#1166)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #1166

Applies new import merging and sorting from µsort v1.0.

When merging imports, µsort will make a best-effort to move associated
comments to match merged elements, but there are known limitations due to
the diynamic nature of Python and developer tooling. These changes should
not produce any dangerous runtime changes, but may require touch-ups to
satisfy linters and other tooling.

Note that µsort uses case-insensitive, lexicographical sorting, which
results in a different ordering compared to isort. This provides a more
consistent sorting order, matching the case-insensitive order used when
sorting import statements by module name, and ensures that "frog", "FROG",
and "Frog" always sort next to each other.

For details on µsort's sorting and merging semantics, see the user guide:
https://usort.readthedocs.io/en/stable/guide.html#sorting

Reviewed By: Balandat

Differential Revision: D35552838

fbshipit-source-id: 897b1e7d532b3b2fb8f3e0eb747f394efa5825fb
  • Loading branch information
thatch authored and facebook-github-bot committed Apr 12, 2022
1 parent 13755e6 commit e5391cf
Show file tree
Hide file tree
Showing 27 changed files with 38 additions and 45 deletions.
2 changes: 1 addition & 1 deletion botorch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
test_functions,
)
from botorch.cross_validation import batch_cross_validation
from botorch.fit import fit_gpytorch_model, fit_fully_bayesian_model_nuts
from botorch.fit import fit_fully_bayesian_model_nuts, fit_gpytorch_model
from botorch.generation.gen import (
gen_candidates_scipy,
gen_candidates_torch,
Expand Down
2 changes: 1 addition & 1 deletion botorch/acquisition/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
OneShotAcquisitionFunction,
)
from botorch.acquisition.active_learning import (
qNegIntegratedPosteriorVariance,
PairwiseMCPosteriorVariance,
qNegIntegratedPosteriorVariance,
)
from botorch.acquisition.analytic import (
AnalyticAcquisitionFunction,
Expand Down
2 changes: 1 addition & 1 deletion botorch/acquisition/acquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import warnings
from abc import ABC, abstractmethod
from typing import Optional, Callable
from typing import Callable, Optional

from botorch.exceptions import BotorchWarning, UnsupportedError
from botorch.models.model import Model
Expand Down
4 changes: 2 additions & 2 deletions botorch/acquisition/cached_cholesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from botorch.exceptions.warnings import BotorchWarning
from botorch.models import HigherOrderGP
from botorch.models.deterministic import DeterministicModel
from botorch.models.model import ModelList, Model
from botorch.models.model import Model, ModelList
from botorch.models.multitask import KroneckerMultiTaskGP, MultiTaskGP
from botorch.posteriors.gpytorch import GPyTorchPosterior
from botorch.posteriors.posterior import Posterior
Expand All @@ -29,7 +29,7 @@
from gpytorch.distributions.multitask_multivariate_normal import (
MultitaskMultivariateNormal,
)
from gpytorch.utils.errors import NotPSDError, NanError
from gpytorch.utils.errors import NanError, NotPSDError
from torch import Tensor


Expand Down
2 changes: 1 addition & 1 deletion botorch/acquisition/input_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
AcquisitionObjective,
IdentityMCObjective,
MCAcquisitionObjective,
ScalarizedObjective,
PosteriorTransform,
ScalarizedObjective,
ScalarizedPosteriorTransform,
)
from botorch.acquisition.utils import (
Expand Down
5 changes: 1 addition & 4 deletions botorch/acquisition/knowledge_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@
from botorch.acquisition.analytic import PosteriorMean
from botorch.acquisition.cost_aware import CostAwareUtility
from botorch.acquisition.monte_carlo import MCAcquisitionFunction, qSimpleRegret
from botorch.acquisition.objective import (
MCAcquisitionObjective,
PosteriorTransform,
)
from botorch.acquisition.objective import MCAcquisitionObjective, PosteriorTransform
from botorch.exceptions.errors import UnsupportedError
from botorch.models.model import Model
from botorch.sampling.samplers import MCSampler, SobolQMCNormalSampler
Expand Down
6 changes: 2 additions & 4 deletions botorch/acquisition/multi_objective/monte_carlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
from typing import Any, Callable, List, Optional, Union

import torch
from botorch.acquisition.acquisition import (
AcquisitionFunction,
)
from botorch.acquisition.acquisition import AcquisitionFunction
from botorch.acquisition.cached_cholesky import CachedCholeskyMCAcquisitionFunction
from botorch.acquisition.multi_objective.objective import (
IdentityMCMultiOutputObjective,
Expand Down Expand Up @@ -65,10 +63,10 @@
from botorch.utils.torch import BufferDict
from botorch.utils.transforms import (
concatenate_pending_points,
is_fully_bayesian,
match_batch_shape,
t_batch_mode_transform,
)
from botorch.utils.transforms import is_fully_bayesian
from torch import Tensor


Expand Down
5 changes: 1 addition & 4 deletions botorch/acquisition/multi_step_lookahead.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
from botorch.acquisition import AcquisitionFunction, OneShotAcquisitionFunction
from botorch.acquisition.analytic import AnalyticAcquisitionFunction, PosteriorMean
from botorch.acquisition.monte_carlo import MCAcquisitionFunction
from botorch.acquisition.objective import (
MCAcquisitionObjective,
PosteriorTransform,
)
from botorch.acquisition.objective import MCAcquisitionObjective, PosteriorTransform
from botorch.exceptions.errors import UnsupportedError
from botorch.exceptions.warnings import BotorchWarning
from botorch.models.model import Model
Expand Down
2 changes: 1 addition & 1 deletion botorch/generation/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import torch
from botorch.acquisition.acquisition import AcquisitionFunction
from botorch.acquisition.objective import (
MCAcquisitionObjective,
IdentityMCObjective,
MCAcquisitionObjective,
PosteriorTransform,
ScalarizedPosteriorTransform,
)
Expand Down
2 changes: 1 addition & 1 deletion botorch/models/fully_bayesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import pyro
import torch
from botorch.acquisition.objective import PosteriorTransform
from botorch.models.gp_regression import SingleTaskGP, FixedNoiseGP
from botorch.models.gp_regression import FixedNoiseGP, SingleTaskGP
from botorch.models.transforms.input import InputTransform
from botorch.models.transforms.outcome import OutcomeTransform
from botorch.models.utils import validate_input_scaling
Expand Down
2 changes: 1 addition & 1 deletion botorch/models/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from abc import ABC, abstractmethod
from collections import defaultdict
from copy import deepcopy
from typing import Any, Dict, List, Optional, Callable
from typing import Any, Callable, Dict, List, Optional

import numpy as np
import torch
Expand Down
2 changes: 1 addition & 1 deletion botorch/utils/low_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from gpytorch.lazy import BlockDiagLazyTensor
from gpytorch.lazy.lazy_tensor import LazyTensor
from gpytorch.utils.cholesky import psd_safe_cholesky
from gpytorch.utils.errors import NotPSDError, NanError
from gpytorch.utils.errors import NanError, NotPSDError
from torch import Tensor


Expand Down
2 changes: 1 addition & 1 deletion test/acquisition/multi_objective/test_monte_carlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
NondominatedPartitioning,
)
from botorch.utils.testing import BotorchTestCase, MockModel, MockPosterior
from botorch.utils.transforms import standardize, match_batch_shape
from botorch.utils.transforms import match_batch_shape, standardize


class DummyMultiObjectiveMCAcquisitionFunction(MultiObjectiveMCAcquisitionFunction):
Expand Down
8 changes: 5 additions & 3 deletions test/acquisition/test_active_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
from unittest import mock

import torch
from botorch.acquisition.active_learning import PairwiseMCPosteriorVariance
from botorch.acquisition.active_learning import qNegIntegratedPosteriorVariance
from botorch.acquisition.active_learning import (
PairwiseMCPosteriorVariance,
qNegIntegratedPosteriorVariance,
)
from botorch.acquisition.objective import (
GenericMCObjective,
IdentityMCObjective,
ScalarizedPosteriorTransform,
GenericMCObjective,
)
from botorch.exceptions.errors import UnsupportedError
from botorch.models.pairwise_gp import PairwiseGP
Expand Down
2 changes: 1 addition & 1 deletion test/acquisition/test_analytic.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
)
from botorch.acquisition.objective import (
IdentityMCObjective,
ScalarizedPosteriorTransform,
ScalarizedObjective,
ScalarizedPosteriorTransform,
)
from botorch.exceptions import UnsupportedError
from botorch.models import FixedNoiseGP, SingleTaskGP
Expand Down
2 changes: 1 addition & 1 deletion test/acquisition/test_cached_cholesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from botorch.models.higher_order_gp import HigherOrderGP
from botorch.sampling.samplers import IIDNormalSampler
from botorch.utils.low_rank import extract_batch_covar
from botorch.utils.testing import MockPosterior, MockModel, BotorchTestCase
from botorch.utils.testing import BotorchTestCase, MockModel, MockPosterior
from gpytorch.utils.errors import NanError, NotPSDError

CHOLESKY_PATH = "gpytorch.lazy.lazy_tensor.psd_safe_cholesky"
Expand Down
2 changes: 1 addition & 1 deletion test/acquisition/test_input_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
)
from botorch.acquisition.fixed_feature import FixedFeatureAcquisitionFunction
from botorch.acquisition.input_constructors import (
_deprecate_objective_arg,
acqf_input_constructor,
construct_inputs_mf_base,
get_acqf_input_constructor,
get_best_f_analytic,
get_best_f_mc,
_deprecate_objective_arg,
)
from botorch.acquisition.knowledge_gradient import (
qKnowledgeGradient,
Expand Down
4 changes: 2 additions & 2 deletions test/acquisition/test_max_value_entropy_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

from typing import Optional, Callable
from typing import Callable, Optional
from unittest import mock

import torch
Expand All @@ -17,8 +17,8 @@
qMultiFidelityMaxValueEntropy,
)
from botorch.acquisition.objective import (
ScalarizedPosteriorTransform,
PosteriorTransform,
ScalarizedPosteriorTransform,
)
from botorch.exceptions.errors import UnsupportedError
from botorch.posteriors import GPyTorchPosterior
Expand Down
2 changes: 1 addition & 1 deletion test/acquisition/test_monte_carlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
qUpperConfidenceBound,
)
from botorch.acquisition.objective import (
ScalarizedPosteriorTransform,
GenericMCObjective,
PosteriorTransform,
ScalarizedPosteriorTransform,
)
from botorch.exceptions import BotorchWarning, UnsupportedError
from botorch.models import SingleTaskGP
Expand Down
2 changes: 1 addition & 1 deletion test/acquisition/test_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from botorch.models.pairwise_gp import PairwiseGP
from botorch.sampling.samplers import SobolQMCNormalSampler
from botorch.utils import apply_constraints
from botorch.utils.testing import BotorchTestCase, _get_test_posterior
from botorch.utils.testing import _get_test_posterior, BotorchTestCase
from torch import Tensor


Expand Down
4 changes: 2 additions & 2 deletions test/acquisition/test_proximal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from typing import Any, Dict, List

import torch
from botorch.acquisition import ScalarizedObjective, LinearMCObjective
from botorch.acquisition import LinearMCObjective, ScalarizedObjective
from botorch.acquisition.acquisition import AcquisitionFunction
from botorch.acquisition.analytic import ExpectedImprovement
from botorch.acquisition.monte_carlo import qExpectedImprovement
from botorch.acquisition.proximal import ProximalAcquisitionFunction
from botorch.exceptions.errors import UnsupportedError
from botorch.models import SingleTaskGP, ModelListGP
from botorch.models import ModelListGP, SingleTaskGP
from botorch.models.gpytorch import GPyTorchModel
from botorch.models.model import Model
from botorch.models.transforms.input import Normalize
Expand Down
2 changes: 1 addition & 1 deletion test/models/test_deterministic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from botorch.models.deterministic import (
AffineDeterministicModel,
DeterministicModel,
FixedSingleSampleModel,
GenericDeterministicModel,
PosteriorMeanModel,
FixedSingleSampleModel,
)
from botorch.models.gp_regression import SingleTaskGP
from botorch.models.transforms.input import Normalize
Expand Down
8 changes: 4 additions & 4 deletions test/models/test_fully_bayesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
qUpperConfidenceBound,
)
from botorch.acquisition.multi_objective import (
qNoisyExpectedHypervolumeImprovement,
qExpectedHypervolumeImprovement,
qNoisyExpectedHypervolumeImprovement,
)
from botorch.models import ModelListGP
from botorch.models.fully_bayesian import (
SaasFullyBayesianSingleTaskGP,
SaasPyroModel,
MIN_INFERRED_NOISE_LEVEL,
PyroModel,
SaasFullyBayesianSingleTaskGP,
SaasPyroModel,
)
from botorch.models.transforms import Normalize, Standardize
from botorch.posteriors import FullyBayesianPosterior
Expand All @@ -42,7 +42,7 @@
)
from botorch.utils.testing import BotorchTestCase
from gpytorch.kernels import MaternKernel, ScaleKernel
from gpytorch.likelihoods import GaussianLikelihood, FixedNoiseGaussianLikelihood
from gpytorch.likelihoods import FixedNoiseGaussianLikelihood, GaussianLikelihood
from gpytorch.means import ConstantMean


Expand Down
3 changes: 1 addition & 2 deletions test/models/test_gp_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
GaussianLikelihood,
HeteroskedasticNoise,
)
from gpytorch.means import ConstantMean
from gpytorch.means import ZeroMean
from gpytorch.means import ConstantMean, ZeroMean
from gpytorch.mlls.exact_marginal_log_likelihood import ExactMarginalLogLikelihood
from gpytorch.mlls.noise_model_added_loss_term import NoiseModelAddedLossTerm
from gpytorch.priors import GammaPrior
Expand Down
2 changes: 1 addition & 1 deletion test/optim/test_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from botorch.optim.optimize import (
_filter_infeasible,
_filter_invalid,
_generate_neighbors,
_gen_batch_initial_conditions_local_search,
_generate_neighbors,
optimize_acqf,
optimize_acqf_cyclic,
optimize_acqf_discrete,
Expand Down
2 changes: 1 addition & 1 deletion test/test_functions/test_multi_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
CarSideImpact,
CONSTR,
ConstrainedBraninCurrin,
DiscBrake,
DH1,
DH2,
DH3,
DH4,
DiscBrake,
DTLZ1,
DTLZ2,
DTLZ3,
Expand Down
2 changes: 1 addition & 1 deletion test/utils/test_low_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)
from gpytorch.lazy import lazify
from gpytorch.lazy.block_diag_lazy_tensor import BlockDiagLazyTensor
from gpytorch.utils.errors import NotPSDError, NanError
from gpytorch.utils.errors import NanError, NotPSDError


class TestExtractBatchCovar(BotorchTestCase):
Expand Down

0 comments on commit e5391cf

Please sign in to comment.