Skip to content

Commit

Permalink
bugfixes, set metric to allways be passthrough, override max_parallelism
Browse files Browse the repository at this point in the history
  • Loading branch information
madeline-scyphers committed Sep 8, 2023
1 parent 1352e3b commit be98afc
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 72 deletions.
124 changes: 61 additions & 63 deletions boa/async-opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
from ax import Data
from ax.storage.json_store.decoder import object_from_json

from boa.config import BOAConfig, BOAScriptOptions
from boa.config import BOAConfig, BOAScriptOptions, MetricType
from boa.controller import Controller
from boa.storage import scheduler_from_json_file
from boa.wrappers.synthetic_wrapper import SyntheticWrapper
from boa.wrappers.wrapper_utils import cd_and_cd_back, load_jsonlike
from boa.wrappers.wrapper_utils import load_jsonlike


@click.command()
Expand Down Expand Up @@ -73,74 +73,70 @@ def main(config_path, scheduler_path, num_trials):
if not config:
sch_jsn = load_jsonlike(scheduler_path)
config = BOAConfig(**{**object_from_json(sch_jsn["wrapper"]["config"]), **config_kw})
if "steps" in config.generation_strategy:
for step in config.generation_strategy["steps"]:
step.max_parallelism = None
else:
config.generation_strategy["max_parallelism_override"] = -1
for metric in config.objective.metrics:
metric.metric = "passthrough"
metric.metric_type = MetricType.PASSTHROUGH

options = dict(
append_timestamp=config.script_options.append_timestamp,
working_dir=config.script_options.working_dir,
wrapper=SyntheticWrapper(config=config),
)

with cd_and_cd_back(options["working_dir"]):
if scheduler_path:
scheduler = scheduler_from_json_file(filepath=scheduler_path)
if num_trials:
scheduler.wrapper.config.scheduler = dataclasses.replace(
scheduler.wrapper.config.scheduler, total_trials=num_trials
)
scheduler.wrapper.config.n_trials = num_trials
scheduler.options = dataclasses.replace(scheduler.options, total_trials=num_trials)

else:
controller = Controller(config_path=config_path, wrapper=SyntheticWrapper(config=config))
controller.initialize_scheduler()
scheduler = controller.scheduler

if not scheduler.opt_csv.exists() and scheduler.experiment.trials:
controller.logger.warning(
"No optimization CSV found, but previous trials exist. "
"\nLikely cause was a previous run was moved with out the CSV."
if scheduler_path:
scheduler = scheduler_from_json_file(filepath=scheduler_path)
if num_trials:
scheduler.wrapper.config.scheduler = dataclasses.replace(
scheduler.wrapper.config.scheduler, total_trials=num_trials
)
scheduler.wrapper.config.n_trials = num_trials
scheduler.options = dataclasses.replace(scheduler.options, total_trials=num_trials)

else:
controller = Controller(config_path=config_path, wrapper=SyntheticWrapper(config=config))
controller.initialize_scheduler()
scheduler = controller.scheduler

if not scheduler.opt_csv.exists() and scheduler.experiment.trials:
controller.logger.warning(
"No optimization CSV found, but previous trials exist. "
"\nLikely cause was a previous run was moved with out the CSV."
)

if scheduler.opt_csv.exists():
exp_attach_data_from_opt_csv(list(config.objective.metric_names), scheduler)
# for trial_index in new_data["trial_index"].unique():
#
# scheduler.experiment.trials[trial_index].mark_completed()
if scheduler.opt_csv.exists():
exp_attach_data_from_opt_csv(list(config.objective.metric_names), scheduler)

generator_runs = [
scheduler.generation_strategy.gen(experiment=scheduler.experiment)
for _ in range(scheduler.wrapper.config.trials)
]
generator_runs = scheduler.generation_strategy._gen_multiple(
experiment=scheduler.experiment, num_generator_runs=scheduler.wrapper.config.trials
)

for generator_run in generator_runs:
trial = scheduler.experiment.new_trial(
generator_run=generator_run,
)
trial.runner = scheduler.runner
trial.mark_running()

if scheduler.experiment.fetch_data().df.empty:
trials = scheduler.experiment.trials
metrics = scheduler.experiment.metrics
for metric in metrics.keys():
scheduler.experiment.attach_data(
Data(
df=pd.DataFrame.from_records(
dict(
trial_index=list(trials.keys()),
arm_name=[f"{i}_0" for i in trials.keys()],
metric_name=metric,
mean=None,
sem=0.0,
)
for generator_run in generator_runs:
trial = scheduler.experiment.new_trial(
generator_run=generator_run,
)
trial.runner = scheduler.runner
trial.mark_running()

if scheduler.experiment.fetch_data().df.empty:
trials = scheduler.experiment.trials
metrics = scheduler.experiment.metrics
for metric in metrics.keys():
scheduler.experiment.attach_data(
Data(
df=pd.DataFrame.from_records(
dict(
trial_index=list(trials.keys()),
arm_name=[f"{i}_0" for i in trials.keys()],
metric_name=metric,
mean=None,
sem=0.0,
)
),
combine_with_last_data=True,
)
)
),
combine_with_last_data=True,
)

scheduler.save_data(metrics_to_end=True, ax_kwargs=dict(always_include_field_columns=True))
# scheduler =
return scheduler
scheduler.save_data(metrics_to_end=True, ax_kwargs=dict(always_include_field_columns=True))
return scheduler


def exp_attach_data_from_opt_csv(metric_names, scheduler):
Expand All @@ -153,6 +149,8 @@ def exp_attach_data_from_opt_csv(metric_names, scheduler):
nan_rows = exp_df["mean"].isna()
nan_trials = exp_df.loc[nan_rows]["trial_index"].unique()
new_data = df.loc[df["trial_index"].isin(nan_trials)]
if new_data.empty:
return
for metric, trial_results in new_data[metric_names].to_dict().items():
scheduler.experiment.attach_data(
Data(
Expand Down
10 changes: 1 addition & 9 deletions boa/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,7 @@ def scheduler_from_json_snapshot(
)

scheduler = Scheduler(generation_strategy=generation_strategy, experiment=experiment, options=options, **kwargs)
fp = serialized.pop("scheduler_filepath", None)
if fp:
scheduler.scheduler_filepath = object_from_json(
fp,
decoder_registry=decoder_registry,
class_decoder_registry=class_decoder_registry,
)
else:
scheduler.scheduler_filepath = pathlib.Path(filepath)
scheduler.scheduler_filepath = pathlib.Path(filepath)
if wrapper:
if isinstance(scheduler.experiment.runner, WrappedJobRunner):
scheduler.experiment.runner.wrapper = wrapper
Expand Down

4 comments on commit be98afc

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
__main__.py90495%134, 165, 210, 218
async-opt.py90900%1–4, 6–10, 12–16, 19–20, 26, 33, 39, 60, 68–78, 80–83, 85–88, 91–92, 95–97, 99–100, 105–106, 108, 112–113, 116–117, 119–123, 138–139, 142–146, 148–155, 171–173, 179–180, 182–183, 185, 191–197, 200–201
ax_instantiation_utils.py47197%123
controller.py831186%74, 94–95, 97–100, 102–104, 181
definitions.py80100% 
instantiation_base.py40197%39
metaclasses.py72395%50–51, 57
plot.py12120%15, 17–18, 20–21, 24, 27, 34, 40–41, 44–45
plotting.py1412880%51–52, 59, 94–95, 251–253, 301–305, 345, 429–432, 434–441, 443, 448
registry.py80100% 
runner.py45491%42, 76–78
scheduler.py781482%38, 125–128, 135–136, 150, 157–158, 165–166, 261–262
storage.py1241786%80, 83, 115–117, 177, 195, 273–281, 300
template.py200100% 
utils.py902077%175, 189–190, 215, 225–229, 231–233, 235, 237, 241–246
config
   __main__.py00100% 
   config.py3073887%33, 211, 217, 221, 223–224, 226, 282, 292, 409, 412, 420–421, 429, 603, 605, 607, 613–617, 619, 690, 723, 744, 751–752, 760, 773, 783–784, 796, 821, 824, 906–907, 909
   converters.py751382%14, 22, 25, 41, 46–48, 51–52, 65, 67, 71, 79
metrics
   metric_funcs.py34488%58, 80–81, 83
   metrics.py1011585%127, 304–305, 310–311, 314, 320, 331–333, 337–341
   modular_metric.py1202083%38–41, 43–50, 64, 131, 142, 184, 235–236, 255–256
   synthetic_funcs.py39489%31, 35, 58, 65
scripts
   moo.py30196%44
   run_branin.py34197%56
   script_wrappers.py31293%57–58
   synth_func_cli.py210100% 
wrappers
   base_wrapper.py1952686%63–64, 89–92, 94, 102, 110, 115, 147, 156, 215–216, 218, 269, 330, 402, 416, 589, 591–594, 602, 612
   script_wrapper.py83890%191, 202–203, 270, 313, 319, 324, 329
   synthetic_wrapper.py16160%1, 3, 5, 7, 10–13, 15–16, 18–19, 21, 27–28, 30
   wrapper_utils.py132993%147–148, 228, 277, 385–387, 395–396
TOTAL216636283% 

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
__main__.py90495%134, 165, 210, 218
async-opt.py90900%1–4, 6–10, 12–16, 19–20, 26, 33, 39, 60, 68–78, 80–83, 85–88, 91–92, 95–97, 99–100, 105–106, 108, 112–113, 116–117, 119–123, 138–139, 142–146, 148–155, 171–173, 179–180, 182–183, 185, 191–197, 200–201
ax_instantiation_utils.py47197%123
controller.py831186%74, 94–95, 97–100, 102–104, 181
definitions.py80100% 
instantiation_base.py40197%39
metaclasses.py72395%50–51, 57
plot.py12120%15, 17–18, 20–21, 24, 27, 34, 40–41, 44–45
plotting.py1412880%51–52, 59, 94–95, 251–253, 301–305, 345, 429–432, 434–441, 443, 448
registry.py80100% 
runner.py45491%42, 76–78
scheduler.py781482%38, 125–128, 135–136, 150, 157–158, 165–166, 261–262
storage.py1241786%80, 83, 115–117, 177, 195, 273–281, 300
template.py200100% 
utils.py902077%175, 189–190, 215, 225–229, 231–233, 235, 237, 241–246
config
   __main__.py00100% 
   config.py3073887%33, 211, 217, 221, 223–224, 226, 282, 292, 409, 412, 420–421, 429, 603, 605, 607, 613–617, 619, 690, 723, 744, 751–752, 760, 773, 783–784, 796, 821, 824, 906–907, 909
   converters.py751382%14, 22, 25, 41, 46–48, 51–52, 65, 67, 71, 79
metrics
   metric_funcs.py34488%58, 80–81, 83
   metrics.py1011585%127, 304–305, 310–311, 314, 320, 331–333, 337–341
   modular_metric.py1202083%38–41, 43–50, 64, 131, 142, 184, 235–236, 255–256
   synthetic_funcs.py39489%31, 35, 58, 65
scripts
   moo.py30196%44
   run_branin.py34197%56
   script_wrappers.py31293%57–58
   synth_func_cli.py210100% 
wrappers
   base_wrapper.py1952686%63–64, 89–92, 94, 102, 110, 115, 147, 156, 215–216, 218, 269, 330, 402, 416, 589, 591–594, 602, 612
   script_wrapper.py83890%191, 202–203, 270, 313, 319, 324, 329
   synthetic_wrapper.py16160%1, 3, 5, 7, 10–13, 15–16, 18–19, 21, 27–28, 30
   wrapper_utils.py132993%147–148, 228, 277, 385–387, 395–396
TOTAL216636283% 

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
__main__.py90495%134, 165, 210, 218
async-opt.py90900%1–4, 6–10, 12–16, 19–20, 26, 33, 39, 60, 68–78, 80–83, 85–88, 91–92, 95–97, 99–100, 105–106, 108, 112–113, 116–117, 119–123, 138–139, 142–146, 148–155, 171–173, 179–180, 182–183, 185, 191–197, 200–201
ax_instantiation_utils.py47197%123
controller.py831186%74, 94–95, 97–100, 102–104, 181
definitions.py80100% 
instantiation_base.py40197%39
metaclasses.py72395%50–51, 57
plot.py12120%15, 17–18, 20–21, 24, 27, 34, 40–41, 44–45
plotting.py1412880%51–52, 59, 94–95, 251–253, 301–305, 345, 429–432, 434–441, 443, 448
registry.py80100% 
runner.py45491%42, 76–78
scheduler.py781482%38, 125–128, 135–136, 150, 157–158, 165–166, 261–262
storage.py1241786%80, 83, 115–117, 177, 195, 273–281, 300
template.py200100% 
utils.py902077%175, 189–190, 215, 225–229, 231–233, 235, 237, 241–246
config
   __main__.py00100% 
   config.py3073887%33, 211, 217, 221, 223–224, 226, 282, 292, 409, 412, 420–421, 429, 603, 605, 607, 613–617, 619, 690, 723, 744, 751–752, 760, 773, 783–784, 796, 821, 824, 906–907, 909
   converters.py751382%14, 22, 25, 41, 46–48, 51–52, 65, 67, 71, 79
metrics
   metric_funcs.py34488%58, 80–81, 83
   metrics.py1011585%127, 304–305, 310–311, 314, 320, 331–333, 337–341
   modular_metric.py1202083%38–41, 43–50, 64, 131, 142, 184, 235–236, 255–256
   synthetic_funcs.py39489%31, 35, 58, 65
scripts
   moo.py30196%44
   run_branin.py34197%56
   script_wrappers.py31293%57–58
   synth_func_cli.py210100% 
wrappers
   base_wrapper.py1952686%63–64, 89–92, 94, 102, 110, 115, 147, 156, 215–216, 218, 269, 330, 402, 416, 589, 591–594, 602, 612
   script_wrapper.py83890%191, 202–203, 270, 313, 319, 324, 329
   synthetic_wrapper.py16160%1, 3, 5, 7, 10–13, 15–16, 18–19, 21, 27–28, 30
   wrapper_utils.py132993%147–148, 228, 277, 385–387, 395–396
TOTAL216636283% 

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
__main__.py90495%134, 165, 210, 218
async-opt.py90900%1–4, 6–10, 12–16, 19–20, 26, 33, 39, 60, 68–78, 80–83, 85–88, 91–92, 95–97, 99–100, 105–106, 108, 112–113, 116–117, 119–123, 138–139, 142–146, 148–155, 171–173, 179–180, 182–183, 185, 191–197, 200–201
ax_instantiation_utils.py47197%123
controller.py831186%74, 94–95, 97–100, 102–104, 181
definitions.py80100% 
instantiation_base.py40197%39
metaclasses.py72395%50–51, 57
plot.py12120%15, 17–18, 20–21, 24, 27, 34, 40–41, 44–45
plotting.py1412880%51–52, 59, 94–95, 251–253, 301–305, 345, 429–432, 434–441, 443, 448
registry.py80100% 
runner.py45491%42, 76–78
scheduler.py781482%38, 125–128, 135–136, 150, 157–158, 165–166, 261–262
storage.py1241786%80, 83, 115–117, 177, 195, 273–281, 300
template.py200100% 
utils.py902077%175, 189–190, 215, 225–229, 231–233, 235, 237, 241–246
config
   __main__.py00100% 
   config.py3073887%33, 211, 217, 221, 223–224, 226, 282, 292, 409, 412, 420–421, 429, 603, 605, 607, 613–617, 619, 690, 723, 744, 751–752, 760, 773, 783–784, 796, 821, 824, 906–907, 909
   converters.py751382%14, 22, 25, 41, 46–48, 51–52, 65, 67, 71, 79
metrics
   metric_funcs.py34488%58, 80–81, 83
   metrics.py1011585%127, 304–305, 310–311, 314, 320, 331–333, 337–341
   modular_metric.py1202083%38–41, 43–50, 64, 131, 142, 184, 235–236, 255–256
   synthetic_funcs.py39489%31, 35, 58, 65
scripts
   moo.py30196%44
   run_branin.py34197%56
   script_wrappers.py31293%57–58
   synth_func_cli.py210100% 
wrappers
   base_wrapper.py1952686%63–64, 89–92, 94, 102, 110, 115, 147, 156, 215–216, 218, 269, 330, 402, 416, 589, 591–594, 602, 612
   script_wrapper.py83890%191, 202–203, 270, 313, 319, 324, 329
   synthetic_wrapper.py16160%1, 3, 5, 7, 10–13, 15–16, 18–19, 21, 27–28, 30
   wrapper_utils.py132993%147–148, 228, 277, 385–387, 395–396
TOTAL216636283% 

Please sign in to comment.