本文整理匯總了Python中azureml.core.Workspace.create方法的典型用法代碼示例。如果您正苦於以下問題:Python Workspace.create方法的具體用法?Python Workspace.create怎麽用?Python Workspace.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類azureml.core.Workspace
的用法示例。
在下文中一共展示了Workspace.create方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create
# 需要導入模塊: from azureml.core import Workspace [as 別名]
# 或者: from azureml.core.Workspace import create [as 別名]
def create(self, name):
name = self._get_name(name)
region = self.ctx.config.get('cluster/region', 'eastus2')
resource_group = self.ctx.config.get(
'resource_group', name+'-resources')
self.ctx.log('Creating %s' % name)
self.ws = Workspace.create(
name=name,
subscription_id=self.credentials.subscription_id,
resource_group=resource_group,
create_resource_group=True,
location=region,
auth=self.credentials.get_serviceprincipal_auth())
self._select(name)
self.ctx.log('%s created' % name)
return {'created': name}
示例2: _create_mlflow_wheel
# 需要導入模塊: from azureml.core import Workspace [as 別名]
# 或者: from azureml.core.Workspace import create [as 別名]
def _create_mlflow_wheel(mlflow_dir, out_dir):
"""
Create the wheel of MLFlow by using setup.py bdist_wheel in the outdir.
:param mlflow_dir: The absolute path to base of the MLflow Repo to create a wheel from..
:param out_dir: The absolute path to the outdir.
Will be created if it does not exist.
:return: The absolute path to the wheel.
"""
unresolved = Path(out_dir)
unresolved.mkdir(parents=True, exist_ok=True)
out_path = unresolved.resolve()
subprocess.run([sys.executable, "setup.py", "bdist_wheel", "-d", out_path],
cwd=mlflow_dir, check=True)
files = list(out_path.glob("./*.whl"))
if len(files) < 1:
raise MlflowException("Error creating MLFlow Wheel - couldn't"
" find it in dir {} - found {}".format(out_path, files))
if len(files) > 1:
raise MlflowException(
"Error creating MLFlow Wheel - couldn't"
" find it in dir {} - found several wheels {}".format(out_path, files))
return files[0]
示例3: _get_ws
# 需要導入模塊: from azureml.core import Workspace [as 別名]
# 或者: from azureml.core.Workspace import create [as 別名]
def _get_ws(self, name = None, create_if_not_exist = False):
name = self._get_name(name)
try:
self.ws = Workspace.get(
name,
subscription_id=self.credentials.subscription_id,
auth=self.credentials.get_serviceprincipal_auth())
except Exception as e:
if create_if_not_exist:
self.create(name)
else:
raise e
return self.ws
示例4: main
# 需要導入模塊: from azureml.core import Workspace [as 別名]
# 或者: from azureml.core.Workspace import create [as 別名]
def main(argv):
try:
opts, args = getopt.getopt(argv,"hs:rg:wn:wr:",["subscription_id=","resource_group=","workspace_name=", "workspace_region="])
except getopt.GetoptError:
print 'aml_creation.py -s <subscription_id> -rg <resource_group> -wn <workspace_name> -wr <workspace_region>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'aml_creation.py -s <subscription_id> -rg <resource_group> -wn <workspace_name> -wr <workspace_region>'
sys.exit()
elif opt in ("-s", "--subscription_id"):
subscription_id = arg
elif opt in ("-rg", "--resource_group"):
resource_group = arg
elif opt in ("-wn", "--workspace_name"):
workspace_name = arg
elif opt in ("-wr", "--workspace_region"):
workspace_region = arg
env_path = find_dotenv()
if env_path == "":
Path(".env").touch()
env_path = find_dotenv()
ws = Workspace.create(
name=workspace_name,
subscription_id=subscription_id,
resource_group=resource_group,
location=workspace_region,
create_resource_group=True,
auth=get_auth(env_path),
exist_ok=True,
)
示例5: main
# 需要導入模塊: from azureml.core import Workspace [as 別名]
# 或者: from azureml.core.Workspace import create [as 別名]
def main(argv):
try:
opts, args = getopt.getopt(argv,"hs:rg:wn:wr:dsn:cn:an:ak:drg:",
["subscription_id=","resource_group=","workspace_name=", "workspace_region=","blob_datastore_name=","container_name=","account_name=","account_key=","datastore_rg="])
except getopt.GetoptError:
print 'aml_creation.py -s <subscription_id> -rg <resource_group> -wn <workspace_name> -wr <workspace_region>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'aml_creation.py -s <subscription_id> -rg <resource_group> -wn <workspace_name> -wr <workspace_region>'
sys.exit()
elif opt in ("-s", "--subscription_id"):
subscription_id = arg
elif opt in ("-rg", "--resource_group"):
resource_group = arg
elif opt in ("-wn", "--workspace_name"):
workspace_name = arg
elif opt in ("-wr", "--workspace_region"):
workspace_region = arg
elif opt in ("-dsn", "--blob_datastore_name"):
workspace_region = arg
elif opt in ("-cn", "--container_name"):
workspace_region = arg
elif opt in ("-an", "--account_name"):
workspace_region = arg
elif opt in ("-ak", "--account_key"):
workspace_region = arg
elif opt in ("-drg", "--datastore_rg"):
workspace_region = arg
env_path = find_dotenv()
if env_path == "":
Path(".env").touch()
env_path = find_dotenv()
ws = Workspace.create(
name=workspace_name,
subscription_id=subscription_id,
resource_group=resource_group,
location=workspace_region,
create_resource_group=True,
auth=get_auth(env_path),
exist_ok=True,
)
blob_datastore = Datastore.register_azure_blob_container(workspace=ws,
datastore_name=blob_datastore_name,
container_name=container_name,
account_name=account_name,
account_key=account_key,
resource_group=datastore_rg)
示例6: get_or_create_workspace
# 需要導入模塊: from azureml.core import Workspace [as 別名]
# 或者: from azureml.core.Workspace import create [as 別名]
def get_or_create_workspace(
config_path="./.azureml", subscription_id=None, resource_group=None, workspace_name=None, workspace_region=None,
):
"""
Method to get or create workspace.
Args:
config_path: optional directory to look for / store config.json file (defaults to current
directory)
subscription_id: Azure subscription id
resource_group: Azure resource group to create workspace and related resources
workspace_name: name of azure ml workspace
workspace_region: region for workspace
Returns:
obj: AzureML workspace if one exists already with the name otherwise creates a new one.
"""
config_file_path = "."
if config_path is not None:
config_dir, config_file_name = os.path.split(config_path)
if config_file_name != "config.json":
config_file_path = os.path.join(config_path, "config.json")
try:
# Get existing azure ml workspace
if os.path.isfile(config_file_path):
ws = Workspace.from_config(config_file_path, auth=get_auth())
else:
ws = Workspace.get(
name=workspace_name, subscription_id=subscription_id, resource_group=resource_group, auth=get_auth(),
)
except ProjectSystemException:
# This call might take a minute or two.
print("Creating new workspace")
ws = Workspace.create(
name=workspace_name,
subscription_id=subscription_id,
resource_group=resource_group,
create_resource_group=True,
location=workspace_region,
auth=get_auth(),
)
ws.write_config(path=config_path)
return ws
示例7: get_or_create_amlcompute
# 需要導入模塊: from azureml.core import Workspace [as 別名]
# 或者: from azureml.core.Workspace import create [as 別名]
def get_or_create_amlcompute(
workspace, compute_name, vm_size="", min_nodes=0, max_nodes=None, idle_seconds_before_scaledown=None, verbose=False,
):
"""
Get or create AmlCompute as the compute target. If a cluster of the same name is found,
attach it and rescale accordingly. Otherwise, create a new cluster.
Args:
workspace (Workspace): workspace
compute_name (str): name
vm_size (str, optional): vm size
min_nodes (int, optional): minimum number of nodes in cluster
max_nodes (None, optional): maximum number of nodes in cluster
idle_seconds_before_scaledown (None, optional): how long to wait before the cluster
autoscales down
verbose (bool, optional): if true, print logs
Returns:
Compute target
"""
try:
if verbose:
print("Found compute target: {}".format(compute_name))
compute_target = ComputeTarget(workspace=workspace, name=compute_name)
if len(compute_target.list_nodes()) < max_nodes:
if verbose:
print("Rescaling to {} nodes".format(max_nodes))
compute_target.update(max_nodes=max_nodes)
compute_target.wait_for_completion(show_output=verbose)
except ComputeTargetException:
if verbose:
print("Creating new compute target: {}".format(compute_name))
compute_config = AmlCompute.provisioning_configuration(
vm_size=vm_size,
min_nodes=min_nodes,
max_nodes=max_nodes,
idle_seconds_before_scaledown=idle_seconds_before_scaledown,
)
compute_target = ComputeTarget.create(workspace, compute_name, compute_config)
compute_target.wait_for_completion(show_output=verbose)
return compute_target
示例8: get_or_create_workspace
# 需要導入模塊: from azureml.core import Workspace [as 別名]
# 或者: from azureml.core.Workspace import create [as 別名]
def get_or_create_workspace(
config_path="./.azureml",
subscription_id=None,
resource_group=None,
workspace_name=None,
workspace_region=None,
):
"""
Method to get or create workspace.
Args:
config_path: optional directory to look for / store config.json file (defaults to current
directory)
subscription_id: Azure subscription id
resource_group: Azure resource group to create workspace and related resources
workspace_name: name of azure ml workspace
workspace_region: region for workspace
Returns:
obj: AzureML workspace if one exists already with the name otherwise creates a new one.
"""
config_file_path = "."
if config_path is not None:
config_dir, config_file_name = os.path.split(config_path)
if config_file_name != "config.json":
config_file_path = os.path.join(config_path, "config.json")
try:
# get existing azure ml workspace
if os.path.isfile(config_file_path):
ws = Workspace.from_config(config_file_path, auth=get_auth())
else:
ws = Workspace.get(
name=workspace_name,
subscription_id=subscription_id,
resource_group=resource_group,
auth=get_auth(),
)
except ProjectSystemException:
# this call might take a minute or two.
print("Creating new workspace")
ws = Workspace.create(
name=workspace_name,
subscription_id=subscription_id,
resource_group=resource_group,
create_resource_group=True,
location=workspace_region,
auth=get_auth(),
)
ws.write_config(path=config_path)
return ws
示例9: get_or_create_amlcompute
# 需要導入模塊: from azureml.core import Workspace [as 別名]
# 或者: from azureml.core.Workspace import create [as 別名]
def get_or_create_amlcompute(
workspace,
compute_name,
vm_size="",
min_nodes=0,
max_nodes=None,
idle_seconds_before_scaledown=None,
verbose=False,
):
"""
Get or create AmlCompute as the compute target. If a cluster of the same name is found,
attach it and rescale accordingly. Otherwise, create a new cluster.
Args:
workspace (Workspace): workspace
compute_name (str): name
vm_size (str, optional): vm size
min_nodes (int, optional): minimum number of nodes in cluster
max_nodes (None, optional): maximum number of nodes in cluster
idle_seconds_before_scaledown (None, optional): how long to wait before the cluster
autoscales down
verbose (bool, optional): if true, print logs
Returns:
Compute target
"""
try:
if verbose:
print("Found compute target: {}".format(compute_name))
compute_target = ComputeTarget(workspace=workspace, name=compute_name)
if len(compute_target.list_nodes()) < max_nodes:
if verbose:
print("Rescaling to {} nodes".format(max_nodes))
compute_target.update(max_nodes=max_nodes)
compute_target.wait_for_completion(show_output=verbose)
except ComputeTargetException:
if verbose:
print("Creating new compute target: {}".format(compute_name))
compute_config = AmlCompute.provisioning_configuration(
vm_size=vm_size,
min_nodes=min_nodes,
max_nodes=max_nodes,
idle_seconds_before_scaledown=idle_seconds_before_scaledown,
)
compute_target = ComputeTarget.create(workspace, compute_name, compute_config)
compute_target.wait_for_completion(show_output=verbose)
return compute_target