1717from azure .identity import DefaultAzureCredential
1818from azure .quantum ._constants import (
1919 EnvironmentKind ,
20+ WorkspaceKind ,
2021 EnvironmentVariables ,
2122 ConnectionConstants ,
2223 GUID_REGEX_PATTERN ,
@@ -48,7 +49,7 @@ class WorkspaceConnectionParams:
4849 ResourceGroupName=(?P<resource_group>[^\s;]+);
4950 WorkspaceName=(?P<workspace_name>[^\s;]+);
5051 ApiKey=(?P<api_key>[^\s;]+);
51- QuantumEndpoint=(?P<quantum_endpoint>https://(?P<location>[a-zA-Z0-9]+)(?:-v2 )?.quantum(?:-test)?.azure.com/);
52+ QuantumEndpoint=(?P<quantum_endpoint>https://(?P<location>[a-zA-Z0-9]+)(?:-(?P<workspace_kind>v2) )?.quantum(?:-test)?.azure.com/);
5253 """ ,
5354 re .VERBOSE | re .IGNORECASE )
5455
@@ -80,13 +81,15 @@ def __init__(
8081 api_version : Optional [str ] = None ,
8182 connection_string : Optional [str ] = None ,
8283 on_new_client_request : Optional [Callable ] = None ,
84+ workspace_kind : Optional [str ] = None ,
8385 ):
8486 # fields are used for these properties since
8587 # they have special getters/setters
8688 self ._location = None
8789 self ._environment = None
8890 self ._quantum_endpoint = None
8991 self ._arm_endpoint = None
92+ self ._workspace_kind = None
9093 # regular connection properties
9194 self .subscription_id = None
9295 self .resource_group = None
@@ -120,6 +123,7 @@ def __init__(
120123 user_agent = user_agent ,
121124 user_agent_app_id = user_agent_app_id ,
122125 workspace_name = workspace_name ,
126+ workspace_kind = workspace_kind ,
123127 )
124128 self .apply_resource_id (resource_id = resource_id )
125129 # Validate connection parameters if they are set
@@ -272,6 +276,19 @@ def api_key(self, value: str):
272276 self .credential = AzureKeyCredential (value )
273277 self ._api_key = value
274278
279+ @property
280+ def workspace_kind (self ) -> WorkspaceKind :
281+ """
282+ The workspace kind, such as V1 or V2.
283+ Defaults to WorkspaceKind.V1
284+ """
285+ return self ._workspace_kind or WorkspaceKind .V1
286+
287+ @workspace_kind .setter
288+ def workspace_kind (self , value : str ):
289+ if isinstance (value , str ):
290+ self ._workspace_kind = WorkspaceKind [value .upper ()]
291+
275292 def __repr__ (self ):
276293 """
277294 Print all fields and properties.
@@ -331,6 +348,7 @@ def merge(
331348 client_id : Optional [str ] = None ,
332349 api_version : Optional [str ] = None ,
333350 api_key : Optional [str ] = None ,
351+ workspace_kind : Optional [str ] = None ,
334352 ):
335353 """
336354 Set all fields/properties with `not None` values
@@ -352,6 +370,7 @@ def merge(
352370 user_agent_app_id = user_agent_app_id ,
353371 workspace_name = workspace_name ,
354372 api_key = api_key ,
373+ workspace_kind = workspace_kind ,
355374 merge_default_mode = False ,
356375 )
357376 return self
@@ -372,6 +391,7 @@ def apply_defaults(
372391 client_id : Optional [str ] = None ,
373392 api_version : Optional [str ] = None ,
374393 api_key : Optional [str ] = None ,
394+ workspace_kind : Optional [str ] = None ,
375395 ) -> WorkspaceConnectionParams :
376396 """
377397 Set all fields/properties with `not None` values
@@ -394,6 +414,7 @@ def apply_defaults(
394414 user_agent_app_id = user_agent_app_id ,
395415 workspace_name = workspace_name ,
396416 api_key = api_key ,
417+ workspace_kind = workspace_kind ,
397418 merge_default_mode = True ,
398419 )
399420 return self
@@ -415,6 +436,7 @@ def _merge(
415436 client_id : Optional [str ] = None ,
416437 api_version : Optional [str ] = None ,
417438 api_key : Optional [str ] = None ,
439+ workspace_kind : Optional [str ] = None ,
418440 ):
419441 """
420442 Set all fields/properties with `not None` values
@@ -447,6 +469,7 @@ def _get_value_or_default(old_value, new_value):
447469 # the private field as the old_value
448470 self .quantum_endpoint = _get_value_or_default (self ._quantum_endpoint , quantum_endpoint )
449471 self .arm_endpoint = _get_value_or_default (self ._arm_endpoint , arm_endpoint )
472+ self .workspace_kind = _get_value_or_default (self ._workspace_kind , workspace_kind )
450473 return self
451474
452475 def _merge_connection_params (
@@ -476,6 +499,7 @@ def _merge_connection_params(
476499 # pylint: disable=protected-access
477500 arm_endpoint = connection_params ._arm_endpoint ,
478501 quantum_endpoint = connection_params ._quantum_endpoint ,
502+ workspace_kind = connection_params ._workspace_kind ,
479503 )
480504 return self
481505
@@ -640,4 +664,5 @@ def get_value(group_name):
640664 quantum_endpoint = get_value ('quantum_endpoint' ),
641665 api_key = get_value ('api_key' ),
642666 arm_endpoint = get_value ('arm_endpoint' ),
667+ workspace_kind = get_value ('workspace_kind' ),
643668 )
0 commit comments