示例#1
0
 def _overwrite_run_info(self, run_info):
     run_dir = self._get_run_dir(run_info.experiment_id, run_info.run_id)
     run_info_dict = _make_persisted_run_info_dict(run_info)
     write_yaml(run_dir,
                FileStore.META_DATA_FILE_NAME,
                run_info_dict,
                overwrite=True)
示例#2
0
def test_yaml_read_and_write(tmpdir):
    temp_dir = str(tmpdir)
    yaml_file = random_file("yaml")
    long_value = long(1) if six.PY2 else 1  # pylint: disable=undefined-variable
    data = {
        "a": random_int(),
        "B": random_int(),
        "text_value": u"中文",
        "long_value": long_value,
        "int_value": 32,
        "text_value_2": u"hi"
    }
    file_utils.write_yaml(temp_dir, yaml_file, data)
    read_data = file_utils.read_yaml(temp_dir, yaml_file)
    assert data == read_data
    yaml_path = os.path.join(temp_dir, yaml_file)
    with codecs.open(yaml_path, encoding="utf-8") as handle:
        contents = handle.read()
    assert "!!python" not in contents
    # Check that UTF-8 strings are written properly to the file (rather than as ASCII
    # representations of their byte sequences).
    assert u"中文" in contents

    def edit_func(old_dict):
        old_dict["more_text"] = u"西班牙语"
        return old_dict

    assert "more_text" not in file_utils.read_yaml(temp_dir, yaml_file)
    with safe_edit_yaml(temp_dir, yaml_file, edit_func):
        editted_dict = file_utils.read_yaml(temp_dir, yaml_file)
        assert "more_text" in editted_dict
        assert editted_dict["more_text"] == u"西班牙语"
    assert "more_text" not in file_utils.read_yaml(temp_dir, yaml_file)
示例#3
0
 def _create_experiment_with_id(self, name, experiment_id, artifact_uri):
     artifact_uri = artifact_uri or append_to_uri_path(
         self.artifact_root_uri, str(experiment_id))
     self._check_root_dir()
     meta_dir = mkdir(self.root_directory, str(experiment_id))
     experiment = Experiment(experiment_id, name, artifact_uri,
                             LifecycleStage.ACTIVE)
     experiment_dict = dict(experiment)
     # tags are added to the file system and are not written to this dict on write
     # As such, we should not include them in the meta file.
     del experiment_dict['tags']
     write_yaml(meta_dir, FileStore.META_DATA_FILE_NAME, experiment_dict)
     return experiment_id
示例#4
0
 def rename_experiment(self, experiment_id, new_name):
     meta_dir = os.path.join(self.root_directory, experiment_id)
     # if experiment is malformed, will raise error
     experiment = self._get_experiment(experiment_id)
     if experiment is None:
         raise MlflowException(
             "Experiment '%s' does not exist." % experiment_id,
             databricks_pb2.RESOURCE_DOES_NOT_EXIST)
     self._validate_experiment_name(new_name)
     experiment._set_name(new_name)
     if experiment.lifecycle_stage != LifecycleStage.ACTIVE:
         raise Exception(
             "Cannot rename experiment in non-active lifecycle stage."
             " Current stage: %s" % experiment.lifecycle_stage)
     write_yaml(meta_dir,
                FileStore.META_DATA_FILE_NAME,
                dict(experiment),
                overwrite=True)
示例#5
0
 def create_run(self, experiment_id, user_id, start_time, tags):
     """
     Creates a run with the specified attributes.
     """
     experiment_id = FileStore.DEFAULT_EXPERIMENT_ID if experiment_id is None else experiment_id
     experiment = self.get_experiment(experiment_id)
     if experiment is None:
         raise MlflowException(
             "Could not create run under experiment with ID %s - no such experiment "
             "exists." % experiment_id,
             databricks_pb2.RESOURCE_DOES_NOT_EXIST)
     if experiment.lifecycle_stage != LifecycleStage.ACTIVE:
         raise MlflowException(
             "Could not create run under non-active experiment with ID "
             "%s." % experiment_id, databricks_pb2.INVALID_STATE)
     run_uuid = uuid.uuid4().hex
     artifact_uri = self._get_artifact_dir(experiment_id, run_uuid)
     run_info = RunInfo(run_uuid=run_uuid,
                        run_id=run_uuid,
                        experiment_id=experiment_id,
                        artifact_uri=artifact_uri,
                        user_id=user_id,
                        status=RunStatus.to_string(RunStatus.RUNNING),
                        start_time=start_time,
                        end_time=None,
                        lifecycle_stage=LifecycleStage.ACTIVE)
     # Persist run metadata and create directories for logging metrics, parameters, artifacts
     run_dir = self._get_run_dir(run_info.experiment_id, run_info.run_id)
     mkdir(run_dir)
     run_info_dict = _make_persisted_run_info_dict(run_info)
     write_yaml(run_dir, FileStore.META_DATA_FILE_NAME, run_info_dict)
     mkdir(run_dir, FileStore.METRICS_FOLDER_NAME)
     mkdir(run_dir, FileStore.PARAMS_FOLDER_NAME)
     mkdir(run_dir, FileStore.ARTIFACTS_FOLDER_NAME)
     for tag in tags:
         self.set_tag(run_uuid, tag)
     return self.get_run(run_id=run_uuid)
示例#6
0
 def __exit__(self, *args):
     write_yaml(self._root, self._file_name, self._original, overwrite=True)
示例#7
0
 def __enter__(self):
     new_dict = self._edit_func(self._original.copy())
     write_yaml(self._root, self._file_name, new_dict, overwrite=True)