Skip to content

Commit

Permalink
Requiring the list of providers as argument on workspace creation (Az…
Browse files Browse the repository at this point in the history
…ure#3165)

* Making the list of providers a required argument on workspace creation
* Update test recordings
  • Loading branch information
ricardo-espinoza authored Mar 23, 2021
1 parent 2632452 commit 5790e3a
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 259 deletions.
4 changes: 0 additions & 4 deletions src/quantum/azext_quantum/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,6 @@
type: command
short-summary: Create a new Azure Quantum workspace.
examples:
- name: Create a new Azure Quantum workspace with default provider.
text: |-
az quantum workspace create -g MyResourceGroup -w MyWorkspace -l MyLocation \\
-a MyStorageAccountName
- name: Create a new Azure Quantum workspace with a specific list of providers.
text: |-
az quantum workspace create -g MyResourceGroup -w MyWorkspace -l MyLocation \\
Expand Down
20 changes: 4 additions & 16 deletions src/quantum/azext_quantum/operations/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
DEFAULT_WORKSPACE_LOCATION = 'westus'
POLLING_TIME_DURATION = 3
MAX_RETRIES_ROLE_ASSIGNMENT = 10
DEFAULT_WORKSPACE_PROVIDER_ID = 'Microsoft'
DEFAULT_WORKSPACE_PROVIDER_SKU = 'Basic'


class WorkspaceInfo(object):
Expand Down Expand Up @@ -76,12 +74,7 @@ def _get_storage_account_path(workspaceInfo, storage_account_name):

def _get_basic_quantum_workspace(location, info, storage_account):
qw = QuantumWorkspace(location=location)
# Use a default provider
# Replace this with user specified providers as part of task 16184.
prov = Provider()
prov.provider_id = DEFAULT_WORKSPACE_PROVIDER_ID
prov.provider_sku = DEFAULT_WORKSPACE_PROVIDER_SKU
qw.providers = [prov]
qw.providers = []
# Allow the system to assign the workspace identity
qw.identity = QuantumWorkspaceIdentity()
qw.identity.type = "SystemAssigned"
Expand Down Expand Up @@ -114,9 +107,6 @@ def _add_quantum_providers(cmd, workspace, providers):
_show_tip(f"Workspace creation has been requested with the following providers:\n{providers_selected}")
# Now that the providers have been requested, add each of them into the workspace
for provider in providers_selected:
if (provider['provider_id'].lower() == DEFAULT_WORKSPACE_PROVIDER_ID.lower() and provider['sku'].lower() == DEFAULT_WORKSPACE_PROVIDER_SKU.lower()):
# We can skip the default provider since it will be added always.)
continue
if _provider_terms_need_acceptance(cmd, provider):
raise CLIError(f"Terms for Provider '{provider['provider_id']}' and SKU '{provider['sku']}' have not been accepted.\n"
"Use command 'az quantum offerings accept-terms' to accept them.")
Expand Down Expand Up @@ -161,15 +151,13 @@ def create(cmd, resource_group_name=None, workspace_name=None, location=None, st
raise CLIError("A quantum workspace requires a valid storage account.")
if (not location):
raise CLIError("A location for the new quantum workspace is required.")
if (provider_sku_list is None):
raise CLIError("A list of Azure Quantum providers and SKUs is required.")
info = WorkspaceInfo(cmd, resource_group_name, workspace_name, location)
if (not info.resource_group):
raise CLIError("Please run 'az quantum workspace set' first to select a default resource group.")
quantum_workspace = _get_basic_quantum_workspace(location, info, storage_account)
if (provider_sku_list is None):
_show_tip(f"Workspace {info.name} will be created with the Basic SKU of the Microsoft QIO optimization provider.\n"
"Please go to the Azure portal https://portal.azure.com/ to configure additional providers.")
else:
_add_quantum_providers(cmd, quantum_workspace, provider_sku_list)
_add_quantum_providers(cmd, quantum_workspace, provider_sku_list)
poller = client.create_or_update(info.resource_group, info.name, quantum_workspace, polling=False)
while not poller.done():
time.sleep(POLLING_TIME_DURATION)
Expand Down
12 changes: 6 additions & 6 deletions src/quantum/azext_quantum/tests/latest/recordings/test_jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Fri, 29 Jan 2021 17:44:48 GMT
- Mon, 22 Mar 2021 16:47:04 GMT
etag:
- '"07009043-0000-3300-0000-5fa7d2e40000"'
expires:
- '-1'
pragma:
- no-cache
server:
- Kestrel
strict-transport-security:
- max-age=31536000; includeSubDomains
transfer-encoding:
Expand All @@ -48,6 +46,8 @@ interactions:
- Accept-Encoding
x-content-type-options:
- nosniff
x-ms-providerhub-traffic:
- 'True'
status:
code: 200
message: OK
Expand All @@ -69,14 +69,14 @@ interactions:
uri: https://eastus2euap.quantum.azure.com/v1.0/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testalias-e2e-tests-canary-rg/providers/Microsoft.Quantum/workspaces/e2e-tests-workspace-ionq/providerStatus
response:
body:
string: '{"value":[{"id":"ionq","currentAvailability":"Available","targets":[{"id":"ionq.qpu","currentAvailability":"Available","averageQueueTime":140,"statusPage":"https://status.ionq.co"},{"id":"ionq.simulator","currentAvailability":"Available","averageQueueTime":0,"statusPage":"https://status.ionq.co"}]}],"nextLink":null}'
string: '{"value":[{"id":"ionq","currentAvailability":"Available","targets":[{"id":"ionq.qpu","currentAvailability":"Available","averageQueueTime":5105,"statusPage":"https://status.ionq.co"},{"id":"ionq.simulator","currentAvailability":"Available","averageQueueTime":0,"statusPage":"https://status.ionq.co"}]}],"nextLink":null}'
headers:
content-length:
- '317'
- '318'
content-type:
- application/json; charset=utf-8
date:
- Fri, 29 Jan 2021 17:44:52 GMT
- Mon, 22 Mar 2021 16:47:08 GMT
request-context:
- appId=cid-v1:4d6ac272-7369-45c6-9036-63d733c8519f
server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,26 @@ interactions:
accept-language:
- en-US
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aqua-provider-validator/providers/Microsoft.Quantum/workspaces/validator-qio-parallel-tempering-cpu-eastus2euap?api-version=2019-11-04-preview
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/validator-test-rg/providers/Microsoft.Quantum/workspaces/testworkspace-canary-microsoft?api-version=2019-11-04-preview
response:
body:
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aqua-provider-validator/providers/microsoft.quantum/workspaces/validator-qio-parallel-tempering-cpu-eastus2euap","name":"validator-qio-parallel-tempering-cpu-eastus2euap","type":"microsoft.quantum/workspaces","location":"eastus2euap","properties":{"providers":[{"providerId":"Microsoft","providerSku":"Basic","applicationName":"validator-qio-parallel-tempering-cpu-eastus2euap-Microsoft","provisioningState":"Succeeded"}],"provisioningState":"Succeeded","usable":"Yes"}}'
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/validator-test-rg/providers/microsoft.quantum/workspaces/testworkspace-canary-microsoft","name":"testworkspace-canary-microsoft","type":"microsoft.quantum/workspaces","location":"East
US 2 EUAP","properties":{"providers":[{"providerId":"Microsoft","providerSku":"basic","applicationName":"testworkspace-canary-microsoft-Microsoft","provisioningState":"Succeeded"}],"provisioningState":"Succeeded","usable":"Yes"}}'
headers:
cache-control:
- no-cache
content-length:
- '544'
- '487'
content-type:
- application/json; charset=utf-8
date:
- Fri, 29 Jan 2021 17:44:49 GMT
- Mon, 22 Mar 2021 16:47:05 GMT
etag:
- '"0200b0aa-0000-3400-0000-5fd8fcfb0000"'
- '"07008443-0000-3300-0000-5fa7d2e40000"'
expires:
- '-1'
pragma:
- no-cache
server:
- Kestrel
strict-transport-security:
- max-age=31536000; includeSubDomains
transfer-encoding:
Expand All @@ -47,6 +46,8 @@ interactions:
- Accept-Encoding
x-content-type-options:
- nosniff
x-ms-providerhub-traffic:
- 'True'
status:
code: 200
message: OK
Expand All @@ -65,7 +66,7 @@ interactions:
accept-language:
- en-US
method: GET
uri: https://eastus2euap.quantum.azure.com/v1.0/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aqua-provider-validator/providers/Microsoft.Quantum/workspaces/validator-qio-parallel-tempering-cpu-eastus2euap/providerStatus
uri: https://eastus2euap.quantum.azure.com/v1.0/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/validator-test-rg/providers/Microsoft.Quantum/workspaces/testworkspace-canary-microsoft/providerStatus
response:
body:
string: '{"value":[{"id":"Microsoft","currentAvailability":"Available","targets":[{"id":"microsoft.paralleltempering-parameterfree.cpu","currentAvailability":"Available","averageQueueTime":0,"statusPage":null},{"id":"microsoft.paralleltempering.cpu","currentAvailability":"Available","averageQueueTime":0,"statusPage":null},{"id":"microsoft.simulatedannealing-parameterfree.cpu","currentAvailability":"Available","averageQueueTime":0,"statusPage":null},{"id":"microsoft.simulatedannealing.cpu","currentAvailability":"Available","averageQueueTime":0,"statusPage":null},{"id":"microsoft.tabu-parameterfree.cpu","currentAvailability":"Available","averageQueueTime":0,"statusPage":null},{"id":"microsoft.tabu.cpu","currentAvailability":"Available","averageQueueTime":0,"statusPage":null},{"id":"microsoft.simulatedannealing-parameterfree.fpga","currentAvailability":"Available","averageQueueTime":0,"statusPage":null},{"id":"microsoft.simulatedannealing.fpga","currentAvailability":"Available","averageQueueTime":0,"statusPage":null},{"id":"microsoft.chemistry.all","currentAvailability":"Available","averageQueueTime":0,"statusPage":null},{"id":"microsoft.qmc.cpu","currentAvailability":"Available","averageQueueTime":0,"statusPage":null}]}],"nextLink":null}'
Expand All @@ -75,7 +76,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Fri, 29 Jan 2021 17:44:52 GMT
- Mon, 22 Mar 2021 16:47:08 GMT
request-context:
- appId=cid-v1:4d6ac272-7369-45c6-9036-63d733c8519f
server:
Expand Down
231 changes: 22 additions & 209 deletions src/quantum/azext_quantum/tests/latest/recordings/test_workspace.yaml

Large diffs are not rendered by default.

28 changes: 15 additions & 13 deletions src/quantum/azext_quantum/tests/latest/test_quantum_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from azure_devtools.scenario_tests import AllowLargeResponse
from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer)

from .utils import TEST_WORKSPACE, TEST_RG, TEST_SUBS, TEST_WORKSPACE_CREATE_DELETE, TEST_WORKSPACE_LOCATION, TEST_WORKSPACE_SA
from .utils import TEST_WORKSPACE_RM, TEST_RG_RM, TEST_SUBS, TEST_WORKSPACE_CREATE_DELETE, TEST_WORKSPACE_LOCATION, TEST_WORKSPACE_SA

TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))

Expand All @@ -25,30 +25,32 @@ def test_workspace(self):
workspaces = self.cmd(f'az quantum workspace list -l {TEST_WORKSPACE_LOCATION} -o json').get_output_in_json()
assert len(workspaces) > 0
self.cmd('az quantum workspace list -o json', checks=[
self.check(f"[?name=='{TEST_WORKSPACE}'].resourceGroup | [0]", TEST_RG)
self.check(f"[?name=='{TEST_WORKSPACE_RM}'].resourceGroup | [0]", TEST_RG_RM)
])

# set
self.cmd(f'az quantum workspace set -g {TEST_RG} -w {TEST_WORKSPACE} -l {TEST_WORKSPACE_LOCATION} -o json', checks=[
self.check("name", TEST_WORKSPACE)
self.cmd(f'az quantum workspace set -g {TEST_RG_RM} -w {TEST_WORKSPACE_RM} -l {TEST_WORKSPACE_LOCATION} -o json', checks=[
self.check("name", TEST_WORKSPACE_RM)
])

# show
self.cmd(f'az quantum workspace show -o json', checks=[
self.check("name", TEST_WORKSPACE)
self.check("name", TEST_WORKSPACE_RM)
])

# clear
self.cmd(f'az quantum workspace clear')

# Currently disabled for required role assignment permissions on test subscription

# create
self.cmd(f'az quantum workspace create -g {TEST_RG} -w {TEST_WORKSPACE_CREATE_DELETE} -l {TEST_WORKSPACE_LOCATION} -a {TEST_WORKSPACE_SA} -o json --skip-role-assignment', checks=[
self.check("name", TEST_WORKSPACE_CREATE_DELETE),
self.check("provisioningState", "Accepted") # Status is accepted since we're not linking the storage account.
])
# self.cmd(f'az quantum workspace create -g {TEST_RG} -w {TEST_WORKSPACE_CREATE_DELETE} -l {TEST_WORKSPACE_LOCATION} -a {TEST_WORKSPACE_SA} -r "Microsoft/Basic" -o json --skip-role-assignment', checks=[
# self.check("name", TEST_WORKSPACE_CREATE_DELETE),
# self.check("provisioningState", "Accepted") # Status is accepted since we're not linking the storage account.
# ])

# delete
self.cmd(f'az quantum workspace delete -g {TEST_RG} -w {TEST_WORKSPACE_CREATE_DELETE} -o json', checks=[
self.check("name", TEST_WORKSPACE_CREATE_DELETE),
self.check("provisioningState", "Deleting")
])
# self.cmd(f'az quantum workspace delete -g {TEST_RG} -w {TEST_WORKSPACE_CREATE_DELETE} -o json', checks=[
# self.check("name", TEST_WORKSPACE_CREATE_DELETE),
# self.check("provisioningState", "Deleting")
# ])
6 changes: 4 additions & 2 deletions src/quantum/azext_quantum/tests/latest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
TEST_SUBS = "677fc922-91d0-4bf6-9b06-4274d319a0fa"
TEST_RG = 'aqua-provider-validator'
TEST_RG_JOBS = 'testalias-e2e-tests-canary-rg'
TEST_RG_TARGET = 'aqua-provider-validator'
TEST_RG_TARGET = 'validator-test-rg'
TEST_RG_RM = 'validator-test-rg'
TEST_WORKSPACE = 'validator-workspace-westus'
TEST_WORKSPACE_JOBS = 'e2e-tests-workspace-ionq'
TEST_WORKSPACE_TARGET = 'validator-qio-parallel-tempering-cpu-eastus2euap'
TEST_WORKSPACE_TARGET = 'testworkspace-canary-microsoft'
TEST_WORKSPACE_RM = 'testworkspace-canary-microsoft'
TEST_WORKSPACE_CREATE_DELETE = 'validator-workspace-crdl-westus'
TEST_WORKSPACE_SA = 'aqvalidatorstorage'
TEST_WORKSPACE_LOCATION = 'westus'
Expand Down

0 comments on commit 5790e3a

Please sign in to comment.