0

I am trying to run a machine learning experiment in azureml.

I can't figure out how to get the workspace context from the control script. Examples like this one in the microsoft docs use Workspace.from_config(). When I use this in the control script I get the following error:

"message": "We could not find config.json in: [path] or in its parent directories. Please provide the full path to the config file or ensure that config.json exists in the parent directories."

I've also tried including my subscription id and the resource specs like so:

subscription_id = 'id'
resource_group = 'name'
workspace_name = 'name'

workspace = Workspace(subscription_id, resource_group, workspace_name)

In this case I have to monitor the log and authenticate on each run as I would locally.

How do you get the local workspace from a control script for azureml?

B. Bogart
  • 998
  • 6
  • 15

3 Answers3

0

Using Workspace.from_config() method:

The workspace configuration file is a JSON file that tells the SDK how to communicate with your Azure Machine Learning workspace. The file is named config.json, and it has the following format:

{"subscription_id": "<subscription-id>",
 "resource_group": "<resource-group>",
 "workspace_name": "<workspace-name>"}
  • IMPORTANT: This JSON file must be in the directory structure that contains your Python scripts or Jupyter Notebooks. It can be in the same directory, a subdirectory named .azureml, or in a parent directory.

Alternatively, use the get method to load an existing workspace without using configuration files: (in your case, your code is missing the .get())

ws = Workspace.get(name="myworkspace",subscription_id='<azure-subscription-id>',resource_group='myresourcegroup')
nferreira78
  • 1,013
  • 4
  • 17
0

What is the development system that you are using? A DSVM in the AML workspace or your local dev system?

If it is your local then use this to write config file to your project root directory under the path /.azureml/config.json

from azureml.core import Workspace

subscription_id = 'xxxx-xxxx-xxxx-xxxx-xxxx'
resource_group  = 'your_resource_group'
workspace_name  = 'your_workspace_name'

try:
   ws = Workspace(subscription_id = subscription_id, resource_group = 
   resource_group, workspace_name = workspace_name)
   ws.write_config()
   print('Library configuration succeeded')
except:
   print('Workspace not found')

or else if it DSVM, then you are all set, Workspace.from_config() should work.

Note: You will have to see .config directory under your user name in AML studio.

Priya
  • 723
  • 1
  • 5
  • 7
0

This had no answers for 10 months, and now they are coming in :). I figuerd this out quite a while ago but haven't gotten around to posting the answer. Here it is.

From the training script, you can get the workspace from the run context as follows:

from azureml.core import Run
Run.get_context()
ws = run.experiment.workspace
B. Bogart
  • 998
  • 6
  • 15