Skip to content

Commit

Permalink
job status
Browse files Browse the repository at this point in the history
  • Loading branch information
forest1040 committed Oct 14, 2024
1 parent 79c2fa1 commit 1fdfc6a
Show file tree
Hide file tree
Showing 20 changed files with 57 additions and 78 deletions.
2 changes: 1 addition & 1 deletion backend/db/init/01.schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CREATE TABLE IF NOT EXISTS main.jobs (
name varchar(256) DEFAULT '' NOT NULL,
description VARCHAR(1024),
device_id VARCHAR(64) NOT NULL,
job_detail TEXT,
job_info TEXT,
transpiler_info TEXT,
simulator_info TEXT,
mitigation_info TEXT,
Expand Down
4 changes: 2 additions & 2 deletions backend/db/init/03.insert_job.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
INSERT INTO main.jobs (id, owner, name, description, device_id, job_detail, transpiler_info, simulator_info, mitigation_info, job_type, shots, status)
INSERT INTO main.jobs (id, owner, name, description, device_id, job_info, transpiler_info, simulator_info, mitigation_info, job_type, shots, status)
SELECT '01927422-86d4-73d6-abb4-f2de6a4f5910', 'admin', 'Test job 1', 'Test job 1 description', 'Kawasaki', '{\'code\': \'todo\'}', '', '', '', 'sampling', 1000, 'submitted'
WHERE NOT EXISTS (SELECT * FROM main.jobs WHERE owner = 'admin' AND name = 'Test job 1');

INSERT INTO main.jobs (id, owner, name, description, device_id, job_detail, transpiler_info, simulator_info, mitigation_info, job_type, shots, status)
INSERT INTO main.jobs (id, owner, name, description, device_id, job_info, transpiler_info, simulator_info, mitigation_info, job_type, shots, status)
SELECT '01927422-86d4-7cbf-98d3-32f5f1263cd9', 'admin', 'Test job 2', 'Test job 2 description', 'Kawasaki', '{\'code\': \'todo\'}', '', '', '', 'sampling', 1000, 'submitted'
WHERE NOT EXISTS (SELECT * FROM main.jobs WHERE owner = 'admin' AND name = 'Test job 2');

3 changes: 2 additions & 1 deletion backend/oas/provider/schemas/jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ jobs.JobDef:
name: "Bell State Sampling",
description: "Bell State Sampling Example",
device_id: "Kawasaki",
shots: 1000,
job_info: "{'code': '{type: string, example: \"OPENQASM 3; qubit[2] q; bit[2] c; h q[0]; cnot q[0], q[1]; c = measure q;\"}', 'operator': 'X 0 Y 1 Z 5 I 2'}",
transpiler_info: "{'qubit_allocation': {'0': 12, '1': 16}, 'skip_transpilation': false, 'seed_transpilation': 873}",
simulator_info: "{'n_qubits': 5, 'n_nodes': 12, 'n_per_node': 2, 'seed_simulation': 39058567, 'simulation_opt': {'optimization_method': 'light', 'optimization_block_size': 1, 'optimization_swap_level': 1}}",
mitigation_info: "{'ro_error_mitigation': 'pseudo_inverse'}",
job_type: "sampling",
shots: 1000,
status: "submitted",
created_at: "2022-10-19T11:45:34+09:00",
updated_at: "2022-10-19T11:45:34+09:00"
Expand Down
10 changes: 6 additions & 4 deletions backend/oas/user/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,12 @@ paths:
name: Bell State Sampling
description: Bell State Sampling Example
device_id: Kawasaki
shots: 1000
job_info: '{''code'': ''{type: string, example: "OPENQASM 3; qubit[2] q; bit[2] c; h q[0]; cnot q[0], q[1]; c = measure q;"}'', ''operator'': ''X 0 Y 1 Z 5 I 2'', ''result'': {''00'': 5020, ''11'': 4980}, ''transpiled_code'': '''', ''reason'': ''''}'
transpiler_info: ''
simulator_info: '{''n_qubits'': 5, ''n_nodes'': 12, ''n_per_node'': 2, ''seed_simulation'': 39058567, ''simulation_opt'': {''optimization_method'': ''light'', ''optimization_block_size'': 1, ''optimization_swap_level'': 1}}'
mitigation_info: ''
job_type: sampling
shots: 1000
status: submitted
created_at: '2022-10-19T11:45:34+09:00'
updated_at: '2022-10-19T11:45:34+09:00'
Expand All @@ -142,11 +143,12 @@ paths:
name: Bell State Sampling
description: Bell State Sampling Example
device_id: Kawasaki
shots: 1000
job_info: '{''code'': ''{type: string, example: "OPENQASM 3; qubit[2] q; bit[2] c; h q[0]; cnot q[0], q[1]; c = measure q;"}'', ''operator'': ''X 0 Y 1 Z 5 I 2'', ''result'': {''00'': 5020, ''11'': 4980}, ''transpiled_code'': '''', ''reason'': ''''}'
transpiler_info: '{''qubit_allocation'': {''0'': 12, ''1'': 16}, ''skip_transpilation'': false, ''seed_transpilation'': 873}'
simulator_info: ''
mitigation_info: '{''ro_error_mitigation'': ''pseudo_inverse''}'
job_type: sampling
shots: 1000
status: submitted
created_at: '2022-10-19T11:45:34+09:00'
updated_at: '2022-10-19T11:45:34+09:00'
Expand Down Expand Up @@ -517,7 +519,6 @@ components:
- detail
jobs.JobId:
type: string
format: uuid
example: 7af020f6-2e38-4d70-8cf0-4349650ea08c
jobs.JobInfo:
type: string
Expand Down Expand Up @@ -591,11 +592,12 @@ components:
name: Bell State Sampling
description: Bell State Sampling Example
device_id: Kawasaki
shots: 1000
job_info: '{''code'': ''{type: string, example: "OPENQASM 3; qubit[2] q; bit[2] c; h q[0]; cnot q[0], q[1]; c = measure q;"}'', ''Operator'': ''X 0 Y 1 Z 5 I 2'', ''result'': {''00'': 5020, ''11'': 4980}, ''transpiled_code'': '''', ''reason'': ''''}'
transpiler_info: '{''qubit_allocation'': {''0'': 12, ''1'': 16}, ''skip_transpilation'': false, ''seed_transpilation'': 873}'
simulator_info: '{''n_qubits'': 5, ''n_nodes'': 12, ''n_per_node'': 2, ''seed_simulation'': 39058567, ''simulation_opt'': {''optimization_method'': ''light'', ''optimization_block_size'': 1, ''optimization_swap_level'': 1}}'
mitigation_info: '{''ro_error_mitigation'': ''pseudo_inverse''}'
job_type: sampling
shots: 1000
status: submitted
created_at: '2022-10-19T11:45:34+09:00'
updated_at: '2022-10-19T11:45:34+09:00'
Expand Down
6 changes: 4 additions & 2 deletions backend/oas/user/paths/jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ jobs:
name: "Bell State Sampling",
description: "Bell State Sampling Example",
device_id: "Kawasaki",
shots: 1000,
job_info: "{'code': '{type: string, example: \"OPENQASM 3; qubit[2] q; bit[2] c; h q[0]; cnot q[0], q[1]; c = measure q;\"}', 'operator': 'X 0 Y 1 Z 5 I 2', 'result': {'00': 5020, '11': 4980}, 'transpiled_code': '', 'reason': ''}",
transpiler_info: "",
simulator_info: "{'n_qubits': 5, 'n_nodes': 12, 'n_per_node': 2, 'seed_simulation': 39058567, 'simulation_opt': {'optimization_method': 'light', 'optimization_block_size': 1, 'optimization_swap_level': 1}}",
mitigation_info: "",
job_type: "sampling",
shots: 1000,
status: "submitted",
created_at: "2022-10-19T11:45:34+09:00",
updated_at: "2022-10-19T11:45:34+09:00"
Expand All @@ -62,11 +63,12 @@ jobs:
name: "Bell State Sampling",
description: "Bell State Sampling Example",
device_id: "Kawasaki",
shots: 1000,
job_info: "{'code': '{type: string, example: \"OPENQASM 3; qubit[2] q; bit[2] c; h q[0]; cnot q[0], q[1]; c = measure q;\"}', 'operator': 'X 0 Y 1 Z 5 I 2', 'result': {'00': 5020, '11': 4980}, 'transpiled_code': '', 'reason': ''}",
transpiler_info: "{'qubit_allocation': {'0': 12, '1': 16}, 'skip_transpilation': false, 'seed_transpilation': 873}",
simulator_info: "",
mitigation_info: "{'ro_error_mitigation': 'pseudo_inverse'}",
job_type: "sampling",
shots: 1000,
status: "submitted",
created_at: "2022-10-19T11:45:34+09:00",
updated_at: "2022-10-19T11:45:34+09:00"
Expand Down
4 changes: 2 additions & 2 deletions backend/oas/user/schemas/jobs.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
jobs.JobId:
type: string
format: uuid
example: "7af020f6-2e38-4d70-8cf0-4349650ea08c"

jobs.GetJobStatusResponse:
Expand Down Expand Up @@ -94,11 +93,12 @@ jobs.JobDef:
name: "Bell State Sampling",
description: "Bell State Sampling Example",
device_id: "Kawasaki",
shots: 1000,
job_info: "{'code': '{type: string, example: \"OPENQASM 3; qubit[2] q; bit[2] c; h q[0]; cnot q[0], q[1]; c = measure q;\"}', 'Operator': 'X 0 Y 1 Z 5 I 2', 'result': {'00': 5020, '11': 4980}, 'transpiled_code': '', 'reason': ''}",
transpiler_info: "{'qubit_allocation': {'0': 12, '1': 16}, 'skip_transpilation': false, 'seed_transpilation': 873}",
simulator_info: "{'n_qubits': 5, 'n_nodes': 12, 'n_per_node': 2, 'seed_simulation': 39058567, 'simulation_opt': {'optimization_method': 'light', 'optimization_block_size': 1, 'optimization_swap_level': 1}}",
mitigation_info: "{'ro_error_mitigation': 'pseudo_inverse'}",
job_type: "sampling",
shots: 1000,
status: "submitted",
created_at: "2022-10-19T11:45:34+09:00",
updated_at: "2022-10-19T11:45:34+09:00"
Expand Down
2 changes: 0 additions & 2 deletions backend/oqtopus_cloud/common/models/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ class Device(Base):
)
created_at: Mapped[datetime.datetime] = mapped_column(
TIMESTAMP,
default="CURRENT_TIMESTAMP",
)
updated_at: Mapped[datetime.datetime] = mapped_column(
TIMESTAMP,
default="CURRENT_TIMESTAMP",
)
6 changes: 2 additions & 4 deletions backend/oqtopus_cloud/common/models/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Job(Base):
description (str): Additional notes for the job.
device_id (str): The device used for the job.
n_qubits (int): The number of qubits used in the job.
job_detail(str): The details of the job.
job_info(str): The information of the job.
transpiler_info(str): The information about the transpiler.
simulator_info(str): The information about the simulator.
mitigation_info(str): The information about the error mitigation.
Expand All @@ -53,7 +53,7 @@ class Job(Base):
String(64),
nullable=False,
)
job_detail: Mapped[str]
job_info: Mapped[str]
transpiler_info: Mapped[str]
simulator_info: Mapped[str]
mitigation_info: Mapped[str]
Expand Down Expand Up @@ -82,11 +82,9 @@ class Job(Base):
)
created_at: Mapped[datetime.datetime] = mapped_column(
TIMESTAMP,
default="CURRENT_TIMESTAMP",
)
updated_at: Mapped[datetime.datetime] = mapped_column(
TIMESTAMP,
default="CURRENT_TIMESTAMP",
)


Expand Down
2 changes: 1 addition & 1 deletion backend/oqtopus_cloud/provider/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
# timestamp: 2024-10-14T07:29:57+00:00
# timestamp: 2024-10-14T08:14:38+00:00
# version: 0.25.9
2 changes: 1 addition & 1 deletion backend/oqtopus_cloud/provider/schemas/devices.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
# timestamp: 2024-10-14T07:29:57+00:00
# timestamp: 2024-10-14T08:14:38+00:00
# version: 0.25.9

from __future__ import annotations
Expand Down
2 changes: 1 addition & 1 deletion backend/oqtopus_cloud/provider/schemas/error.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
# timestamp: 2024-10-14T07:29:57+00:00
# timestamp: 2024-10-14T08:14:38+00:00
# version: 0.25.9

from __future__ import annotations
Expand Down
2 changes: 1 addition & 1 deletion backend/oqtopus_cloud/provider/schemas/jobs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
# timestamp: 2024-10-14T07:29:57+00:00
# timestamp: 2024-10-14T08:14:38+00:00
# version: 0.25.9

from __future__ import annotations
Expand Down
59 changes: 18 additions & 41 deletions backend/oqtopus_cloud/user/routers/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ def get_jobs(

def validate_name(request: JobDef) -> str | None:
if request.name is not None:
request.name
return None
return request.name
return ""


def validate_description(
request: JobDef,
) -> str | None:
return request.description if (request.description is not None) else None
return request.description if (request.description is not None) else ""


@router.post(
Expand Down Expand Up @@ -117,12 +117,12 @@ def submit_jobs(

job = Job(
# TODO: UUIDv7
id=uuid.uuid4().bytes,
id=uuid.uuid4(),
owner=owner,
name=name,
description=description,
device_id=request.device_id,
job_detail=request.job_detail,
job_info=request.job_info,
transpiler_info=request.transpiler_info,
simulator_info=request.simulator_info,
mitigation_info=request.mitigation_info,
Expand All @@ -139,7 +139,7 @@ def submit_jobs(


@router.get(
"/jobs/{jobId}",
"/jobs/{job_id}",
response_model=JobDef,
responses={400: {"model": Detail}, 404: {"model": Detail}, 500: {"model": Detail}},
)
Expand All @@ -150,14 +150,8 @@ def get_job(
db: Session = Depends(get_db),
) -> JobDef | ErrorResponse:
try:
JobId(root=uuid.UUID(job_id))
except ValidationError:
logger.info(f"invalid job id: {job_id}")
return BadRequestResponse(detail="invalid job id")
try:
job_id = uuid.UUID(job_id).bytes
owner = event.state.owner
logger.info("invoked!", extra={"owner": owner})
logger.info("invoked!", extra={"owner": owner, "job_id": job_id})
job = db.query(Job).filter(Job.id == job_id, Job.owner == owner).first()
if job is None:
return NotFoundErrorResponse(detail="job not found with the given id")
Expand All @@ -168,7 +162,7 @@ def get_job(


@router.delete(
"/jobs/{jobId}",
"/jobs/{job_id}",
response_model=SuccessResponse,
responses={400: {"model": Detail}, 404: {"model": Detail}, 500: {"model": Detail}},
)
Expand All @@ -179,12 +173,6 @@ def delete_job(
db: Session = Depends(get_db),
) -> SuccessResponse | ErrorResponse:
try:
JobId(root=uuid.UUID(job_id))
except ValidationError:
logger.info(f"invalid job id: {job_id}")
return BadRequestResponse(detail="invalid job id")
try:
job_id = uuid.UUID(job_id).bytes
owner = event.state.owner
logger.info("invoked!", extra={"owner": owner})
job = db.get(Job, job_id)
Expand All @@ -194,7 +182,7 @@ def delete_job(

if job.owner != owner or job.status not in ["success", "failed", "cancelled"]:
return NotFoundErrorResponse(
detail=f"{job_id} job is not in valid status for deletion (valid statuses for deletion: 'COMPLETED', 'FAILED' and 'CANCELLED')"
detail=f"{job_id} job is not in valid status for deletion (valid statuses for deletion: 'success', 'failed' and 'cancelled')"
)

db.delete(job)
Expand All @@ -206,35 +194,30 @@ def delete_job(


@router.get(
"/jobs/{jobId}/status",
response_model=str,
"/jobs/{job_id}/status",
response_model=GetJobStatusResponse,
responses={400: {"model": Detail}, 404: {"model": Detail}, 500: {"model": Detail}},
)
@tracer.capture_method
def get_job_status(
event: Event,
jobId: str,
job_id: str,
db: Session = Depends(get_db),
) -> str | ErrorResponse:
try:
JobId(root=uuid.UUID(jobId))
except ValidationError:
logger.info(f"invalid job id: {jobId}")
return BadRequestResponse(detail="invalid job id")
) -> GetJobStatusResponse | ErrorResponse:
owner = event.state.owner
logger.info("invoked!", extra={"owner": owner})
job = (
db.query(Job.id, Job.status)
.filter(
Job.id == uuid.UUID(jobId).bytes,
Job.id == job_id,
Job.owner == owner,
)
.first()
)
if job is None:
return NotFoundErrorResponse(detail="job not found with the given id")
return GetJobStatusResponse(
jobId=JobId(uuid.UUID(jobId)), status=JobStatus(root=job.status)
job_id=JobId(job_id), status=JobStatus(job.status)
)


Expand All @@ -246,16 +229,10 @@ def get_job_status(
@tracer.capture_method
def cancel_job(
event: Event,
jobId: str,
job_id: str,
db: Session = Depends(get_db),
) -> SuccessResponse | ErrorResponse:
try:
JobId(root=uuid.UUID(jobId))
except ValidationError:
logger.info(f"invalid job id: {jobId}")
return BadRequestResponse(detail="invalid job id")
try:
job_id = uuid.UUID(jobId).bytes
owner = event.state.owner
logger.info("invoked!", extra={"owner": owner})

Expand All @@ -265,7 +242,7 @@ def cancel_job(
return NotFoundErrorResponse(detail="job not found with the given id")
if job.owner != owner or job.status not in ["ready", "submitted", "running"]:
return NotFoundErrorResponse(
detail=f"{jobId} job is not in valid status for cancellation (valid statuses for cancellation: 'QUEUED_FETCHED', 'submitted' and 'RUNNING')"
detail=f"{job_id} job is not in valid status for cancellation (valid statuses for cancellation: 'QUEUED_FETCHED', 'submitted' and 'RUNNING')"
)
if job.status in ["submitted", "ready", "running"]:
logger.info(
Expand All @@ -286,7 +263,7 @@ def cancel_job(
"name": "name",
"description": "description",
"device_id": "device_id",
"job_detail": "job_detail",
"job_info": "job_info",
"transpiler_info": "transpiler_info",
"simulator_info": "simulator_info",
"mitigation_info": "mitigation_info",
Expand Down
2 changes: 1 addition & 1 deletion backend/oqtopus_cloud/user/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
# timestamp: 2024-10-14T07:29:50+00:00
# timestamp: 2024-10-14T08:14:30+00:00
# version: 0.25.9
2 changes: 1 addition & 1 deletion backend/oqtopus_cloud/user/schemas/devices.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
# timestamp: 2024-10-14T07:29:50+00:00
# timestamp: 2024-10-14T08:14:30+00:00
# version: 0.25.9

from __future__ import annotations
Expand Down
2 changes: 1 addition & 1 deletion backend/oqtopus_cloud/user/schemas/error.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: openapi.yaml
# timestamp: 2024-10-14T07:29:50+00:00
# timestamp: 2024-10-14T08:14:30+00:00
# version: 0.25.9

from __future__ import annotations
Expand Down
Loading

0 comments on commit 1fdfc6a

Please sign in to comment.