def create_experiment( self, config: Union[str, pathlib.Path, Dict], model_dir: str, ) -> experiment.ExperimentReference: check.is_instance(config, (str, pathlib.Path, dict), "config parameter must be dictionary or path") if isinstance(config, str): with open(config) as f: experiment_config = yaml.safe_load(f) elif isinstance(config, pathlib.Path): with config.open() as f: experiment_config = yaml.safe_load(f) elif isinstance(config, Dict): experiment_config = config model_context = _path_to_files(pathlib.Path(model_dir)) experiment_request = V1CreateExperimentRequest( model_definition=model_context, config=yaml.safe_dump(experiment_config), ) experiment_response = self._internal.determined_create_experiment( experiment_request) return experiment.ExperimentReference( experiment_response.experiment.id, self._session._master, self._experiments, )
def get_experiment(self, experiment_id: int) -> experiment.ExperimentReference: """ Get the :class:`~determined.experimental.ExperimentReference` representing the experiment with the provided experiment ID. """ return experiment.ExperimentReference( experiment_id, self._session, )
def create_experiment( self, config: Union[str, pathlib.Path, Dict], model_dir: Union[str, pathlib.Path], ) -> experiment.ExperimentReference: """ Create an experiment with config parameters and model directory. The function returns :class:`~determined.experimental.ExperimentReference` of the experiment. Arguments: config(string, pathlib.Path, dictionary): experiment config filename (.yaml) or a dict. model_dir(string): directory containing model definition. """ check.is_instance( config, (str, pathlib.Path, dict), "config parameter must be dictionary or path" ) if isinstance(config, str): with open(config) as f: experiment_config = util.safe_load_yaml_with_exceptions(f) elif isinstance(config, pathlib.Path): with config.open() as f: experiment_config = util.safe_load_yaml_with_exceptions(f) elif isinstance(config, Dict): experiment_config = config if isinstance(model_dir, str): model_dir = pathlib.Path(model_dir) model_context, _ = context.read_context(model_dir) resp = self._session.post( "/api/v1/experiments", body={ "config": yaml.safe_dump(experiment_config), "model_definition": model_context, }, ) exp_id = _CreateExperimentResponse(resp.json()).id exp = experiment.ExperimentReference(exp_id, self._session) exp.activate() return exp
def create_experiment( self, config: Union[str, pathlib.Path, Dict], model_dir: str, ) -> experiment.ExperimentReference: """ Create an experiment with config parameters and model direcotry. The function returns :class:`~determined.experimental.ExperimentReference` of the experiment. Arguments: config(string, pathlib.Path, dictionary): experiment config filename (.yaml) or a dict. model_dir(string): directory containing model definition. """ check.is_instance(config, (str, pathlib.Path, dict), "config parameter must be dictionary or path") if isinstance(config, str): with open(config) as f: experiment_config = util.safe_load_yaml_with_exceptions(f) elif isinstance(config, pathlib.Path): with config.open() as f: experiment_config = util.safe_load_yaml_with_exceptions(f) elif isinstance(config, Dict): experiment_config = config model_context = _path_to_files(pathlib.Path(model_dir)) experiment_request = V1CreateExperimentRequest( model_definition=model_context, config=yaml.safe_dump(experiment_config), ) experiment_response = self._internal.determined_create_experiment( experiment_request) return experiment.ExperimentReference( experiment_response.experiment.id, self._session._master, self._experiments, )