Skip to content

Commit

Permalink
Merge pull request #7 from Alqor-UG/2-update-the-requirements-to-the-…
Browse files Browse the repository at this point in the history
…new-sqooler-release

Update sqooler
  • Loading branch information
fretchen authored Jan 26, 2024
2 parents 55eb5b1 + b2538d1 commit 915047d
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 83 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# django-qlued
A django package the couples together quantum hardware and endusers
A django package the couples together quantum hardware and endusers.
65 changes: 47 additions & 18 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ python-decouple = "^3.8"
pytz = "^2023.3.post1"
django-csp = "^3.7"
whitenoise = "^6.6.0"
sqooler = "^0.3.0"
sqooler = "^0.4.0"


[tool.poetry.group.dev.dependencies]
Expand Down
63 changes: 29 additions & 34 deletions src/qlued/api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@

from dropbox.exceptions import ApiError, AuthError

from sqooler.schemes import BackendConfigSchemaOut, BackendStatusSchemaOut
from sqooler.schemes import (
BackendConfigSchemaOut,
BackendStatusSchemaOut,
StatusMsgDict,
)

from .schemas import (
JobSchemaWithTokenIn,
JobResponseSchema,
)

from .models import Token, StorageProviderDb
Expand All @@ -29,7 +32,7 @@

@api.get(
"{backend_name}/get_config",
response={200: BackendConfigSchemaOut, codes_4xx: JobResponseSchema},
response={200: BackendConfigSchemaOut, codes_4xx: StatusMsgDict},
tags=["Backend"],
url_name="get_config",
)
Expand Down Expand Up @@ -80,7 +83,7 @@ def get_config(request, backend_name: str):

@api.get(
"{backend_name}/get_backend_status",
response={200: BackendStatusSchemaOut, codes_4xx: JobResponseSchema},
response={200: BackendStatusSchemaOut, codes_4xx: StatusMsgDict},
tags=["Backend"],
url_name="get_backend_status",
)
Expand Down Expand Up @@ -129,7 +132,7 @@ def get_backend_status(request, backend_name: str):

@api.post(
"{backend_name}/post_job",
response={200: JobResponseSchema, codes_4xx: JobResponseSchema},
response={200: StatusMsgDict, codes_4xx: StatusMsgDict},
tags=["Backend"],
url_name="post_job",
)
Expand Down Expand Up @@ -203,7 +206,7 @@ def post_job(request, data: JobSchemaWithTokenIn, backend_name: str):

@api.get(
"{backend_name}/get_job_status",
response={200: JobResponseSchema, codes_4xx: JobResponseSchema},
response={200: StatusMsgDict, codes_4xx: StatusMsgDict},
tags=["Backend"],
url_name="get_job_status",
)
Expand Down Expand Up @@ -271,7 +274,7 @@ def get_job_status(request, backend_name: str, job_id: str, token: str):

@api.get(
"{backend_name}/get_job_result",
response={200: dict, codes_4xx: JobResponseSchema},
response={200: dict, codes_4xx: StatusMsgDict},
tags=["Backend"],
url_name="get_job_result",
)
Expand All @@ -280,7 +283,7 @@ def get_job_result(request, backend_name: str, job_id: str, token: str):
A view to obtain the results of job that was previously submitted to the backend.
"""
# pylint: disable=W0613, R0914, R0911
status_msg_dict = {
status_msg_draft = {
"job_id": "None",
"status": "None",
"detail": "None",
Expand All @@ -290,47 +293,39 @@ def get_job_result(request, backend_name: str, job_id: str, token: str):
try:
token_object = Token.objects.get(key=token)
except Token.DoesNotExist:
status_msg_dict["status"] = "ERROR"
status_msg_dict["error_message"] = "Invalid credentials!"
status_msg_dict["detail"] = "Invalid credentials!"
return 401, status_msg_dict
status_msg_draft["status"] = "ERROR"
status_msg_draft["error_message"] = "Invalid credentials!"
status_msg_draft["detail"] = "Invalid credentials!"
return 401, status_msg_draft

username = token_object.user.username
short_backend = get_short_backend_name(backend_name)
storage_provider = get_storage_provider(backend_name)
backend_names = storage_provider.get_backends()
if short_backend not in backend_names:
status_msg_dict["status"] = "ERROR"
status_msg_dict["detail"] = "Unknown back-end!"
status_msg_dict["error_message"] = "Unknown back-end!"
return 404, status_msg_dict
status_msg_draft["status"] = "ERROR"
status_msg_draft["detail"] = "Unknown back-end!"
status_msg_draft["error_message"] = "Unknown back-end!"
return 404, status_msg_draft

# We should really handle these exceptions cleaner, but this seems a bit
# complicated right now
status_msg_draft["job_id"] = job_id
# pylint: disable=W0702
# decode the job-id to request the data from the queue
try:
status_msg_dict["job_id"] = job_id
except:
status_msg_dict["detail"] = "Error loading json data from input request!"
status_msg_dict["error_message"] = "Error loading json data from input request!"
return 406, status_msg_dict

# request the data from the queue
try:
status_msg_dict = storage_provider.get_status(
display_name=short_backend, username=username, job_id=job_id
)
if status_msg_dict["status"] != "DONE":
return 200, status_msg_dict
status_msg_draft = status_msg_dict.model_dump()
if status_msg_draft["status"] != "DONE":
return 200, status_msg_draft
except:
status_msg_dict[
status_msg_draft[
"detail"
] = "Error getting status from database. Maybe invalid JOB ID!"
status_msg_dict[
status_msg_draft[
"error_message"
] = "Error getting status from database. Maybe invalid JOB ID!"
return 406, status_msg_dict
return 406, status_msg_draft
# and if the status is switched to done, we can also obtain the result
try:
result_dict = storage_provider.get_result(
Expand All @@ -339,9 +334,9 @@ def get_job_result(request, backend_name: str, job_id: str, token: str):

return 200, result_dict
except:
status_msg_dict["detail"] = "Error getting result from database!"
status_msg_dict["error_message"] = "Error getting result from database!"
return 406, status_msg_dict
status_msg_draft["detail"] = "Error getting result from database!"
status_msg_draft["error_message"] = "Error getting result from database!"
return 406, status_msg_draft


@api.get(
Expand Down
29 changes: 0 additions & 29 deletions src/qlued/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,9 @@
The schemas that define our communication with the api.
"""


from typing import Optional, TypedDict
from ninja import Schema


class ResultDict(TypedDict):
"""
A class that defines the structure of results.
"""

display_name: str
backend_name: str
backend_version: str
job_id: str
qobj_id: Optional[str]
success: bool
status: str
header: dict
results: list


# pylint: disable=R0903
class JobSchemaIn(Schema):
"""
Expand All @@ -44,14 +26,3 @@ class JobSchemaWithTokenIn(Schema):

job: str
token: str


class JobResponseSchema(Schema):
"""
The schema for any job response.
"""

job_id: str
status: str
detail: str
error_message: str

0 comments on commit 915047d

Please sign in to comment.