Beispiel #1
0
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 = {
        "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", body=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:
        activate_experiment(master_url, experiment_id)

    return experiment_id
Beispiel #2
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)
Beispiel #3
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)