Hi all,

today I want to tackle the issue of bulk copying more than one Azure ML experiment at once between different workspaces.

May be you already know that you can partially solve this task by copying an experiment one at a time. But you have to access to both the workspaces with your user. If not, you can simply share a workspace in this way:

https://docs.microsoft.com/en-us/azure/machine-learning/machine-learning-create-workspace

Once you can see both the workspaces in your Azure Machine Learning Studio, you can simply select an experiment and than “Copy to workspace”:

AzureML_Copy_001

and than you can choose the destination workspace:

AzureML_Copy_002

A you can imagine… you can’t simply select more than one experiment and than copy all them:

AzureML_Copy_000

Now suppose you have dozens of experiments and simply you don’t want to waste your time coping them all manually, or moreover you can’t have access to a shared workspace for security reasons. Is there a way to bulk copy your experiments? I’ll show you how to do that using few rows of PowerShell.

Azure ML PowerShell Configuration

First of all, you need to download the PowerShell Module for Azure Machine Learning Studio & Web Services from this link:

https://github.com/hning86/azuremlps

It allows you to interact with Azure Machine Learning Workspaces, Datasets, Trained Models, Transforms, Custom Modules, Experiments, Web Services and Web Service Endpoints.

Just click on the “%% releases” link:

AzureML_Copy_003

and download the top most available download from the page:

AzureML_Copy_004

Then be sure to unpack the two files (.dll and .json) in your preferred folder:

AzureML_Copy_005

I unpacked them in my C:\Install\AzureMLPS\ folder.

Then clone the json file in two other files: one is used for your source workspace (config_source.json) and the other for your destination workspace (config_destination.json). If you open your config_source.json file in any editor, you can see this code:

{
"Location": "South Central US (or other supported region)",
"WorkspaceId": "",
"AuthorizationToken": ""
}

So you simply have to replace the < ... > tokens and the Location with the ones of your source workspace. In particular you can find these information as shown below:

AzureML_Copy_006
AzureML_Copy_007
AzureML_Copy_008

In the example above I choose the secondary authorization token, but you could use the primary too. The two tokens are equivalent, they are there just to help you in case you have to rotate the keys.

So the content of my config_source.json file become:

{
"Location": "South Central US",
"WorkspaceId": "8******************************8",
"AuthorizationToken": "B**************************************="
}

In the same way, change the content of your config_destination.json file, so that it’ll refer the destination workspace.

Just Use the Scripts: Copy the Experiments between Workspaces

Ok, now it’s time to have fun with few rows of PowerShell script! Simply go to my repository:

https://github.com/lucazav/azureml-scripts

and download the zip file:

AzureML_Copy_009

Unpack the script files it contains in your preferred folder. Now open the Windows PowerShell ISE:

AzureML_Copy_010

Then open the AzureML-Scripts_CopyExperimentsBetweenWorkspacesGUI.ps1 file just dragging it into the PowerShell ISE workspace (or using the usual Open FIle feature of all the IDEs).

Now make sure to edit the paths of your source and destination workspace config files:

AzureML_Copy_012

Just push the Run button (the green arrow in the toolbar) or F5 and that’s it! A dazzling grid view windows will pop up. It contains all the experiments of your source workspace. You can filter the content of each column you can see using the Filter textbox and you can select one or more experiments holding down the CTRL or the SHIF key as usual:

AzureML_Copy_013

Now push the OK button and the copy operation will start:

AzureML_Copy_014

If your original experiment contains datasets, those are automatically deep-copied into the new workspace. Trained models or transforms are not copied instead. If there are any name collisions with existing assets, they get automatically renamed as well.

Just Use the Scripts: Export the Experiments in JSON Files

Suppose you can’t access to the destination workspace’s authorization tokens due to security policies, but you need to bulk copy some experiments to that workspace. The above mentioned script is not useful to you in this case. Also suppose you are using an Azure ML free account, that has a limited storage of 10 GB, and you are out of space. What if you want to backup your experiments so that you can delete them in the workspace to free up some space? Here a simply solution for both the cases.

Just open the the AzureML-Scripts_ExportExperimentsFromWorkspaceGUI.ps1 file and make sure to edit the path of your source workspace config file and the path of your destination folder that will contain the JSON files to be exported:

AzureML_Copy_015

Then just push the Run button and a grid view window containing the experiments of the source workspace will pop up. Just select one or more experiment to export and than push the OK button. Your JSON files will be created in your destination folder:

AzureML_Copy_016

Now you can zip and store them as a backup of your experiments, or you can send the zip file to the destination workspace owner so that he can import the experiments by himself.

Just Use the Scripts: Import the Experiments from JSON Files

If you have to restore some JSON files you created earlier, or if you receive some JSON files to import in your workspace, than you can use the AzureML-Scripts_ImportExperimentFromJsonFiles.ps1 file. As well as the scripts we have seen before, even in this case you have to edit just few parameters. You have to edit the path of the folder containing the source JSON files, the destination workspace config file and a new parameter: a boolean value ( $true or  $false in PowerShell) that indicates if you want to assign to the experiments the corresponding JSON file name ( $true ) or the original experiment name ( $false ):

AzureML_Copy_017

Then you can Run the script and a grid view window containing all the JSON files found in the source folder:

AzureML_Copy_018

Just select one or more files and press the OK button. Your files will be imported as the apiTestUser author:

AzureML_Copy_019

After then you can enjoy your experiments on the destination workspace.

Conclusions

Sometimes you have to deal with dozens of experiments to copy to a destination workspace. You can copy them manually using Azure ML Studio, but with some limitations:

  1. you must have access to the destination workspace after someone has shared it to you;
  2. then you can copy them one at a time.

Moreover you often need to make a copy of your experiments as a backup, especially if you need to free up some space into your workspace storage.

You can easily solve this cases using few PowerShell scripts I described above.

Enjoy your Azure Machine Learning experiments!