Esempio n. 1
0
def format_base64_as_yaml(source: str) -> str:
    s = yaml.safe_dump(yaml.safe_load(base64.b64decode(source)),
                       default_flow_style=False)

    if not isinstance(s, str):
        raise AssertionError("cannot format base64 string to yaml")
    return s
Esempio n. 2
0
    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,
        )
Esempio n. 3
0
    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
Esempio n. 4
0
    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,
        )
def create_experiment(
    master_url: str,
    config: Dict[str, Any],
    model_context: context.Context,
    template: Optional[str] = None,
    validate_only: bool = False,
    archived: bool = False,
    activate: bool = True,
    additional_body_fields: Optional[Dict[str, Any]] = None,
) -> int:
    body = {
        "activate": False,
        "experiment_config": yaml.safe_dump(config),
        "model_definition": [e.dict() for e in model_context.entries],
        "validate_only": validate_only,
    }
    if template:
        body["template"] = template
    if archived:
        body["archived"] = archived
    if additional_body_fields:
        body.update(additional_body_fields)

    r = req.post(master_url, "experiments", json=body)
    if not hasattr(r, "headers"):
        raise Exception(r)

    if validate_only:
        return 0

    new_resource = r.headers["Location"]
    experiment_id = int(new_resource.split("/")[-1])

    if activate:
        sess = session.Session(master_url, None, None, None)
        bindings.post_ActivateExperiment(sess, id=experiment_id)

    return experiment_id
Esempio n. 6
0
def _parse_config(field: Any) -> Any:
    # Pretty print the config field.
    return yaml.safe_dump(yaml.safe_load(base64.b64decode(field)),
                          default_flow_style=False)
Esempio n. 7
0
def config(args: Namespace) -> None:
    result = api.get(args.master, "experiments/{}/config".format(args.experiment_id))
    yaml.safe_dump(result.json(), stream=sys.stdout, default_flow_style=False)
Esempio n. 8
0
def format_object_as_yaml(source: Dict[str, Any]) -> str:
    s = yaml.safe_dump(source, default_flow_style=False)
    if not isinstance(s, str):
        raise AssertionError("cannot format object to yaml")
    return s
Esempio n. 9
0
def get_master(args: Namespace) -> None:
    resp = bindings.get_GetMaster(setup_session(args))
    if args.json:
        print(json.dumps(resp.to_json(), indent=4))
    else:
        print(yaml.safe_dump(resp.to_json(), default_flow_style=False))
Esempio n. 10
0
def config(args: Namespace) -> None:
    response = api.get(args.master, "config")
    if args.json:
        print(json.dumps(response.json(), indent=4))
    else:
        print(yaml.safe_dump(response.json(), default_flow_style=False))
Esempio n. 11
0
def config(args: Namespace) -> None:
    result = bindings.get_GetExperiment(setup_session(args),
                                        experimentId=args.experiment_id).config
    yaml.safe_dump(result, stream=sys.stdout, default_flow_style=False)