Skip to content

Commit

Permalink
Virtual queue support quera internal api (#636)
Browse files Browse the repository at this point in the history
* adding virtual queue header.

* fixing unit tests.

* adding modification of base header.
  • Loading branch information
weinbe58 authored Sep 26, 2023
1 parent eec79d8 commit 96f1b08
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 72 deletions.
10 changes: 8 additions & 2 deletions src/bloqade/submission/quera.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pydantic import PrivateAttr
from bloqade.submission.base import SubmissionBackend, ValidationError
from bloqade.submission.quera_api_client.api import QueueApi
from bloqade.submission.ir.task_specification import (
Expand All @@ -15,6 +16,7 @@ class QuEraBackend(SubmissionBackend):
api_hostname: str
qpu_id: str
api_stage: str = "v0"
virtual_queue: Optional[str] = None
proxy: Optional[str] = None
# Sigv4Request arguments
region: Optional[str] = None
Expand All @@ -25,11 +27,15 @@ class QuEraBackend(SubmissionBackend):
role_arn: Optional[str] = None
role_session_name: Optional[str] = None
profile: Optional[str] = None
_queue_api: Optional[QueueApi] = PrivateAttr(None)

@property
def queue_api(self):
kwargs = {k: v for k, v in self.__dict__.items() if v is not None}
return QueueApi(**kwargs)
if self._queue_api is None:
kwargs = {k: v for k, v in self.__dict__.items() if v is not None}
self._queue_api = QueueApi(**kwargs)

return self._queue_api

def get_capabilities(self) -> QuEraCapabilities:
try:
Expand Down
37 changes: 26 additions & 11 deletions src/bloqade/submission/quera_api_client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ def __init__(
api_hostname: str,
qpu_id: str,
api_stage="v0",
virtual_queue: Optional[str] = None,
proxy: Optional[str] = None,
):
"""
Create an instance of `ApiRequest`.
@param api_hostname: hostname of the API instance.
@param qpu_id: The QPU ID, for example `qpu1-mock`.
@param api_stage: Specify which version of the API to call from this object.
@param virtual_queue: Optional, the virtual queue to use for the API.
@param proxy: Optional, the hostname for running the API via some proxy
endpoint.
"""
Expand All @@ -43,6 +45,7 @@ def __init__(

self.base_url = "https://" + uri_with_version
self.qpu_id = qpu_id
self.virtual_queue = virtual_queue
self.logger = logging.getLogger(self.__class__.__name__)

@staticmethod
Expand All @@ -60,17 +63,18 @@ def _result_as_json(result: requests.Response) -> Dict:

def _generate_headers(self, base: Optional[dict] = None) -> Dict:
if base is None:
if self.hostname is None:
return {"Content-Type": "application/json"}
else:
return {"Content-Type": "application/json", "Host": self.hostname}
header = {"Content-Type": "application/json"}
else:
if self.hostname is None:
return base
else:
header = dict(base)
header["Host"] = self.hostname
return header # type: ignore
header = dict(base)
header["Content-Type"] = "application/json"

if self.hostname is not None:
header["Host"] = self.hostname

if self.virtual_queue is not None:
header["virtual_queue"] = self.virtual_queue

return header

def _get_path(self, *path_list: str):
return "/".join((self.base_url, self.qpu_id) + path_list)
Expand Down Expand Up @@ -124,6 +128,7 @@ def __init__(
api_hostname: str,
qpu_id: str,
api_stage="v0",
virtual_queue: Optional[str] = None,
proxy: Optional[str] = None,
# Sigv4Request arguments
region: str = "us-east-1",
Expand All @@ -140,6 +145,7 @@ def __init__(
@param api_hostname: hostname of the API instance.
@param qpu_id: The QPU ID, for example `qpu1-mock`.
@param api_stage: Specify which version of the API to call from this object.
@param virtual_queue: Optional, the virtual queue to use for the API.
@param proxy: Optional, the hostname for running the API via some proxy
endpoint.
@param region: AWS region, default value: "us-east-1"
Expand All @@ -152,7 +158,13 @@ def __init__(
@param role_session_name: AWS role session name, defualy value: 'awsrequest',
@param profile: Optional, AWS profile to use credentials for.
"""
super().__init__(api_hostname, qpu_id, api_stage=api_stage, proxy=proxy)
super().__init__(
api_hostname,
qpu_id,
virtual_queue=virtual_queue,
api_stage=api_stage,
proxy=proxy,
)

self.request = Sigv4Request(
region=region,
Expand Down Expand Up @@ -262,6 +274,7 @@ def __init__(
api_hostname: str,
qpu_id: str,
api_stage="v0",
virtual_queue: Optional[str] = None,
proxy: Optional[str] = None,
**request_sigv4_kwargs,
):
Expand All @@ -270,6 +283,7 @@ def __init__(
@param api_hostname: hostname of the API instance.
@param qpu_id: The QPU ID, for example `qpu1-mock`.
@param api_stage: Specify which version of the API to call from this object.
@param virtual_queue: Optional, the virtual queue to use for the API.
@param proxy: Optional, the hostname for running the API via some proxy
endpoint.
Expand All @@ -289,6 +303,7 @@ def __init__(
api_hostname,
qpu_id,
api_stage=api_stage,
virtual_queue=virtual_queue,
proxy=proxy,
**request_sigv4_kwargs,
)
Expand Down
Loading

0 comments on commit 96f1b08

Please sign in to comment.