Azure ML Defaults

1.62.0 · active · verified Thu Apr 16

azureml-defaults is a metapackage provided by Microsoft Azure Machine Learning. It simplifies the installation of the Azure ML SDK by pulling in a curated set of `azureml-*` packages (like `azureml-core`, `azureml-data`, `azureml-train`) at compatible versions. Its primary purpose is to ensure users have a consistent and working environment for developing Azure ML solutions. The current version is 1.62.0, and updates typically align with the broader Azure ML SDK release cycle.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to connect to an existing Azure Machine Learning Workspace and initiate a simple experiment run using the `azureml.core` components that `azureml-defaults` ensures are installed. It highlights the importance of authentication and workspace configuration (via `config.json` or environment variables) for local development.

import os
from azureml.core import Workspace, Experiment, Environment

# NOTE: For local execution, ensure you have a config.json or environment variables.
# You can create a config.json by connecting to your workspace in Azure portal
# and downloading the config.json file.

# Example for connecting to an existing workspace
try:
    ws = Workspace.from_config() # Looks for config.json in current directory or parent directories
    print(f"Workspace name: {ws.name}, Resource Group: {ws.resource_group}, Location: {ws.location}")

    # Create a simple experiment
    exp = Experiment(workspace=ws, name="my-first-azureml-experiment")
    print(f"Experiment name: {exp.name}")

    # Start a run (this example won't submit to a remote compute, just demonstrates API)
    with exp.start_logging() as run:
        run.log('hello_world', 'true')
        print("Run logged 'hello_world'")
        print(f"Run ID: {run.id}")

except Exception as e:
    print(f"Error connecting to workspace or running experiment: {e}")
    print("Please ensure you are authenticated (e.g., 'az login') or have a valid config.json.")
    print("You might need to set AZUREML_CR_NAME, AZUREML_CR_RESOURCE_GROUP, AZUREML_CR_SUBSCRIPTION_ID in environment variables.")

# Example of creating a workspace (requires Azure CLI login and permissions)
# from azureml.core.authentication import AzureCliAuthentication
# try:
#     cli_auth = AzureCliAuthentication()
#     ws = Workspace.create(
#         name='myworkspacename',
#         subscription_id=os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUB_ID'),
#         resource_group='myresourcegroup',
#         create_resource_group=True,
#         location='eastus',
#         auth=cli_auth
#     )
#     print(f"Created workspace: {ws.name}")
# except Exception as e:
#     print(f"Could not create workspace: {e}")

view raw JSON →