Skip to content

Commit

Permalink
Make format
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamc committed Jul 24, 2024
1 parent 89089fe commit eb3b652
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 58 deletions.
2 changes: 1 addition & 1 deletion examples/1_basics/7_parallelization_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def train(self, config: Configuration, seed: int = 0) -> float:
# if you would like to limit the resources consumption of each function evaluation with pynisher, you need to
# set nanny as False
# Otherwise, an error `daemonic processes are not allowed to have children` will raise!
nanny=False # if you do not use pynisher to limit the memory/time usage, feel free to set this one as True
nanny=False, # if you do not use pynisher to limit the memory/time usage, feel free to set this one as True
)
cluster.scale(jobs=n_workers)

Expand Down
75 changes: 18 additions & 57 deletions tests/test_runhistory/test_runhistory_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
from smac.runhistory.encoder.encoder import RunHistoryEncoder
from smac.runner.abstract_runner import StatusType

from ConfigSpace import Configuration
from ConfigSpace.hyperparameters import CategoricalHyperparameter


@pytest.fixture
def configs(configspace_small):
Expand All @@ -44,9 +41,7 @@ def test_transform(runhistory, make_scenario, configspace_small, configs):
)

# Normal encoder
encoder = RunHistoryEncoder(
scenario=scenario, considered_states=[StatusType.SUCCESS]
)
encoder = RunHistoryEncoder(scenario=scenario, considered_states=[StatusType.SUCCESS])
encoder.runhistory = runhistory

# TODO: Please replace with the more general solution once ConfigSpace 1.0
Expand All @@ -73,49 +68,37 @@ def test_transform(runhistory, make_scenario, configspace_small, configs):
assert ((X1 <= upper) & (X1 >= lower)).all()

# Log encoder
encoder = RunHistoryLogEncoder(
scenario=scenario, considered_states=[StatusType.SUCCESS]
)
encoder = RunHistoryLogEncoder(scenario=scenario, considered_states=[StatusType.SUCCESS])
encoder.runhistory = runhistory
X, Y = encoder.transform()
assert Y.tolist() != Y1.tolist()
assert ((X <= upper) & (X >= lower)).all()

encoder = RunHistoryLogScaledEncoder(
scenario=scenario, considered_states=[StatusType.SUCCESS]
)
encoder = RunHistoryLogScaledEncoder(scenario=scenario, considered_states=[StatusType.SUCCESS])
encoder.runhistory = runhistory
X, Y = encoder.transform()
assert Y.tolist() != Y1.tolist()
assert ((X <= upper) & (X >= lower)).all()

encoder = RunHistoryScaledEncoder(
scenario=scenario, considered_states=[StatusType.SUCCESS]
)
encoder = RunHistoryScaledEncoder(scenario=scenario, considered_states=[StatusType.SUCCESS])
encoder.runhistory = runhistory
X, Y = encoder.transform()
assert Y.tolist() != Y1.tolist()
assert ((X <= upper) & (X >= lower)).all()

encoder = RunHistoryInverseScaledEncoder(
scenario=scenario, considered_states=[StatusType.SUCCESS]
)
encoder = RunHistoryInverseScaledEncoder(scenario=scenario, considered_states=[StatusType.SUCCESS])
encoder.runhistory = runhistory
X, Y = encoder.transform()
assert Y.tolist() != Y1.tolist()
assert ((X <= upper) & (X >= lower)).all()

encoder = RunHistorySqrtScaledEncoder(
scenario=scenario, considered_states=[StatusType.SUCCESS]
)
encoder = RunHistorySqrtScaledEncoder(scenario=scenario, considered_states=[StatusType.SUCCESS])
encoder.runhistory = runhistory
X, Y = encoder.transform()
assert Y.tolist() != Y1.tolist()
assert ((X <= upper) & (X >= lower)).all()

encoder = RunHistoryEIPSEncoder(
scenario=scenario, considered_states=[StatusType.SUCCESS]
)
encoder = RunHistoryEIPSEncoder(scenario=scenario, considered_states=[StatusType.SUCCESS])
encoder.runhistory = runhistory
X, Y = encoder.transform()
assert Y.tolist() != Y1.tolist()
Expand Down Expand Up @@ -160,9 +143,7 @@ def test_transform_conditionals(runhistory, make_scenario, configspace_large):
status=StatusType.SUCCESS,
)

encoder = RunHistoryEncoder(
scenario=scenario, considered_states=[StatusType.SUCCESS]
)
encoder = RunHistoryEncoder(scenario=scenario, considered_states=[StatusType.SUCCESS])
encoder.runhistory = runhistory
X, Y = encoder.transform()

Expand All @@ -184,9 +165,7 @@ def test_multi_objective(runhistory, make_scenario, configspace_small, configs):

# Multi objective algorithm must be set
with pytest.raises(AssertionError):
encoder = RunHistoryEncoder(
scenario=scenario, considered_states=[StatusType.SUCCESS]
)
encoder = RunHistoryEncoder(scenario=scenario, considered_states=[StatusType.SUCCESS])
encoder.runhistory = runhistory
_, Y = encoder.transform()

Expand Down Expand Up @@ -242,9 +221,7 @@ def test_ignore(runhistory, make_scenario, configspace_small, configs):
)

# Normal encoder
encoder = RunHistoryEncoder(
scenario=scenario, considered_states=[StatusType.SUCCESS]
)
encoder = RunHistoryEncoder(scenario=scenario, considered_states=[StatusType.SUCCESS])
encoder.runhistory = runhistory
X1, Y1 = encoder.transform()

Expand Down Expand Up @@ -283,14 +260,10 @@ def test_budgets(runhistory, make_scenario, configspace_small, configs):
budget=2,
)

runhistory.add(
config=configs[1], cost=5, time=4, status=StatusType.SUCCESS, budget=2
)
runhistory.add(config=configs[1], cost=5, time=4, status=StatusType.SUCCESS, budget=2)

# Normal encoder
encoder = RunHistoryEncoder(
scenario=scenario, considered_states=[StatusType.SUCCESS]
)
encoder = RunHistoryEncoder(scenario=scenario, considered_states=[StatusType.SUCCESS])
encoder.runhistory = runhistory
X, Y = encoder.transform(budget_subset=[2])
assert Y.tolist() == [[99999999]]
Expand Down Expand Up @@ -319,14 +292,10 @@ def test_budgets(runhistory, make_scenario, configspace_small, configs):
budget=2,
)

runhistory.add(
config=configs[1], cost=5, time=4, status=StatusType.SUCCESS, budget=2
)
runhistory.add(config=configs[1], cost=5, time=4, status=StatusType.SUCCESS, budget=2)

# Normal encoder
encoder = RunHistoryEncoder(
scenario=scenario, considered_states=[StatusType.SUCCESS]
)
encoder = RunHistoryEncoder(scenario=scenario, considered_states=[StatusType.SUCCESS])
encoder.runhistory = runhistory
X, Y = encoder.transform(budget_subset=[2])
assert Y.tolist() == [[99999999]]
Expand All @@ -338,20 +307,12 @@ def test_budgets(runhistory, make_scenario, configspace_small, configs):
def test_lower_budget_states(runhistory, make_scenario, configspace_small, configs):
"""Tests lower budgets based on budget subset and considered states."""
scenario = make_scenario(configspace_small)
encoder = RunHistoryEncoder(
scenario=scenario, considered_states=[StatusType.SUCCESS]
)
encoder = RunHistoryEncoder(scenario=scenario, considered_states=[StatusType.SUCCESS])
encoder.runhistory = runhistory

runhistory.add(
config=configs[0], cost=1, time=1, status=StatusType.SUCCESS, budget=3
)
runhistory.add(
config=configs[0], cost=2, time=2, status=StatusType.SUCCESS, budget=4
)
runhistory.add(
config=configs[0], cost=3, time=4, status=StatusType.TIMEOUT, budget=5
)
runhistory.add(config=configs[0], cost=1, time=1, status=StatusType.SUCCESS, budget=3)
runhistory.add(config=configs[0], cost=2, time=2, status=StatusType.SUCCESS, budget=4)
runhistory.add(config=configs[0], cost=3, time=4, status=StatusType.TIMEOUT, budget=5)

# We request a higher budget but can't find it, so we expect an empty list
X, Y = encoder.transform(budget_subset=[500])
Expand Down

0 comments on commit eb3b652

Please sign in to comment.