Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
If you have an Azure Quantum workspace, you can connect to your workspace and submit your code with the qdk.azure Python module. The qdk.azure module provides a Workspace class that represents an Azure Quantum workspace.
Prerequisites
To connect to your workspace with the qdk.azure module, you need the following:
An Azure account with an active subscription. If you don’t have an Azure account, register for free and sign up for a pay-as-you-go subscription.
An Azure Quantum workspace. If you don't have a workspace, see Create an Azure Quantum workspace.
The latest version of the
qdkpython package with theazureextra.pip install --upgrade "qdk[azure]"If you use Azure CLI, update to the latest version. For installation instructions, see:
Connect with a connection string
Use a connection string to specify the connection parameters to an Azure Quantum workspace. Connection strings are useful in the following scenarios:
- You want to share access to your workspace with others who don't have an Azure account.
- You want to share access to your workspace with others for a limited time.
- You can't use Microsoft Entra ID because of company policies.
Tip
Every Azure Quantum workspace has a primary key and a secondary key, and each key has its own connection string. To allow others to access your workspace, share the secondary key and use the primary key only for your own services. You can replace the secondary key without causing downtime in your own services. For more information about sharing access to your workspace, see Share your workspace access.
Copy the connection string
- Sign in to the Azure portal.
- Go to your Azure Quantum workspace.
- In the workspace panel, expand the Operations dropdown and select Access Keys.
- Enable access keys for your workspace. If the Access Keys slider is set to Disabled, set the slider to Enabled.
- Select the Copy icon for the connection string that you want to copy. You can choose either the primary or secondary connection string.
Warning
It's a security risk to store your account access keys or connection strings in clear text. Store your account keys in an encrypted format, or migrate your applications to use Microsoft Entra authorization for access to your Azure Quantum workspace.
Use the connection string to access your Azure Quantum workspace
Use the connection string you copied to connect to your Azure Quantum workspace with the qdk.azure module or the QDK extension in Visual Studio Code.
To connect to your Azure Quantum workspace, choose one of the following methods.
Use the
from_connection_stringfunction to create aWorkspaceobject.from qdk.azure import Workspace connection_string = "" # Add your connection string workspace = Workspace.from_connection_string(connection_string) print(workspace.get_targets())Store your connection string in an environment variable.
import os from qdk.azure import Workspace connection_string = "" # Add your connection string os.environ["AZURE_QUANTUM_CONNECTION_STRING"] = connection_string workspace = Workspace() print(workspace.get_targets())
For more information about how to work with keys, see Manage your Access Keys.
Important
If you disable access keys for your workspace, you can't use connection strings to connect to your workspace. Use workspace parameters to connect instead.
Connect to your workspace with workspace parameters
Every Azure Quantum workspace has a unique set of parameters that you can use to connect to the workspace.
| Parameter | Description | Use when you connect with |
|---|---|---|
subscription_id |
The Azure subscription ID. | Azure CLI |
resource_group |
The Azure resource group name. | Azure CLI |
name |
The name of your Azure Quantum workspace. | Azure CLI |
resource_id |
The Azure resource ID of the Azure Quantum workspace. | Python |
To find your workspace parameters, follow these steps:
- Sign in to the Azure portal.
- Go to your Azure Quantum workspace.
- From your workspace panel, choose Overview.
- Expand the Essentials dropdown.
- Copy the parameters in their corresponding fields.
Note
Ensure that you sign in to the correct tenant before you connect to your workspace. For more information about tenants, see How to manage Azure subscriptions with the Azure CLI.
Use workspace parameters to connect to your Azure Quantum workspace
To stay signed in when you run your Python scripts, open a terminal and run the following Azure CLI command. This command sets the subscription for your workspace. Replace <subscriptionId> with your subscription ID.
az account set --subscription <subscriptionId>
You can use your workspace parameters to connect to your Azure Quantum workspace through the qdk.azure module or through Azure CLI.
To connect to your Azure Quantum workspace, choose one of the following options.
Specify the resource ID (recommended):
from qdk.azure import Workspace workspace = Workspace(resource_id="") # Add the resource ID of your workspaceSpecify the subscription ID, resource group, and workspace name:
from qdk.azure import Workspace workspace = Workspace( subscription_id="", # Add the subscription ID of your workspace resource_group="", # Add the resource group of your workspace name="" # Add the name of your workspace )Specify only the workspace name. This option might fail when you have multiple workspaces that have the same name in the same tenant.
from qdk.azure import Workspace workspace = Workspace(name="") # Add the name of your workspace