-
Notifications
You must be signed in to change notification settings - Fork 15
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
Continue an optimization run. #6
Open
PhMueller
wants to merge
4
commits into
automl:development
Choose a base branch
from
PhMueller:master
base: development
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
from loguru import logger | ||
import sys | ||
|
||
logger.configure(handlers=[{"sink": sys.stdout, "level": "INFO"}]) | ||
|
||
|
||
from .optimizers import DE, AsyncDE | ||
from .optimizers import DEHB | ||
from .utils import SHBracketManager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = '0.0.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import time | ||
import logging | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
from pathlib import Path | ||
from dehb.optimizers.dehb_with_warmstart import DEHB | ||
|
||
|
||
from hpobench.container.benchmarks.surrogates.paramnet_benchmark import ParamNetPokerOnTimeBenchmark | ||
|
||
|
||
def objective_function(config, budget, **kwargs): | ||
|
||
start = time.time() | ||
socket_id = kwargs.get('socket_id') | ||
benchmark = ParamNetPokerOnTimeBenchmark(socket_id=socket_id) | ||
result_dict = benchmark.objective_function(configuration=config, fidelity={'budget': int(budget)}) | ||
finish = time.time() | ||
return {'fitness': result_dict['function_value'], 'cost': result_dict['cost'], | ||
'info': {'res_info': result_dict['info'], 'time': float(finish - start)}} | ||
|
||
|
||
def main(result_path: str, seed=0): | ||
|
||
result_path = Path(result_path) | ||
result_path.mkdir(exist_ok=True, parents=True) | ||
|
||
checkpoint_file = result_path / 'checkpoint.pkl' | ||
|
||
benchmark = ParamNetPokerOnTimeBenchmark() | ||
|
||
dehb = DEHB(f=objective_function, | ||
cs=benchmark.get_configuration_space(seed=seed), | ||
dimensions=len(benchmark.get_configuration_space().get_hyperparameters()), | ||
min_budget=81, # Those are the budgets used by the benchmark. | ||
max_budget=2187, | ||
eta=3, | ||
output_path=result_path / 'dehb_logs', | ||
n_workers=1) | ||
|
||
try: | ||
traj, runtime, history = dehb.run(total_cost=20, # Let the procedure run for 20 seconds. | ||
verbose=True, | ||
save_intermediate=True, | ||
# arguments below are part of **kwargs shared across workers | ||
eta=3, | ||
result_path=result_path, | ||
socket_id=benchmark.socket_id) | ||
except Exception: | ||
# One could this a try-except to save the intermediate results in case of an error. | ||
dehb.save_checkpoint(checkpoint_file) | ||
|
||
# Call this function to save the checkpoint to disk. | ||
dehb.save_checkpoint(checkpoint_file) | ||
|
||
# To restart now the optimization procedure, create a new object. | ||
# Set the parameters `checkpoint_file` and `restore_checkpooint`. Then, the checkpoint will be automatically loaded. | ||
dehb_2 = DEHB(f=objective_function, | ||
cs=benchmark.get_configuration_space(seed=seed), | ||
dimensions=len(benchmark.get_configuration_space().get_hyperparameters()), | ||
min_budget=81, | ||
max_budget=2187, | ||
eta=3, | ||
output_path=result_path / 'dehb_logs', | ||
n_workers=1, | ||
checkpoint_file=result_path / 'checkpoint.pkl', | ||
restore_checkpoint=True) | ||
|
||
# NOTE: Make sure to increase the time limit!! | ||
traj2, runtime2, history2 = dehb_2.run(total_cost=20 + 20, | ||
verbose=True, | ||
save_intermediate=True, | ||
# This parameter is needed for the HPOBench-Benchmark Object. | ||
socket_id=benchmark.socket_id) | ||
|
||
|
||
if __name__ == '__main__': | ||
import argparse | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--result_path', type=str) | ||
args = parser.parse_args() | ||
|
||
main(result_path=args.result_path, seed=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
""" | ||
Before calling this event start the scheduler with | ||
|
||
`dask-scheduler --scheduler-file <result_path>/scheduler_file.txt` | ||
|
||
and then the worker with | ||
|
||
`dask-worker --scheduler-file <result_path>/scheduler_file.txt` --name 1 --resources "limit_proc=1" --no-nanny | ||
|
||
Note that we give the worker a resource. By doing so, only a single task can be executed per worker. | ||
|
||
""" | ||
|
||
import time | ||
import logging | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
from distributed import Client | ||
from pathlib import Path | ||
from dehb.optimizers.dehb_with_warmstart import DEHB | ||
|
||
from hpobench.container.benchmarks.surrogates.paramnet_benchmark import ParamNetPokerOnTimeBenchmark | ||
|
||
|
||
def objective_function(config, budget, **kwargs): | ||
|
||
start = time.time() | ||
socket_id = kwargs.get('socket_id') | ||
benchmark = ParamNetPokerOnTimeBenchmark(socket_id=socket_id) | ||
result_dict = benchmark.objective_function(configuration=config, fidelity={'budget': int(budget)}) | ||
finish = time.time() | ||
return {'fitness': result_dict['function_value'], 'cost': result_dict['cost'], | ||
'info': {'res_info': result_dict['info'], 'time': float(finish - start)}} | ||
|
||
|
||
def main(result_path: str, seed=0): | ||
|
||
result_path = Path(result_path) | ||
result_path.mkdir(exist_ok=True, parents=True) | ||
|
||
checkpoint_file = result_path / 'checkpoint.pkl' | ||
scheduler_file = result_path / 'scheduler_file.txt' | ||
|
||
benchmark = ParamNetPokerOnTimeBenchmark() | ||
|
||
client = Client(scheduler_file=scheduler_file) | ||
|
||
dehb = DEHB(f=objective_function, | ||
cs=benchmark.get_configuration_space(seed=seed), | ||
dimensions=len(benchmark.get_configuration_space().get_hyperparameters()), | ||
min_budget=81, # Those are the budgets used by the benchmark. | ||
max_budget=2187, | ||
eta=3, | ||
output_path=result_path / 'dehb_logs', | ||
client=client, | ||
# Limit the tasks per worker by starting the worker with the same resource! See above. | ||
client_resources={'limit_proc': 1}, | ||
) | ||
|
||
try: | ||
traj, runtime, history = dehb.run(total_cost=20, # Let the procedure run for 20 seconds. | ||
verbose=True, | ||
save_intermediate=True, | ||
# arguments below are part of **kwargs shared across workers | ||
eta=3, | ||
result_path=result_path, | ||
socket_id=benchmark.socket_id) | ||
except Exception: | ||
# One could this a try-except to save the intermediate results in case of an error. | ||
dehb.save_checkpoint(checkpoint_file) | ||
|
||
# Call this function to save the checkpoint to disk. | ||
dehb.save_checkpoint(checkpoint_file) | ||
|
||
dehb_2 = DEHB(f=objective_function, | ||
cs=benchmark.get_configuration_space(seed=seed), | ||
dimensions=len(benchmark.get_configuration_space().get_hyperparameters()), | ||
min_budget=81, | ||
max_budget=2187, | ||
eta=3, | ||
output_path=result_path / 'dehb_logs', | ||
client=client, | ||
client_resources={'limit_proc': 1}, # Also the new object needs this limit. | ||
checkpoint_file=result_path / 'checkpoint.pkl', | ||
restore_checkpoint=True, | ||
) | ||
|
||
traj2, runtime2, history2 = dehb_2.run(total_cost=20 + 20, | ||
verbose=True, | ||
save_intermediate=True, | ||
# arguments below are part of **kwargs shared across workers | ||
socket_id=benchmark.socket_id) | ||
|
||
|
||
from matplotlib import pyplot as plt | ||
import numpy as np | ||
|
||
f = plt.figure() | ||
plt.plot(np.arange(len(traj2)), traj2, label='restarted') | ||
plt.plot(np.arange(len(traj)), traj, label='first run') | ||
plt.yscale('log') | ||
plt.legend() | ||
plt.savefig(result_path / 'traj.png') | ||
plt.close() | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
import argparse | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--result_path', type=str) | ||
args = parser.parse_args() | ||
|
||
main(result_path=args.result_path, seed=0) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does bringing this here help? or does it clash with the configuration defined in
optimizers/dehb.py
?can
logger
now be imported directly? or could you point me to how you're using this maybe?