def log_trial_end(self, trial, failed): e = CNVRGExperiment(self._cnvrg_experiments[trial.trial_id]) e.log("===== Logging Artifacts =====") from os import listdir files_list = [ os.path.join(trial.logdir, p) for p in os.listdir(trial.logdir) ] e.log_artifacts(files_list) e.finish(exit_status=int(failed))
def log_trial_result(self, iteration, trial, result): e = CNVRGExperiment(self._cnvrg_experiments[trial.trial_id]) e.log(str(result)) if self._cnvrg_metrics == []: self._cnvrg_metrics = [key for key in result] training_iteration = result['training_iteration'] for key in self._cnvrg_metrics: try: value = float(result[key]) except (ValueError, TypeError): continue e.log_metric(key, value, training_iteration)
class NbConverter: def __init__(self, input, to, template, inplace, allow_errors): self.__cnvrg_env = True # When testing locally, it is turned False. self.input = input self.to = to self.template = template self.inplace = inplace self.allow_errors = allow_errors try: self.__experiment = Experiment() except: self.__cnvrg_env = False if self.__cnvrg_env: self.__experiment.log_param("template", template) def run(self): if self.__cnvrg_env: self.__experiment.log("Configuring nbconvert options") run_string = '' if self.allow_errors is False: if self.template is None: if self.to != 'notebook': run_string = "jupyter nbconvert --to {} {}".format( self.to, self.input) elif self.inplace is True and self.to == 'notebook': run_string = "jupyter nbconvert --inplace --to {} {}".format( self.to, self.input) else: run_string = "jupyter nbconvert --to notebook {}".format( self.input) else: run_string = "jupyter nbconvert --to {} -template {} {}".format( self.to, self.template, self.input) else: if self.template is None: if self.to != 'notebook': run_string = "jupyter nbconvert --allow-errors --to {} {}".format( self.to, self.input) elif self.inplace is True and self.to == 'notebook': run_string = "jupyter nbconvert --allow-errors --inplace --to {} {}".format( self.to, self.input) else: run_string = "jupyter nbconvert --allow-errors --to notebook {}".format( self.input) else: run_string = "jupyter nbconvert --allow-errors --to {} -template {} {}".format( self.to, self.template, self.input) log_string = "Running command: {}".format(run_string) run_list = run_string.split(' ') dir = '/cnvrg' if self.__cnvrg_env: self.__experiment.log(log_string) try: subprocess.call(run_list, cwd=dir) except OSError: print( 'jupyter nbconvert was unsuccessful. Please check your file path and parameters.' ) exit(1) if self.__cnvrg_env: self.__experiment.log("Conversion finished")