Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update black #861

Merged
merged 1 commit into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/orion/algo/asha.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def compute_budgets(
for bracket_ressources in ressources:
bracket_budgets = []
for i, min_ressources in enumerate(bracket_ressources[::-1]):
budget = (reduction_factor ** i, min_ressources)
budget = (reduction_factor**i, min_ressources)
bracket_budgets.append(budget)
budgets_tab[len(bracket_ressources) - i - 1].append(budget)
budgets.append(bracket_budgets[::-1])
Expand Down
4 changes: 2 additions & 2 deletions src/orion/algo/evolution_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def compute_budgets(
num_brackets - bracket_id
)
for i in range(0, num_brackets - bracket_id + 1):
n_i = int(num_trials / reduction_factor ** i)
min_i = int(min_resources * reduction_factor ** i)
n_i = int(num_trials / reduction_factor**i)
min_i = int(min_resources * reduction_factor**i)
bracket_budgets.append((n_i, min_i))

if budgets_tab.get(i):
Expand Down
4 changes: 2 additions & 2 deletions src/orion/algo/hyperband.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def compute_budgets(max_resources, reduction_factor):

min_resources = max_resources / reduction_factor ** (num_brackets - bracket_id)
for i in range(0, num_brackets - bracket_id + 1):
n_i = int(num_trials / reduction_factor ** i)
min_i = int(min_resources * reduction_factor ** i)
n_i = int(num_trials / reduction_factor**i)
min_i = int(min_resources * reduction_factor**i)
bracket_budgets.append((n_i, min_i))

if budgets_tab.get(i):
Expand Down
2 changes: 1 addition & 1 deletion src/orion/analysis/lpi_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def lpi(
results = numpy.zeros((n_runs, len(flattened_space)))
for i in range(n_runs):
trained_model = train_regressor(
model, data, random_state=rng.randint(2 ** 32 - 1), **kwargs
model, data, random_state=rng.randint(2**32 - 1), **kwargs
)
results[i] = modes[mode](best_point, flattened_space, trained_model, n_points)

Expand Down
2 changes: 1 addition & 1 deletion src/orion/benchmark/task/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __call__(self, *args, **kwargs):

@property
def max_trials(self) -> int:
"""Return the max number of trials to run for the task. """
"""Return the max number of trials to run for the task."""
return self._max_trials

@abstractmethod
Expand Down
2 changes: 1 addition & 1 deletion src/orion/benchmark/task/profet/forrester.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


class ProfetForresterTask(ProfetTask):
"""Simulated Task consisting in training a model on a variant of the Forrester function. """
"""Simulated Task consisting in training a model on a variant of the Forrester function."""

@dataclass
class ModelConfig(ProfetTask.ModelConfig):
Expand Down
4 changes: 2 additions & 2 deletions src/orion/benchmark/task/profet/profet_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def make_reproducible(seed: int):
with torch.random.fork_rng():
# Set the random state, using the given seed.
random.seed(seed)
np_seed = random.randint(0, 2 ** 32 - 1)
np_seed = random.randint(0, 2**32 - 1)
np.random.seed(np_seed)

torch_seed = random.randint(0, 2 ** 32 - 1)
torch_seed = random.randint(0, 2**32 - 1)
torch.random.manual_seed(torch_seed)
if torch.cuda.is_available():
torch.cuda.manual_seed_all(torch_seed)
Expand Down
2 changes: 1 addition & 1 deletion src/orion/testing/evc.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def build_root_experiment(space=None, trials=None):
if space is None:
space = {"x": "uniform(0, 100)", "y": "uniform(0, 100)", "z": "uniform(0, 100)"}
if trials is None:
trials = [{"x": i, "y": i * 2, "z": i ** 2} for i in range(4)]
trials = [{"x": i, "y": i * 2, "z": i**2} for i in range(4)]

root = build_experiment(name="root", max_trials=len(trials), space=space)

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/algos/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def rosenbrock(x, noise=None):
z *= random.gauss(0, noise)

return [
{"name": "objective", "type": "objective", "value": 4 * z ** 2 + 23.4},
{"name": "objective", "type": "objective", "value": 4 * z**2 + 23.4},
{"name": "gradient", "type": "gradient", "value": [8 * z]},
]

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/backward_compatibility/black_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def function(x, noise):
"""Evaluate partial information of a quadratic."""
z = (x - 34.56789) * random.gauss(0, noise)
return 4 * z ** 2 + 23.4, 8 * z
return 4 * z**2 + 23.4, 8 * z


def execute():
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/backward_compatibility/test_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
def function(x):
"""Evaluate partial information of a quadratic."""
z = x - 34.56789
return [dict(name="example_objective", type="objective", value=4 * z ** 2 + 23.4)]
return [dict(name="example_objective", type="objective", value=4 * z**2 + 23.4)]


def get_branch_argument(version):
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/benchmark/test_benchmark_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, max_trials=20):

def call(self, x):

y = (2 * x ** 4 + x ** 2 + 2) / (x ** 4 + 1)
y = (2 * x**4 + x**2 + 2) / (x**4 + 1)

return [dict(name="birdlike", type="objective", value=y)]

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/branching/black_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def function(x):
"""Evaluate partial information of a quadratic."""
y = x - 34.56789
return 4 * y ** 2 + 23.4, 8 * y
return 4 * y**2 + 23.4, 8 * y


def execute():
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/branching/black_box_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def function(x):
"""Evaluate partial information of a quadratic."""
y = x - 34.56789
return 4 * y ** 2 + 23.4, 8 * y
return 4 * y**2 + 23.4, 8 * y


def execute():
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/branching/black_box_with_y.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def function(x, y):
"""Evaluate partial information of a quadratic."""
y = x + y - 34.56789
return 4 * y ** 2 + 23.4, 8 * y
return 4 * y**2 + 23.4, 8 * y


def execute():
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/branching/black_box_with_z.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def function(x, z):
"""Evaluate partial information of a quadratic."""
y = x + z - 34.56789
return 4 * y ** 2 + 23.4, 8 * y
return 4 * y**2 + 23.4, 8 * y


def execute():
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/commands/black_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def function(x):
"""Evaluate partial information of a quadratic."""
z = x - 34.56789
return 4 * z ** 2 + 23.4, 8 * z
return 4 * z**2 + 23.4, 8 * z


def execute():
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/demo/black_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def function(x):
"""Evaluate partial information of a quadratic."""
z = x - 34.56789
return 4 * z ** 2 + 23.4, 8 * z
return 4 * z**2 + 23.4, 8 * z


def execute():
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/demo/black_box_w_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def function(x):
"""Evaluate partial information of a quadratic."""
z = x - 34.56789
return 4 * z ** 2 + 23.4, 8 * z
return 4 * z**2 + 23.4, 8 * z


def execute():
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/demo/black_box_w_config_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def function(x):
"""Evaluate partial information of a quadratic."""
z = x - 34.56789
return 4 * z ** 2 + 23.4, 8 * z
return 4 * z**2 + 23.4, 8 * z


def execute():
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/demo/dir_per_trial.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def function(x):
"""Evaluate partial information of a quadratic."""
z = x - 34.56789168765984988448213179176
return 4 * z ** 2 + 23.4, 8 * z
return 4 * z**2 + 23.4, 8 * z


def execute():
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/storage/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def foo(x, sleep_time):
keys = ["net_in", "net_out"]
MongoStat = namedtuple("MongoStat", keys)

order_values = dict(b=1 / 1000.0, k=1, m=1000, g=1000 ** 2)
order_values = dict(b=1 / 1000.0, k=1, m=1000, g=1000**2)


def _convert_str_size(size):
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/algo/pbt/test_pbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_base_1(self):
assert compute_fidelities(10, 10, 20, 1) == list(map(float, range(10, 21)))

def test_other_bases(self):
assert compute_fidelities(9, 2, 2 ** 10, 2) == [2 ** i for i in range(1, 11)]
assert compute_fidelities(9, 2, 2**10, 2) == [2**i for i in range(1, 11)]


class TestPBTObserve:
Expand Down
8 changes: 4 additions & 4 deletions tests/unittests/algo/test_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,13 @@ def test_basic_cardinality(self):
("reciprocal", 1e-4, 1e-2, 2, 90 * 2 + 1),
("reciprocal", 1e-5, 1e-2, 2, 90 + 90 * 2 + 1),
("reciprocal", 5.234e-3, 1.5908e-2, 2, (90 - 52) + 15 + 1),
("reciprocal", 5.234e-3, 1.5908e-2, 4, (9 * 10 ** 3 - 5234) + 1590 + 1),
("reciprocal", 5.234e-3, 1.5908e-2, 4, (9 * 10**3 - 5234) + 1590 + 1),
(
"reciprocal",
5.234e-5,
1.5908e-2,
4,
(9 * 10 ** 3 * 3 - 5234) + 1590 + 1,
(9 * 10**3 * 3 - 5234) + 1590 + 1,
),
("uniform", 1e-5, 1e-2, 2, np.inf),
("uniform", -3, 4, 3, np.inf),
Expand Down Expand Up @@ -885,11 +885,11 @@ def test_cardinality(self):
dim = Fidelity("epoch", 1, 9, 3)
space.register(dim)

assert space.cardinality == (4 ** 2) * (6 + 1) * 1
assert space.cardinality == (4**2) * (6 + 1) * 1

dim = Integer("yolo3", "uniform", -3, 2, shape=(3, 2))
space.register(dim)
assert space.cardinality == (4 ** 2) * (6 + 1) * 1 * ((2 + 1) ** (3 * 2))
assert space.cardinality == (4**2) * (6 + 1) * 1 * ((2 + 1) ** (3 * 2))

dim = Real("yolo4", "norm", 0.9)
space.register(dim)
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/core/evc/test_experiment_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
}


CHILD_TRIALS_DUPLICATES = [{"x": i, "y": i * 2, "z": i ** 2} for i in range(2, 8)]
CHILD_TRIALS_DUPLICATES = [{"x": i, "y": i * 2, "z": i**2} for i in range(2, 8)]

GRAND_CHILD_TRIALS_DUPLICATES = [
{"x": i, "y": i * 2, "z": i ** 2} for i in list(range(1, 4)) + list(range(8, 10))
{"x": i, "y": i * 2, "z": i**2} for i in list(range(1, 4)) + list(range(8, 10))
]


Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/core/io/test_orion_cmdline_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class WeirdArgument(NamedTuple):
]
)
def prior_and_prior_type_and_value(request):
""" Fixture that gives a prior str, the prior type, and a value. """
"""Fixture that gives a prior str, the prior type, and a value."""
prior_str, prior_type, value = request.param
return prior_str, prior_type, value

Expand All @@ -67,7 +67,7 @@ def prior_and_prior_type_and_value(request):
]
)
def weird_argument(request, prior_and_prior_type_and_value: Tuple[str, str, str]):
""" Fixture that provides a weird name, along with a prior and value. """
"""Fixture that provides a weird name, along with a prior and value."""
weird_param_name = request.param
prior_str, prior_type, value = prior_and_prior_type_and_value
return WeirdArgument(
Expand Down
8 changes: 4 additions & 4 deletions tests/unittests/core/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1322,22 +1322,22 @@ def test_capacity(self, space_each_type):
dim = Integer("yolo2", "uniform", -3, 6)
space.register(dim)
tspace = build_required_space(space, type_requirement="integer")
assert tspace.cardinality == (4 ** 2) * (6 + 1)
assert tspace.cardinality == (4**2) * (6 + 1)

dim = Integer("yolo3", "uniform", -3, 6, shape=(2, 1))
space.register(dim)
tspace = build_required_space(space, type_requirement="integer")
assert tspace.cardinality == (4 ** 2) * (6 + 1) * ((6 + 1) ** (2 * 1))
assert tspace.cardinality == (4**2) * (6 + 1) * ((6 + 1) ** (2 * 1))

tspace = build_required_space(
space, type_requirement="integer", shape_requirement="flattened"
)
assert tspace.cardinality == (4 ** 2) * (6 + 1) * ((6 + 1) ** (2 * 1))
assert tspace.cardinality == (4**2) * (6 + 1) * ((6 + 1) ** (2 * 1))

tspace = build_required_space(
space, type_requirement="integer", dist_requirement="linear"
)
assert tspace.cardinality == (4 ** 2) * (6 + 1) * ((6 + 1) ** (2 * 1))
assert tspace.cardinality == (4**2) * (6 + 1) * ((6 + 1) ** (2 * 1))


def test_quantization_does_not_violate_bounds():
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/plotting/test_plotly_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def test_multidim(self, monkeypatch):
def test_fidelity(self, monkeypatch):
"""Tests that fidelity is supported"""
config = mock_space(y="fidelity(1, 200, base=3)")
mock_experiment(monkeypatch, y=[1, 3 ** 2, 1, 3 ** 4])
mock_experiment(monkeypatch, y=[1, 3**2, 1, 3**4])
with create_experiment(config, trial_config) as (_, _, experiment):
plot = lpi(experiment, model_kwargs=dict(random_state=1))

Expand Down Expand Up @@ -485,7 +485,7 @@ def test_fidelity(self, monkeypatch):
"""Tests that fidelity is supported"""
mock_train_regressor(monkeypatch)
config = mock_space(y="fidelity(1, 200, base=3)")
mock_experiment(monkeypatch, y=[1, 3 ** 2, 1, 3 ** 4])
mock_experiment(monkeypatch, y=[1, 3**2, 1, 3**4])
with create_experiment(config, trial_config) as (_, _, experiment):
plot = partial_dependencies(
experiment, n_grid_points=5, model_kwargs=dict(random_state=1)
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ description = Verify code style with black
basepython = python3
skip_install = true
deps =
black == 20.8b1
black == 22.3.0
commands =
black --check src/orion/ tests/

Expand Down