Exemplo n.º 1
0
def test_experiment_name() -> None:
    c = AzureConfig()
    c.build_branch = "branch"
    c.get_git_information()
    assert create_experiment_name(c) == "branch"
    c.experiment_name = "foo"
    assert create_experiment_name(c) == "foo"
Exemplo n.º 2
0
def set_run_tags(run: Run, azure_config: AzureConfig, model_config_overrides: str) -> None:
    """
    Set metadata for the run
    :param run: Run to set metadata for.
    :param azure_config: The configurations for the present AzureML job
    :param model_config_overrides: A string that describes which model parameters were overwritten by commandline
     arguments in the present run.
    """
    git_information = azure_config.get_git_information()
    run.set_tags({
        "tag": azure_config.tag,
        "model_name": azure_config.model,
        "execution_mode": ModelExecutionMode.TRAIN.value if azure_config.train else ModelExecutionMode.TEST.value,
        RUN_RECOVERY_ID_KEY_NAME: azure_util.create_run_recovery_id(run=run),
        RUN_RECOVERY_FROM_ID_KEY_NAME: azure_config.run_recovery_id,
        "build_number": str(azure_config.build_number),
        "build_user": azure_config.build_user,
        "build_user_email": azure_config.build_user_email,
        "source_repository": git_information.repository,
        "source_branch": git_information.branch,
        "source_id": git_information.commit_id,
        "source_message": git_information.commit_message,
        "source_author": git_information.commit_author,
        "source_dirty": str(git_information.is_dirty),
        "overrides": model_config_overrides,
        CROSS_VALIDATION_SPLIT_INDEX_TAG_KEY: -1,
    })
Exemplo n.º 3
0
def create_experiment_name(azure_config: AzureConfig) -> str:
    """
    Gets the name of the AzureML experiment. This is taken from the commandline, or from the git branch.
    :param azure_config: The object containing all Azure-related settings.
    :return: The name to use for the AzureML experiment.
    """
    if azure_config.experiment_name:
        return azure_config.experiment_name
    branch = azure_config.get_git_information().branch
    # If no branch information is found anywhere, create an experiment name that is the user alias and a timestamp
    # at monthly granularity, so that not too many runs accumulate in that experiment.
    return branch or getpass.getuser() + f"_local_branch_{date.today().strftime('%Y%m')}"
Exemplo n.º 4
0
def get_git_tags(azure_config: AzureConfig) -> Dict[str, str]:
    """
    Creates a dictionary with git-related information, like branch and commit ID. The dictionary key is a string
    that can be used as a tag on an AzureML run, the dictionary value is the git information. If git information
    is passed in via commandline arguments, those take precedence over information read out from the repository.
    :param azure_config: An AzureConfig object specifying git-related commandline args.
    :return: A dictionary mapping from tag name to git info.
    """
    git_information = azure_config.get_git_information()
    return {
        "source_repository": git_information.repository,
        "source_branch": git_information.branch,
        "source_id": git_information.commit_id,
        "source_dirty": str(git_information.is_dirty),
        "source_author": git_information.commit_author,
        "source_message": git_information.commit_message,
    }
Exemplo n.º 5
0
def build_information_to_dot_net_json(
        azure_config: AzureConfig,
        result_location: ExperimentResultLocation) -> str:
    """
    Converts the build metadata to a JSON string.
    :param azure_config: Azure configuration file with build information.
    :param result_location: ExperimentResultLocation object with result locations.
    """
    git_information = azure_config.get_git_information()
    return json.dumps({
        "BuildNumber": azure_config.build_number,
        "BuildRequestedFor": azure_config.build_user,
        "BuildSourceBranchName": git_information.branch,
        "BuildSourceVersion": git_information.commit_id,
        "BuildSourceAuthor": git_information.commit_author,
        "ModelName": azure_config.model,
        "ResultsContainerName": result_location.results_container_name,
        "ResultsUri": result_location.results_uri,
        "DatasetFolder": result_location.dataset_folder,
        "DatasetFolderUri": result_location.dataset_uri,
        "AzureBatchJobName": result_location.azure_job_name
    })