Skip to content

Commit

Permalink
Merge branch 'develop' into issue#225
Browse files Browse the repository at this point in the history
  • Loading branch information
n-kakuko authored Oct 10, 2024
2 parents fed5deb + 27b38d9 commit 2a41abd
Show file tree
Hide file tree
Showing 47 changed files with 1,494 additions and 1,219 deletions.
12 changes: 8 additions & 4 deletions backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ generate:
@poetry run datamodel-codegen \
--use-schema-description \
--target-python-version 3.12 \
--enable-version-header \
--field-constraints \
--use-annotated \
--use-field-description \
--input ${INPUT} \
--input-file-type openapi \
--output-model-type pydantic_v2.BaseModel \
--enum-field-as-literal all \
--disable-timestamp \
--use-standard-collections \
--strict-nullable \
--use-default \
Expand All @@ -43,16 +43,20 @@ export ENV=local
export DB_HOST=localhost
export DB_NAME=main
export DB_CONNECTOR=mysql+pymysql

export ALLOW_ORIGINS=http://127.0.0.1:8000# pass the allowed origins -> http://localhost:3000,http://localhost:3001
export ALLOW_CREDENTIALS=true
export ALLOW_METHODS=*# pass the allowed methods -> GET,POST,PUT,DELETE
export ALLOW_HEADERS=*# pass the allowed headers -> Content-Type,Authorization
export LOG_LEVEL=DEBUG
run-user: ## Start the User API
@export POWERTOOLS_METRICS_NAMESPACE=user-api && \
export POWERTOOLS_SERVICE_NAME=user-api && \
poetry run uvicorn oqtopus_cloud.user.lambda_function:app --host 0.0.0.0 --port 8080 --reload
poetry run uvicorn oqtopus_cloud.user.lambda_function:app --host 0.0.0.0 --port 8080 --reload --log-level debug

run-provider: ## Start the Provider API
@export POWERTOOLS_METRICS_NAMESPACE=provider-api && \
export POWERTOOLS_SERVICE_NAME=provider-api && \
poetry run uvicorn oqtopus_cloud.provider.lambda_function:app --host 0.0.0.0 --port 8888 --reload
poetry run uvicorn oqtopus_cloud.provider.lambda_function:app --host 0.0.0.0 --port 8888 --reload --log-level debug

up: ## Start the DB
@docker compose up
Expand Down
8 changes: 4 additions & 4 deletions backend/oas/provider/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ components:
description: Parameter mandatory and valid for status 'NOT_AVAILABLE'
type: string
format: date-time
example: '2023-09-10T14:00:00Z'
example: '2023-09-10T14:00:00+09:00'
devices.DevicePendingTasksUpdate:
type: object
properties:
Expand Down Expand Up @@ -513,7 +513,7 @@ components:
description: Parameter mandatory and valid if calibrationData not null
type: string
format: date-time
example: '2023-09-10T14:00:00Z'
example: '2023-09-10T14:00:00+09:00'
devices.DeviceDataUpdate:
discriminator:
propertyName: command
Expand Down Expand Up @@ -710,7 +710,7 @@ components:
createdAt:
type: string
format: date-time
example: '2022-10-19 11:45:34'
example: '2022-10-19T11:45:34+09:00'
required:
- taskId
- code
Expand Down Expand Up @@ -739,7 +739,7 @@ components:
optimizationBlockSize: 1
optimizationSwapLevel: 1
status: QUEUED_FETCHED
createdAt: '2022-10-19 11:45:34'
createdAt: '2022-10-19T11:45:34+09:00'
tasks.TaskStatusUpdate:
type: object
properties:
Expand Down
4 changes: 2 additions & 2 deletions backend/oas/provider/schemas/devices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ devices.DeviceStatusUpdate:
description: "Parameter mandatory and valid for status 'NOT_AVAILABLE'"
type: string
format: date-time
example: "2023-09-10T14:00:00Z"
example: "2023-09-10T14:00:00+09:00"

devices.DevicePendingTasksUpdate:
type: object
Expand All @@ -57,7 +57,7 @@ devices.DeviceCalibrationUpdate:
description: "Parameter mandatory and valid if calibrationData not null"
type: string
format: date-time
example: "2023-09-10T14:00:00Z"
example: "2023-09-10T14:00:00+09:00"

components:
schemas:
Expand Down
12 changes: 0 additions & 12 deletions backend/oas/provider/schemas/hello.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions backend/oas/provider/schemas/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ tasks.TaskInfo:
createdAt:
type: string
format: date-time
example: "2022-10-19 11:45:34"
example: "2022-10-19T11:45:34+09:00"
required: [
taskId, code, device, action, skipTranspilation, status, createdAt
]
Expand All @@ -164,7 +164,7 @@ tasks.TaskInfo:
optimizationSwapLevel: 1
}
status: QUEUED_FETCHED
createdAt: '2022-10-19 11:45:34'
createdAt: "2022-10-19T11:45:34+09:00"

tasks.TaskStatusUpdate:
type: object
Expand Down
22 changes: 16 additions & 6 deletions backend/oas/user/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ paths:
$ref: '#/components/schemas/tasks.SubmitTaskResponse'
example:
taskId: 7af020f6-2e38-4d70-8cf0-4349650ea08c
createdAt: '2022-10-19T11:45:34+09:00'
status: QUEUED
'400':
description: Bad Request
content:
Expand Down Expand Up @@ -453,6 +455,8 @@ paths:
$ref: '#/components/schemas/tasks.SubmitTaskResponse'
example:
taskId: 7af020f6-2e38-4d70-8cf0-4349650ea08c
createdAt: '2022-10-19T11:45:34+09:00'
status: QUEUED
'400':
description: Bad Request
content:
Expand Down Expand Up @@ -928,7 +932,7 @@ components:
description: Parameter mandatory and valid for 'NOT_AVAILABLE' devices
type: string
format: date-time
example: '2022-10-19 11:45:34'
example: '2022-10-19T11:45:34+09:00'
nPendingTasks:
type: integer
example: 8
Expand Down Expand Up @@ -980,7 +984,7 @@ components:
description: Parameter available only for 'QPU' devices with available calibration data
type: string
format: date-time
example: '2022-10-19 11:45:34'
example: '2022-10-19T11:45:34+09:00'
description:
type: string
example: State vector-based quantum circuit simulator
Expand Down Expand Up @@ -1135,7 +1139,7 @@ components:
createdAt:
type: string
format: date-time
example: '2022-10-19 11:45:34'
example: '2022-10-19T11:45:34+09:00'
required:
- taskId
- code
Expand All @@ -1161,7 +1165,7 @@ components:
optimizationSwapLevel: 1
note: Bell State Sampling Example
status: QUEUED
createdAt: '2022-10-19 11:45:34'
createdAt: '2022-10-19T11:45:34+09:00'
tasks.SamplingTaskDef:
type: object
properties:
Expand Down Expand Up @@ -1240,6 +1244,12 @@ components:
properties:
taskId:
$ref: '#/components/schemas/tasks.TaskId'
createdAt:
type: string
format: date-time
example: '2022-10-19T11:45:34+09:00'
status:
$ref: '#/components/schemas/tasks.TaskStatus'
required:
- taskId
error.BadRequest:
Expand Down Expand Up @@ -1379,7 +1389,7 @@ components:
createdAt:
type: string
format: date-time
example: '2022-10-19 11:45:34'
example: '2022-10-19T11:45:34+09:00'
required:
- taskId
- code
Expand Down Expand Up @@ -1414,7 +1424,7 @@ components:
optimizationSwapLevel: 1
note: Bell State Estimation Example
status: QUEUED
createdAt: '2022-10-19 11:45:34'
createdAt: '2022-10-19T11:45:34+09:00'
tasks.EstimationTaskDef:
type: object
properties:
Expand Down
4 changes: 4 additions & 0 deletions backend/oas/user/paths/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ tasks.sampling:
$ref: "../schemas/tasks.yaml#/tasks.SubmitTaskResponse"
example:
taskId: 7af020f6-2e38-4d70-8cf0-4349650ea08c
createdAt: "2022-10-19T11:45:34+09:00"
status: "QUEUED"
'400':
description: Bad Request
content:
Expand Down Expand Up @@ -379,6 +381,8 @@ tasks.estimation:
$ref: "../schemas/tasks.yaml#/tasks.SubmitTaskResponse"
example:
taskId: 7af020f6-2e38-4d70-8cf0-4349650ea08c
createdAt: "2022-10-19T11:45:34+09:00"
status: "QUEUED"
"400":
description: Bad Request
content:
Expand Down
4 changes: 2 additions & 2 deletions backend/oas/user/schemas/devices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ devices.DeviceInfo:
description: "Parameter mandatory and valid for 'NOT_AVAILABLE' devices"
type: string
format: date-time
example: "2022-10-19 11:45:34"
example: "2022-10-19T11:45:34+09:00"
nPendingTasks:
type: integer
example: 8
Expand All @@ -45,7 +45,7 @@ devices.DeviceInfo:
description: "Parameter available only for 'QPU' devices with available calibration data"
type: string
format: date-time
example: "2022-10-19 11:45:34"
example: "2022-10-19T11:45:34+09:00"
description:
type: string
example: "State vector-based quantum circuit simulator"
Expand Down
16 changes: 12 additions & 4 deletions backend/oas/user/schemas/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,17 @@ tasks.SubmitTaskResponse:
properties:
taskId:
$ref: '#/components/schemas/tasks.TaskId'
createdAt:
type: string
format: date-time
example: "2022-10-19T11:45:34+09:00"
status:
$ref: "#/tasks.TaskStatus"

required:
- taskId


tasks.TaskStatus:
type: string
enum: ["QUEUED", "RUNNING", "COMPLETED", "FAILED", "CANCELLING", "CANCELLED"]
Expand Down Expand Up @@ -110,7 +118,7 @@ tasks.SamplingTaskInfo:
createdAt:
type: string
format: date-time
example: "2022-10-19 11:45:34"
example: "2022-10-19T11:45:34+09:00"
required: [
taskId, code, device, nShots, skipTranspilation, status, createdAt
]
Expand All @@ -133,7 +141,7 @@ tasks.SamplingTaskInfo:
},
note: "Bell State Sampling Example",
status: "QUEUED",
createdAt: "2022-10-19 11:45:34"
createdAt: "2022-10-19T11:45:34+09:00"
}

tasks.SamplingTaskDef:
Expand Down Expand Up @@ -384,7 +392,7 @@ tasks.EstimationTaskInfo:
createdAt:
type: string
format: date-time
example: "2022-10-19 11:45:34"
example: "2022-10-19T11:45:34+09:00"
required: [
taskId, code, device, method, operator, skipTranspilation, status, createdAt
]
Expand Down Expand Up @@ -413,5 +421,5 @@ tasks.EstimationTaskInfo:
},
note: "Bell State Estimation Example",
status: "QUEUED",
createdAt: "2022-10-19 11:45:34"
createdAt: "2022-10-19T11:45:34+09:00"
}
5 changes: 4 additions & 1 deletion backend/oqtopus_cloud/provider/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import os

from aws_lambda_powertools import Logger, Metrics, Tracer

logger: Logger = Logger()
tracer: Tracer = Tracer()
metrics: Metrics = Metrics()

logger.setLevel("INFO")
LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO")
logger.setLevel(LOG_LEVEL)
17 changes: 14 additions & 3 deletions backend/oqtopus_cloud/provider/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
This module is the entry point of the development application. It creates the FastAPI
"""

import os

import setuptools._distutils.util
from fastapi import FastAPI
from mangum import (
Mangum,
Expand All @@ -26,12 +29,20 @@
app: FastAPI = FastAPI()

app.add_middleware(CustomMiddleware)

ALLOW_ORIGINS = os.getenv("ALLOW_ORIGINS", "").split(",")
ALLOW_CREDENTIALS = setuptools._distutils.util.strtobool(
os.getenv("ALLOW_CREDENTIALS", "false")
)
ALLOW_METHODS = os.getenv("ALLOW_METHODS", "").split(",")
ALLOW_HEADERS = os.getenv("ALLOW_HEADERS", "").split(",")

app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_origins=ALLOW_ORIGINS,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
allow_methods=ALLOW_METHODS,
allow_headers=ALLOW_HEADERS,
)

app.include_router(
Expand Down
2 changes: 0 additions & 2 deletions backend/oqtopus_cloud/provider/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
# timestamp: 2024-08-29T09:11:46+00:00
# version: 0.25.8

from __future__ import annotations

Expand Down
6 changes: 2 additions & 4 deletions backend/oqtopus_cloud/provider/schemas/devices.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
# timestamp: 2024-08-29T09:11:46+00:00
# version: 0.25.8

from __future__ import annotations

Expand All @@ -18,7 +16,7 @@ class DeviceStatusUpdate(BaseModel):
]
status: Optional[Literal["AVAILABLE", "NOT_AVAILABLE"]] = None
restartAt: Annotated[
Optional[AwareDatetime], Field(None, examples=["2023-09-10T14:00:00Z"])
Optional[AwareDatetime], Field(None, examples=["2023-09-10T14:00:00+09:00"])
]
"""
Parameter mandatory and valid for status 'NOT_AVAILABLE'
Expand All @@ -39,7 +37,7 @@ class DeviceCalibrationUpdate(BaseModel):
]
calibrationData: Optional[CalibrationData] = None
calibratedAt: Annotated[
Optional[AwareDatetime], Field(None, examples=["2023-09-10T14:00:00Z"])
Optional[AwareDatetime], Field(None, examples=["2023-09-10T14:00:00+09:00"])
]
"""
Parameter mandatory and valid if calibrationData not null
Expand Down
2 changes: 0 additions & 2 deletions backend/oqtopus_cloud/provider/schemas/error.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
# timestamp: 2024-08-29T09:11:46+00:00
# version: 0.25.8

from __future__ import annotations

Expand Down
2 changes: 0 additions & 2 deletions backend/oqtopus_cloud/provider/schemas/results.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
# timestamp: 2024-08-29T09:11:46+00:00
# version: 0.25.8

from __future__ import annotations

Expand Down
Loading

0 comments on commit 2a41abd

Please sign in to comment.