def consume(self, trial): """Execute user's script as a block box using the options contained within `trial`. :type trial: `orion.core.worker.trial.Trial` """ log.debug("### Create new directory at '%s':", self.working_dir) temp_dir = self.experiment.working_dir is None prefix = self.experiment.name + "_" suffix = trial.id try: with WorkingDir(self.working_dir, temp_dir, prefix=prefix, suffix=suffix) as workdirname: log.debug("## New consumer context: %s", workdirname) trial.working_dir = workdirname results_file = self._consume(trial, workdirname) log.debug( "## Parse results from file and fill corresponding Trial object." ) self.experiment.update_completed_trial(trial, results_file) except KeyboardInterrupt: log.debug("### Save %s as interrupted.", trial) self.experiment.set_trial_status(trial, status='interrupted') raise except ExecutionError: log.debug("### Save %s as broken.", trial) self.experiment.set_trial_status(trial, status='broken')
def consume(self, trial): """Execute user's script as a block box using the options contained within `trial`. :type trial: `orion.core.worker.trial.Trial` """ log.debug("### Create new directory at '%s':", self.working_dir) temp_dir = self.experiment.working_dir is None prefix = self.experiment.name + "_" suffix = trial.id with WorkingDir(self.working_dir, temp_dir, prefix=prefix, suffix=suffix) as workdirname: log.debug("## New consumer context: %s", workdirname) completed_trial = self._consume(trial, workdirname) if completed_trial is not None: log.debug("### Register successfully evaluated %s.", completed_trial) self.experiment.push_completed_trial(completed_trial) else: log.debug("### Save %s as broken.", trial) trial.status = 'broken' Database().write('trials', trial.to_dict(), query={'_id': trial.id})
def test_temp_dir_when_exists(tmp_path, path): """Check if a permanent directory is deleted.""" os.mkdir(path) with WorkingDir(tmp_path, temp=True, prefix="hi", suffix="_hello"): assert os.path.exists(path) assert os.path.exists(path) shutil.rmtree(path)
def consume(self, trial): """Execute user's script as a block box using the options contained within `trial`. Parameters ---------- trial: `orion.core.worker.trial.Trial` Orion trial to execute. Returns ------- bool True if the trial was successfully executed. False if the trial is broken. """ log.debug("### Create new directory at '%s':", self.working_dir) temp_dir = not bool(self.experiment.working_dir) prefix = self.experiment.name + "_" suffix = trial.id try: with WorkingDir(self.working_dir, temp_dir, prefix=prefix, suffix=suffix) as workdirname: log.debug("## New consumer context: %s", workdirname) trial.working_dir = workdirname results_file = self._consume(trial, workdirname) log.debug( "## Parse results from file and fill corresponding Trial object." ) self.experiment.update_completed_trial(trial, results_file) success = True except KeyboardInterrupt: log.debug("### Save %s as interrupted.", trial) self.experiment.set_trial_status(trial, status="interrupted") raise except ExecutionError: log.debug("### Save %s as broken.", trial) self.experiment.set_trial_status(trial, status="broken") success = False return success
def test_create_temp_dir(tmp_path): """Check if a temporary directory is created.""" with WorkingDir(tmp_path, prefix="hi", suffix="_hello") as w: assert os.path.exists(w) assert not os.path.exists(w)
def test_create_permanent_dir(tmp_path, path): """Check if a permanent directory is created.""" with WorkingDir(tmp_path, temp=False, prefix="hi", suffix="_hello"): assert os.path.exists(path) assert os.path.exists(path)