BatchCompute Class

Manages a Batch compute target in Azure Machine Learning.

Azure Batch is used to run large-scale parallel and high-performance computing (HPC) applications efficiently in the cloud. BatchCompute is used in Azure Machine Learning Pipelines to submit jobs to an Azure Batch pool of machines using an AzureBatchStep. For more information, see What are compute targets in Azure Machine Learning?

Class ComputeTarget constructor.

Retrieve a cloud representation of a Compute object associated with the provided workspace. Returns an instance of a child class corresponding to the specific type of the retrieved Compute object.

Inheritance
BatchCompute

Constructor

BatchCompute(workspace, name)

Parameters

Name Description
workspace
Required

The workspace object containing the BatchCompute object to retrieve.

name
Required
str

The name of the BatchCompute object to retrieve.

workspace
Required

The workspace object containing the Compute object to retrieve.

name
Required
str

The name of the of the Compute object to retrieve.

Remarks

Create an Azure Batch account before using it. To create one, see Create a Batch account with the Azure portal.

The following example shows how to attach a Azure Batch compute account to a workspace using attach_configuration.


   batch_compute_name = 'mybatchcompute' # Name to associate with new compute in workspace

   # Batch account details needed to attach as compute to workspace
   batch_account_name = "<batch_account_name>" # Name of the Batch account
   batch_resource_group = "<batch_resource_group>" # Name of the resource group which contains this account

   try:
       # check if already attached
       batch_compute = BatchCompute(ws, batch_compute_name)
   except ComputeTargetException:
       print('Attaching Batch compute...')
       provisioning_config = BatchCompute.attach_configuration(resource_group=batch_resource_group,
                                                               account_name=batch_account_name)
       batch_compute = ComputeTarget.attach(ws, batch_compute_name, provisioning_config)
       batch_compute.wait_for_completion()
       print("Provisioning state:{}".format(batch_compute.provisioning_state))
       print("Provisioning errors:{}".format(batch_compute.provisioning_errors))

   print("Using Batch compute:{}".format(batch_compute.cluster_resource_id))

Full sample is available from https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-how-to-use-azurebatch-to-run-a-windows-executable.ipynb

Methods

attach_configuration

Create a configuration object for attaching a Batch compute target.

delete

Delete is not supported for a BatchCompute object. Use detach instead.

deserialize

Convert a JSON object into a BatchCompute object.

detach

Detaches the Batch object from its associated workspace.

Underlying cloud objects are not deleted, only the association is removed.

refresh_state

Perform an in-place update of the properties of the object.

This method updates the properties based on the current state of the corresponding cloud object. This is primarily used for manual polling of compute state.

serialize

Convert this BatchCompute object into a JSON serialized dictionary.

attach_configuration

Create a configuration object for attaching a Batch compute target.

static attach_configuration(resource_group=None, account_name=None, resource_id=None)

Parameters

Name Description
resource_group
str

The name of the resource group in which the Batch account is located.

Default value: None
account_name
str

The Batch account name.

Default value: None
resource_id
str

The Azure resource ID for the compute resource being attached.

Default value: None

Returns

Type Description

A configuration object to be used when attaching a Compute object.

delete

Delete is not supported for a BatchCompute object. Use detach instead.

delete()

Exceptions

Type Description

deserialize

Convert a JSON object into a BatchCompute object.

static deserialize(workspace, object_dict)

Parameters

Name Description
workspace
Required

The workspace object the BatchCompute object is associated with.

object_dict
Required

A JSON object to convert to a BatchCompute object.

Returns

Type Description

The BatchCompute representation of the provided JSON object.

Exceptions

Type Description

Remarks

Raises a ComputeTargetException if the provided workspace is not the workspace the Compute is associated with.

detach

Detaches the Batch object from its associated workspace.

Underlying cloud objects are not deleted, only the association is removed.

detach()

Exceptions

Type Description

refresh_state

Perform an in-place update of the properties of the object.

This method updates the properties based on the current state of the corresponding cloud object. This is primarily used for manual polling of compute state.

refresh_state()

serialize

Convert this BatchCompute object into a JSON serialized dictionary.

serialize()

Returns

Type Description

The JSON representation of this BatchCompute object.