Exemple #1
0
 def mockreturn(train_py, score_py):
     project_configuration = ProjectConfiguration(
         project_configuration_file)
     assert project_configuration.has_value("subscription_id")
     assert project_configuration.has_value("resource_group")
     assert project_configuration.has_value("workspace_name")
     ws = MockDeepRealtimeScore(
         project_configuration.get_value("subscription_id"),
         project_configuration.get_value("resource_group"),
         project_configuration.get_value("workspace_name"),
         project_configuration_file,
         score_py=score_py,
         train_py=train_py,
     )
     return ws
Exemple #2
0
    def get_or_create_workspace(
            cls,
            configuration_file: str = project_configuration_file,
            **kwargs):
        project_configuration = ProjectConfiguration(configuration_file)
        assert project_configuration.has_value("subscription_id")
        assert project_configuration.has_value("resource_group")
        assert project_configuration.has_value("workspace_name")
        assert project_configuration.has_value("workspace_region")

        return MockMLRealtimeScore(
            project_configuration.get_value("subscription_id"),
            project_configuration.get_value("resource_group"),
            project_configuration.get_value("workspace_name"),
            project_configuration_file,
            **kwargs,
        )
Exemple #3
0
    def get_or_create_workspace(
            cls,
            configuration_file: str = project_configuration_file,
            project_configuration: ProjectConfiguration = None,
            **kwargs):
        """ Get or create a workspace if it doesn't exist.

        :param configuration_file:
        :param project_configuration: ProjectConfiguration
        """
        if not project_configuration:
            project_configuration = ProjectConfiguration(configuration_file)
        assert project_configuration.has_value("subscription_id")
        assert project_configuration.has_value("resource_group")
        assert project_configuration.has_value("workspace_name")
        assert project_configuration.has_value("workspace_region")

        try:
            check_valid_resource_name(
                project_configuration.get_value("workspace_name"), "Workspace")
        except UserErrorException:
            print(project_configuration.get_value("workspace_name"))
            raise

        cls.create(
            subscription_id=project_configuration.get_value("subscription_id"),
            resource_group=project_configuration.get_value("resource_group"),
            name=project_configuration.get_value("workspace_name"),
            location=project_configuration.get_value("workspace_region"),
            exist_ok=True,
        )

        ws = cls(
            subscription_id=project_configuration.get_value("subscription_id"),
            resource_group=project_configuration.get_value("resource_group"),
            workspace_name=project_configuration.get_value("workspace_name"),
            project_configuration=project_configuration,
            **kwargs)
        return ws
Exemple #4
0
def get_or_create_image(
    image_config,
    image_settings_name,
    show_output,
    models=None,
    configuration_file: str = project_configuration_file,
):
    """

    :param image_config:
    :param image_settings_name:
    :param models:
    :param show_output:
    :param configuration_file: path to project configuration file. default: project.yml
:return:
    """
    if not models:
        models = []

    project_configuration = ProjectConfiguration(configuration_file)

    assert project_configuration.has_value(image_settings_name)
    image_name = project_configuration.get_value(image_settings_name)

    workspace = get_or_create_workspace_from_project(
        project_configuration, show_output=show_output
    )

    workspace_images = workspace.images
    if (
        image_name in workspace_images
        and workspace_images[image_name].creation_state != "Failed"
    ):
        return workspace_images[image_name]

    image_create_start = time.time()
    image = ContainerImage.create(
        name=image_name, models=models, image_config=image_config, workspace=workspace
    )
    image.wait_for_creation(show_output=show_output)
    assert image.creation_state != "Failed"
    if show_output:
        print_image_deployment_info(image, image_name, image_create_start)
    return image
Exemple #5
0
def update_setting_boxes(new_proj_config: ProjectConfiguration,
                         setting_boxes: dict, id2name: dict):
    """
    Update Settings with new Project Configuration

    :param new_proj_config: Newly loaded project configuration
    :param setting_boxes: list of setting widgets
    :param id2name: mapping of sub ids to sub names
    """
    for setting_box_key in setting_boxes:
        if new_proj_config.has_value(setting_box_key):
            if setting_box_key == "subscription_id":
                setting_boxes[setting_box_key].value = id2name[
                    new_proj_config.get_value(setting_box_key)]
            else:
                setting_boxes[
                    setting_box_key].value = new_proj_config.get_value(
                        setting_box_key)
        else:
            warnings.warn("Reload Widget to display new properties")
Exemple #6
0
class WorkspaceContext(Workspace):
    """
    AzureML Workspace Context - Base Framework Interface
    """
    def __init__(self,
                 subscription_id: str,
                 resource_group: str,
                 workspace_name: str,
                 configuration_file: str = project_configuration_file,
                 project_configuration=None,
                 train_py: str = train_py_default,
                 score_py: str = score_py_default,
                 **kwargs):
        """
        Interface Constructor for Workspace Context

        :param subscription_id: Azure subscription id
        :param resource_group: Azure Resource Group name
        :param workspace_name: Azure Machine Learning Workspace
        :param configuration_file: path to project configuration file. default: project.yml
        :param train_py: python source file for training
        :param score_py: python source file for scoring
        """
        super().__init__(subscription_id, resource_group, workspace_name,
                         **kwargs)
        if not project_configuration:
            self.project_configuration = ProjectConfiguration(
                configuration_file)

        self.image_tags = None
        self.args = None
        self.train_py = train_py
        self.score_py = score_py
        self.show_output = True
        self.source_directory = "./script"
        self.experiment_name = None
        self.model_name = None
        self.wait_for_completion = True
        self.model_path = None

    @classmethod
    def get_or_create_workspace(
            cls,
            configuration_file: str = project_configuration_file,
            project_configuration: ProjectConfiguration = None,
            **kwargs):
        """ Get or create a workspace if it doesn't exist.

        :param configuration_file:
        :param project_configuration: ProjectConfiguration
        """
        if not project_configuration:
            project_configuration = ProjectConfiguration(configuration_file)
        assert project_configuration.has_value("subscription_id")
        assert project_configuration.has_value("resource_group")
        assert project_configuration.has_value("workspace_name")
        assert project_configuration.has_value("workspace_region")

        try:
            check_valid_resource_name(
                project_configuration.get_value("workspace_name"), "Workspace")
        except UserErrorException:
            print(project_configuration.get_value("workspace_name"))
            raise

        cls.create(
            subscription_id=project_configuration.get_value("subscription_id"),
            resource_group=project_configuration.get_value("resource_group"),
            name=project_configuration.get_value("workspace_name"),
            location=project_configuration.get_value("workspace_region"),
            exist_ok=True,
        )

        ws = cls(
            subscription_id=project_configuration.get_value("subscription_id"),
            resource_group=project_configuration.get_value("resource_group"),
            workspace_name=project_configuration.get_value("workspace_name"),
            project_configuration=project_configuration,
            **kwargs)
        return ws

    @staticmethod
    def _get_file_md5(file_name: str) -> str:
        hasher = hashlib.md5()
        with open(file_name, "rb") as afile:
            buf = afile.read()
            hasher.update(buf)
        file_hash = hasher.hexdigest()
        return file_hash

    def assert_and_get_value(self, setting_name: str) -> str:
        """

        :param setting_name:
        :return:
        """
        assert self.project_configuration.has_value(setting_name)
        return self.project_configuration.get_value(setting_name)