Skip to content

Commit 2f8725b

Browse files
author
SDKAuto
committed
CodeGen from PR 34482 in Azure/azure-rest-api-specs
Merge 45bc57995d2c200fab406df9a3ff0ee8e6e1b9f3 into e2006c1b75927db9d566a4d38bd256103b5b5c12
1 parent 066b303 commit 2f8725b

35 files changed

+9208
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Release History
2+
3+
## 1.0.0b1 (1970-01-01)
4+
5+
- Initial version

sdk/quantum/azure-quantum/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright (c) Microsoft Corporation.
2+
3+
MIT License
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
include *.md
2+
include LICENSE
3+
include azure/quantum/py.typed
4+
recursive-include tests *.py
5+
recursive-include samples *.py *.md
6+
include azure/__init__.py
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Azure Quantum client library for Python
2+
<!-- write necessary description of service -->
3+
4+
## Getting started
5+
6+
### Install the package
7+
8+
```bash
9+
python -m pip install azure-quantum
10+
```
11+
12+
#### Prequisites
13+
14+
- Python 3.9 or later is required to use this package.
15+
- You need an [Azure subscription][azure_sub] to use this package.
16+
- An existing Azure Quantum instance.
17+
18+
19+
## Contributing
20+
21+
This project welcomes contributions and suggestions. Most contributions require
22+
you to agree to a Contributor License Agreement (CLA) declaring that you have
23+
the right to, and actually do, grant us the rights to use your contribution.
24+
For details, visit https://cla.microsoft.com.
25+
26+
When you submit a pull request, a CLA-bot will automatically determine whether
27+
you need to provide a CLA and decorate the PR appropriately (e.g., label,
28+
comment). Simply follow the instructions provided by the bot. You will only
29+
need to do this once across all repos using our CLA.
30+
31+
This project has adopted the
32+
[Microsoft Open Source Code of Conduct][code_of_conduct]. For more information,
33+
see the Code of Conduct FAQ or contact [email protected] with any
34+
additional questions or comments.
35+
36+
<!-- LINKS -->
37+
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
38+
[authenticate_with_token]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token
39+
[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#credentials
40+
[azure_identity_pip]: https://pypi.org/project/azure-identity/
41+
[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential
42+
[pip]: https://pypi.org/project/pip/
43+
[azure_sub]: https://azure.microsoft.com/free/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"commit": "0660a73ea14775552af66f95d92e1a0446a04b54",
3+
"repository_url": "https://github.com/Azure/azure-rest-api-specs",
4+
"typespec_src": "specification/quantum/Quantum.Workspace",
5+
"@azure-tools/typespec-python": "0.44.1"
6+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"CrossLanguagePackageId": "Quantum.Workspace",
3+
"CrossLanguageDefinitionId": {
4+
"azure.quantum.models.BlobDetails": "Quantum.Workspace.BlobDetails",
5+
"azure.quantum.models.CostEstimate": "Quantum.Workspace.CostEstimate",
6+
"azure.quantum.models.InnerError": "Azure.Core.Foundations.InnerError",
7+
"azure.quantum.models.ItemDetails": "Quantum.Workspace.ItemDetails",
8+
"azure.quantum.models.JobDetails": "Quantum.Workspace.JobDetails",
9+
"azure.quantum.models.JsonPatchObject": "Quantum.Workspace.JsonPatchObject",
10+
"azure.quantum.models.ProviderStatus": "Quantum.Workspace.ProviderStatus",
11+
"azure.quantum.models.QuantumComputingData": "Quantum.Workspace.QuantumComputingData",
12+
"azure.quantum.models.Quota": "Quantum.Workspace.Quota",
13+
"azure.quantum.models.SasUriResponse": "Quantum.Workspace.SasUriResponse",
14+
"azure.quantum.models.SessionDetails": "Quantum.Workspace.SessionDetails",
15+
"azure.quantum.models.TargetStatus": "Quantum.Workspace.TargetStatus",
16+
"azure.quantum.models.UsageEvent": "Quantum.Workspace.UsageEvent",
17+
"azure.quantum.models.WorkspaceItemError": "Errors.WorkspaceItemError",
18+
"azure.quantum.models.ItemType": "Quantum.Workspace.ItemType",
19+
"azure.quantum.models.JobType": "Quantum.Workspace.JobType",
20+
"azure.quantum.models.JobStatus": "Quantum.Workspace.JobStatus",
21+
"azure.quantum.models.SessionJobFailurePolicy": "Quantum.Workspace.SessionJobFailurePolicy",
22+
"azure.quantum.models.SessionStatus": "Quantum.Workspace.SessionStatus",
23+
"azure.quantum.models.JsonPatchOperation": "Quantum.Workspace.JsonPatchOperation",
24+
"azure.quantum.models.ProviderAvailability": "Quantum.Workspace.ProviderAvailability",
25+
"azure.quantum.models.TargetAvailability": "Quantum.Workspace.TargetAvailability",
26+
"azure.quantum.models.DimensionScope": "Quantum.Workspace.DimensionScope",
27+
"azure.quantum.models.MeterPeriod": "Quantum.Workspace.MeterPeriod"
28+
}
29+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) Python Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
# pylint: disable=wrong-import-position
9+
10+
from typing import TYPE_CHECKING
11+
12+
if TYPE_CHECKING:
13+
from ._patch import * # pylint: disable=unused-wildcard-import
14+
15+
from ._client import WorkspaceClient # type: ignore
16+
from ._version import VERSION
17+
18+
__version__ = VERSION
19+
20+
try:
21+
from ._patch import __all__ as _patch_all
22+
from ._patch import *
23+
except ImportError:
24+
_patch_all = []
25+
from ._patch import patch_sdk as _patch_sdk
26+
27+
__all__ = [
28+
"WorkspaceClient",
29+
]
30+
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore
31+
32+
_patch_sdk()
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) Python Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from copy import deepcopy
10+
from typing import Any, TYPE_CHECKING, Union
11+
from typing_extensions import Self
12+
13+
from azure.core import PipelineClient
14+
from azure.core.credentials import AzureKeyCredential
15+
from azure.core.pipeline import policies
16+
from azure.core.rest import HttpRequest, HttpResponse
17+
18+
from ._configuration import WorkspaceClientConfiguration
19+
from ._utils.serialization import Deserializer, Serializer
20+
from .operations import ServicesOperations
21+
22+
if TYPE_CHECKING:
23+
from azure.core.credentials import TokenCredential
24+
25+
26+
class WorkspaceClient:
27+
"""Azure Quantum Workspace Services.
28+
29+
:ivar services: ServicesOperations operations
30+
:vartype services: azure.quantum.operations.ServicesOperations
31+
:param region: The Azure region where the Azure Quantum Workspace is located. Required.
32+
:type region: str
33+
:param credential: Credential used to authenticate requests to the service. Is either a token
34+
credential type or a key credential type. Required.
35+
:type credential: ~azure.core.credentials.TokenCredential or
36+
~azure.core.credentials.AzureKeyCredential
37+
:keyword service_base_url: The Azure Quantum service base url. Default value is
38+
"quantum.azure.com".
39+
:paramtype service_base_url: str
40+
:keyword api_version: The API version to use for this operation. Default value is
41+
"2024-10-01-preview". Note that overriding this default value may result in unsupported
42+
behavior.
43+
:paramtype api_version: str
44+
"""
45+
46+
def __init__(
47+
self,
48+
region: str,
49+
credential: Union["TokenCredential", AzureKeyCredential],
50+
*,
51+
service_base_url: str = "quantum.azure.com",
52+
**kwargs: Any
53+
) -> None:
54+
_endpoint = "https://{region}.{serviceBaseUrl}"
55+
self._config = WorkspaceClientConfiguration(
56+
region=region, credential=credential, service_base_url=service_base_url, **kwargs
57+
)
58+
59+
_policies = kwargs.pop("policies", None)
60+
if _policies is None:
61+
_policies = [
62+
policies.RequestIdPolicy(**kwargs),
63+
self._config.headers_policy,
64+
self._config.user_agent_policy,
65+
self._config.proxy_policy,
66+
policies.ContentDecodePolicy(**kwargs),
67+
self._config.redirect_policy,
68+
self._config.retry_policy,
69+
self._config.authentication_policy,
70+
self._config.custom_hook_policy,
71+
self._config.logging_policy,
72+
policies.DistributedTracingPolicy(**kwargs),
73+
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
74+
self._config.http_logging_policy,
75+
]
76+
self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs)
77+
78+
self._serialize = Serializer()
79+
self._deserialize = Deserializer()
80+
self._serialize.client_side_validation = False
81+
self.services = ServicesOperations(self._client, self._config, self._serialize, self._deserialize)
82+
83+
def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
84+
"""Runs the network request through the client's chained policies.
85+
86+
>>> from azure.core.rest import HttpRequest
87+
>>> request = HttpRequest("GET", "https://www.example.org/")
88+
<HttpRequest [GET], url: 'https://www.example.org/'>
89+
>>> response = client.send_request(request)
90+
<HttpResponse: 200 OK>
91+
92+
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request
93+
94+
:param request: The network request you want to make. Required.
95+
:type request: ~azure.core.rest.HttpRequest
96+
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
97+
:return: The response of your network call. Does not do error handling on your response.
98+
:rtype: ~azure.core.rest.HttpResponse
99+
"""
100+
101+
request_copy = deepcopy(request)
102+
path_format_arguments = {
103+
"region": self._serialize.url("self._config.region", self._config.region, "str"),
104+
"serviceBaseUrl": self._serialize.url(
105+
"self._config.service_base_url", self._config.service_base_url, "str"
106+
),
107+
}
108+
109+
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
110+
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore
111+
112+
def close(self) -> None:
113+
self._client.close()
114+
115+
def __enter__(self) -> Self:
116+
self._client.__enter__()
117+
return self
118+
119+
def __exit__(self, *exc_details: Any) -> None:
120+
self._client.__exit__(*exc_details)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) Python Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from typing import Any, TYPE_CHECKING, Union
10+
11+
from azure.core.credentials import AzureKeyCredential
12+
from azure.core.pipeline import policies
13+
14+
from ._version import VERSION
15+
16+
if TYPE_CHECKING:
17+
from azure.core.credentials import TokenCredential
18+
19+
20+
class WorkspaceClientConfiguration: # pylint: disable=too-many-instance-attributes
21+
"""Configuration for WorkspaceClient.
22+
23+
Note that all parameters used to create this instance are saved as instance
24+
attributes.
25+
26+
:param region: The Azure region where the Azure Quantum Workspace is located. Required.
27+
:type region: str
28+
:param credential: Credential used to authenticate requests to the service. Is either a token
29+
credential type or a key credential type. Required.
30+
:type credential: ~azure.core.credentials.TokenCredential or
31+
~azure.core.credentials.AzureKeyCredential
32+
:param service_base_url: The Azure Quantum service base url. Default value is
33+
"quantum.azure.com".
34+
:type service_base_url: str
35+
:keyword api_version: The API version to use for this operation. Default value is
36+
"2024-10-01-preview". Note that overriding this default value may result in unsupported
37+
behavior.
38+
:paramtype api_version: str
39+
"""
40+
41+
def __init__(
42+
self,
43+
region: str,
44+
credential: Union["TokenCredential", AzureKeyCredential],
45+
service_base_url: str = "quantum.azure.com",
46+
**kwargs: Any,
47+
) -> None:
48+
api_version: str = kwargs.pop("api_version", "2024-10-01-preview")
49+
50+
if region is None:
51+
raise ValueError("Parameter 'region' must not be None.")
52+
if credential is None:
53+
raise ValueError("Parameter 'credential' must not be None.")
54+
55+
self.region = region
56+
self.credential = credential
57+
self.service_base_url = service_base_url
58+
self.api_version = api_version
59+
self.credential_scopes = kwargs.pop("credential_scopes", ["https://quantum.microsoft.com/.default"])
60+
kwargs.setdefault("sdk_moniker", "quantum/{}".format(VERSION))
61+
self.polling_interval = kwargs.get("polling_interval", 30)
62+
self._configure(**kwargs)
63+
64+
def _infer_policy(self, **kwargs):
65+
if hasattr(self.credential, "get_token"):
66+
return policies.BearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs)
67+
if isinstance(self.credential, AzureKeyCredential):
68+
return policies.AzureKeyCredentialPolicy(self.credential, "x-ms-quantum-api-key", **kwargs)
69+
raise TypeError(f"Unsupported credential: {self.credential}")
70+
71+
def _configure(self, **kwargs: Any) -> None:
72+
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
73+
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
74+
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
75+
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
76+
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
77+
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
78+
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
79+
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
80+
self.authentication_policy = kwargs.get("authentication_policy")
81+
if self.credential and not self.authentication_policy:
82+
self.authentication_policy = self._infer_policy(**kwargs)

0 commit comments

Comments
 (0)