Example #1
0
def _submit_experiment(
    config: Optional[Dict[str, Any]],
    context_dir: str,
    command: Optional[List[str]],
    test: bool = False,
    master_url: Optional[str] = None,
) -> Optional[int]:
    if context_dir == "":
        raise errors.InvalidExperimentException(
            "Cannot specify the context directory to be empty.")

    context_path = pathlib.Path(context_dir)
    config = {**constants.DEFAULT_EXP_CFG, **(config or {})}
    config.setdefault("internal", {})
    config["internal"]["native"] = {
        "command": _set_command_default(context_path, command)
    }
    logging.info(f"Creating an experiment with config: {config}")

    if master_url is None:
        master_url = util.get_default_master_address()

    exp_context = context.Context.from_local(context_path)

    # When a requested_user isn't specified to initialize_session(), the
    # authentication module will attempt to use the token store to grab the
    # current logged-in user. If there is no logged in user found, it will
    # default to constants.DEFAULT_DETERMINED_USER.
    auth.initialize_session(master_url, requested_user=None, try_reauth=True)

    if test:
        print(colored("Validating experiment configuration...", "yellow"),
              end="\r")
        api.create_experiment(master_url, config, exp_context, None, True)
        print(
            colored("Experiment configuration validation succeeded! 🎉",
                    "green"))
        exp_id = api.create_test_experiment(master_url, config, exp_context)
        print(colored("Test experiment ID: {}".format(exp_id), "green"))
        api.follow_test_experiment_logs(master_url, exp_id)
    else:
        exp_id = api.create_experiment(master_url, config, exp_context)

    logging.info(f"Created experiment {exp_id}")
    api.follow_experiment_logs(master_url, exp_id)
    return exp_id
Example #2
0
def create_experiment_and_follow_logs(
    master_url: str,
    config: Dict[str, Any],
    model_context: context.Context,
    template: Optional[str] = None,
    additional_body_fields: Optional[Dict[str, Any]] = None,
    activate: bool = True,
    follow_first_trial_logs: bool = True,
) -> int:
    exp_id = api.experiment.create_experiment(
        master_url,
        config,
        model_context,
        template=template,
        additional_body_fields=additional_body_fields,
        activate=activate,
    )
    print("Created experiment {}".format(exp_id))
    if activate and follow_first_trial_logs:
        api.follow_experiment_logs(master_url, exp_id)
    return exp_id