Source code for qiskit_aqt_provider._cloud.workspace_provider
# This code is part of Qiskit.
#
# (C) Copyright Alpine Quantum Technologies GmbH 2023
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0).
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
import httpx
from aqt_connector import ArnicaApp
from aqt_connector.models.arnica.response_bodies.resources import ResourceDetails, WorkspaceResource
from aqt_connector.models.arnica.response_bodies.workspaces import Workspace as APIWorkspace
from qiskit.providers.exceptions import QiskitBackendNotFoundError
from qiskit_aqt_provider._cloud.resource import CloudResource
from qiskit_aqt_provider.api_client.errors import http_response_raise_for_status
[docs]
class WorkspaceProvider:
"""A provider for a workspace in the AQT cloud."""
def __init__(self, data: APIWorkspace, arnica: ArnicaApp, api_client: httpx.Client) -> None:
"""Initializes a workspace provider from the given API workspace data."""
self._id = data.id
self._resources = data.resources
self._arnica = arnica
self._api_client = api_client
@property
def id(self) -> str:
"""The workspace's identifier."""
return self._id
[docs]
def list_backends(self) -> list[WorkspaceResource]:
"""Lists the backends available in this workspace.
Returns:
list[WorkspaceResource]: The list of backends available in this workspace.
"""
return self._resources
[docs]
def get_backend(self, backend_id: str) -> CloudResource:
"""Gets a specific backend available in this workspace by its identifier.
Args:
backend_id (str): The identifier of the backend to retrieve.
Returns:
CloudResource: The backend with the specified identifier.
Raises:
QiskitBackendNotFoundError: If no backend with the specified identifier is found.
"""
for resource in self._resources:
if resource.id == backend_id:
response = http_response_raise_for_status(self._api_client.get(f"/v1/resources/{resource.id}"))
details = ResourceDetails.model_validate_json(response.text)
return CloudResource(self._arnica, self._api_client, self._id, details)
raise QiskitBackendNotFoundError(f"Backend with ID '{backend_id}' not found in workspace '{self._id}'.")