def test_trial_working_dir_is_changed(config, monkeypatch): """Check that trial has its working_dir attribute changed.""" exp = ExperimentBuilder().build_from(config) trial = tuple_to_trial((1.0, ), exp.space) exp.register_trial(trial) con = Consumer(exp) con.consume(trial) assert trial.working_dir is not None assert trial.working_dir == con.working_dir + "/exp_" + trial.id
def main(args): """Fetch config and insert new point""" command_line_user_args = args.pop('user_args', [None])[1:] # TODO: Views are not fully configured until configuration is refactored experiment = ExperimentBuilder().build_view_from(args) # TODO: Remove this line when views gets fully configured experiment = ExperimentBuilder().build_from(args) transformed_args = _build_from(command_line_user_args) exp_space = experiment.space values = _create_tuple_from_values(transformed_args, exp_space) trial = tuple_to_trial(values, exp_space) experiment.register_trial(trial)
def test_pacemaker_termination(config, monkeypatch): """Check if pacemaker stops as soon as the trial completes.""" exp = ExperimentBuilder().build_from(config) trial = tuple_to_trial((1.0, ), exp.space) exp.register_trial(trial) con = Consumer(exp) start = time.time() con.consume(trial) con.pacemaker.join() duration = time.time() - start assert duration < con.pacemaker.wait_time
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_by_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_by_status('interrupted') assert len(trials) assert trials[0].id == trial.id