def main(): """ This function aims at fetching the results of an ORION Experiment. An `experiment_name` needs to be provided. Also, it is possible to retrieve results from complete trials. """ args = manage_arguments() # some_datetime = datetime.datetime.now() - datetime.timedelta(minutes=5) experiment = ExperimentBuilder().build_view_from( {"name": args.experiment_name}) pprint.pprint(experiment.stats) query = {} if args.only_completed: query['status'] = 'completed' # query['end_time'] = {'$gte': some_datetime} for trial in experiment.fetch_trials(query): print(trial.id) print(trial.status) print(trial.params) print(trial.results) print() pprint.pprint(trial.to_dict())
def test_trials_interrupted_sigterm(config, monkeypatch): """Check if a trial is set as interrupted when a signal is raised.""" def mock_popen(*args, **kwargs): os.kill(os.getpid(), signal.SIGTERM) exp = ExperimentBuilder().build_from(config) monkeypatch.setattr(subprocess.Popen, "wait", mock_popen) trial = tuple_to_trial((1.0, ), exp.space) exp.register_trial(trial) con = Consumer(exp) with pytest.raises(KeyboardInterrupt): con.consume(trial) trials = exp.fetch_trials({'status': 'interrupted'}) assert len(trials) assert trials[0].id == trial.id
def test_trials_interrupted_keyboard_int(config, monkeypatch): """Check if a trial is set as interrupted when a KeyboardInterrupt is raised.""" def mock_Popen(*args, **kwargs): raise KeyboardInterrupt exp = ExperimentBuilder().build_from(config) monkeypatch.setattr(consumer.subprocess, "Popen", mock_Popen) trial = tuple_to_trial((1.0, ), exp.space) exp.register_trial(trial) con = Consumer(exp) with pytest.raises(KeyboardInterrupt): con.consume(trial) trials = exp.fetch_trials({'status': 'interrupted'}) assert len(trials) assert trials[0].id == trial.id
def plot(no_xserver=False): """Plot the evolution of the best objective for each algorithm""" if no_xserver: import matplotlib matplotlib.use('agg') import matplotlib.pyplot as plt for algo_name, _ in get_algorithm_configs(): experiment = ExperimentBuilder().build_view_from( {"name": algo_name, "database": database_config}) objectives = [] sorted_trials = sorted( experiment.fetch_trials({'status': 'completed'}), key=lambda trial: trial.submit_time) for trial in sorted_trials: objectives.append(min([trial.objective.value] + objectives)) plt.plot(range(len(objectives)), objectives, label=algo_name) plt.legend() plt.show()