def test_resilience(monkeypatch): """Test if Oríon stops after enough broken trials.""" monkeypatch.chdir(os.path.dirname(os.path.abspath(__file__))) MAX_BROKEN = 3 orion.core.config.worker.max_broken = 3 orion.core.cli.main([ "hunt", "--config", "./orion_config_random.yaml", "./broken_box.py", "-x~uniform(-50, 50)" ]) exp = ExperimentBuilder().build_from({'name': 'demo_random_search'}) assert len(exp.fetch_trials_by_status('broken')) == MAX_BROKEN
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