def __init__(self, workspace=None, **kwargs): self._backends = None if workspace is None: workspace = Workspace(**kwargs) workspace.append_user_agent(QISKIT_USER_AGENT) self._workspace = workspace
def __init__(self, workspace: Workspace = None, default_target: Optional[str] = None, **kwargs): """AzureQuantumService class :param workspace: Azure Quantum workspace. If missing it will create a new Workspace passing `kwargs` to the constructor. Defaults to None. :type workspace: Workspace, optional :param default_target: Default target name, defaults to None :type default_target: Optional[str], optional """ if workspace is None: workspace = Workspace(**kwargs) workspace.append_user_agent(CIRQ_USER_AGENT) self._workspace = workspace self._default_target = default_target
def create_workspace(self, **kwargs) -> Workspace: """Create workspace using credentials passed via OS Environment Variables described in the README.md documentation, or when in playback mode use a placeholder credential. :return: Workspace :rtype: Workspace """ playback_credential = ClientSecretCredential(self.tenant_id, self.client_id, self.client_secret) default_credential = playback_credential if self.is_playback \ else None workspace = Workspace(credential=default_credential, subscription_id=self.subscription_id, resource_group=self.resource_group, name=self.workspace_name, location=self.location, **kwargs) workspace.append_user_agent("testapp") return workspace
def test_workspace_user_agent_appid(self): env_var_app_id = "MyEnvVarAppId" user_agent = "MyUserAgentAppId" very_long_user_agent = "MyVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongUserAgentAppId" original_env_app_id = os.environ.get(USER_AGENT_APPID_ENV_VAR_NAME, "") try: # no UserAgent parameter and no EnvVar AppId os.environ[USER_AGENT_APPID_ENV_VAR_NAME] = "" ws = Workspace( subscription_id=self.subscription_id, resource_group=self.resource_group, name=self.workspace_name, location=self.location ) assert ws.user_agent is None # no UserAgent parameter and with EnvVar AppId os.environ[USER_AGENT_APPID_ENV_VAR_NAME] = env_var_app_id ws = Workspace( subscription_id=self.subscription_id, resource_group=self.resource_group, name=self.workspace_name, location=self.location ) assert ws.user_agent == env_var_app_id # with UserAgent parameter and no EnvVar AppId os.environ[USER_AGENT_APPID_ENV_VAR_NAME] = "" ws = Workspace( subscription_id=self.subscription_id, resource_group=self.resource_group, name=self.workspace_name, location=self.location, user_agent=user_agent ) assert ws.user_agent == user_agent # with very long UserAgent parameter and no EnvVar AppId os.environ[USER_AGENT_APPID_ENV_VAR_NAME] = "" ws = Workspace( subscription_id=self.subscription_id, resource_group=self.resource_group, name=self.workspace_name, location=self.location, user_agent=very_long_user_agent ) assert ws.user_agent == very_long_user_agent # with UserAgent parameter and with EnvVar AppId os.environ[USER_AGENT_APPID_ENV_VAR_NAME] = env_var_app_id ws = Workspace( subscription_id=self.subscription_id, resource_group=self.resource_group, name=self.workspace_name, location=self.location, user_agent=user_agent ) assert ws.user_agent == f"{user_agent}-{env_var_app_id}" # Append with UserAgent parameter and with EnvVar AppId os.environ[USER_AGENT_APPID_ENV_VAR_NAME] = env_var_app_id ws = Workspace( subscription_id=self.subscription_id, resource_group=self.resource_group, name=self.workspace_name, location=self.location, user_agent=user_agent ) ws.append_user_agent("featurex") assert ws.user_agent == f"{user_agent}-featurex-{env_var_app_id}" # Append with no UserAgent parameter and no EnvVar AppId os.environ[USER_AGENT_APPID_ENV_VAR_NAME] = "" ws = Workspace( subscription_id=self.subscription_id, resource_group=self.resource_group, name=self.workspace_name, location=self.location ) ws.append_user_agent("featurex") assert ws.user_agent == "featurex" finally: if original_env_app_id: os.environ[USER_AGENT_APPID_ENV_VAR_NAME] = original_env_app_id else: os.environ.pop(USER_AGENT_APPID_ENV_VAR_NAME)