Skip to content

Commit

Permalink
Use HistoryReader and from_saved_histories when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
YamLyubov committed Feb 16, 2024
1 parent 497528b commit 12248f0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
12 changes: 1 addition & 11 deletions examples/molecule_search/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,8 @@ def run_experiment(optimizer_setup: Callable,

def plot_experiment_comparison(experiment_ids: Sequence[str], metric_id: int = 0, results_dir='./results'):
root = Path(results_dir)
histories = {}
for exp_name in experiment_ids:
trials = []
for history_filename in os.listdir(root / exp_name):
if history_filename.startswith('history'):
history = OptHistory.load(root / exp_name / history_filename)
trials.append(history)
histories[exp_name] = trials
print(f'Loaded {len(trials)} trial histories for experiment: {exp_name}')
# Visualize
MultipleFitnessLines.from_histories(histories).visualize(metric_id=metric_id)
return histories
MultipleFitnessLines.from_saved_histories(experiment_ids, root).visualize(metric_id=metric_id)


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions test/unit/adaptive/test_mab_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
(os.path.join(Path(__file__).parent), '0_mab.pkl')])
def test_save_mab(path_to_save, file_name):
""" Tests if MAB is saved with specifying file_nam and without. """
mab = MultiArmedBanditAgent(actions=[0, 1, 2],
mab = MultiArmedBanditAgent(actions=['0', '1', '2'],
n_jobs=1,
path_to_save=path_to_save)
mab.save()
Expand All @@ -25,7 +25,7 @@ def test_load_mab():
file_name = 'test_mab.pkl'
path_to_load = os.path.join(Path(__file__).parent, file_name)
# save mab to load it later
mab = MultiArmedBanditAgent(actions=[0, 1, 2],
mab = MultiArmedBanditAgent(actions=['0', '1', '2'],
n_jobs=1,
path_to_save=path_to_load)
mab.save()
Expand Down

0 comments on commit 12248f0

Please sign in to comment.