本文整理汇总了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