Skip to content

Commit

Permalink
change pending_tasks to pending_jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
forest1040 committed Oct 10, 2024
1 parent 3475499 commit c9012af
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 33 deletions.
22 changes: 9 additions & 13 deletions backend/oqtopus_cloud/common/models/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ class Device(Base):
id (str): The unique identifier of the device.
device_type (str): The type of the device (QPU or simulator).
status (str): The status of the device (AVAILABLE or NOT_AVAILABLE).
restart_at (datetime): The date and time when the device is scheduled to restart.
pending_tasks (int): The number of pending tasks for the device.
available_at (datetime): The date and time when the device is scheduled to restart.
pending_jobs (int): The number of pending jobs for the device.
n_qubits (int): The number of qubits of the device.
n_nodes (int): The number of nodes of the device.
basis_gates (str): The basis gates supported by the device.
instructions (str): The supported instructions of the device.
calibration_data (str): The calibration data of the device.
device_info (str): The infomation of the device.
calibrated_at (datetime): The date and time when the device was last calibrated.
description (str): The description of the device.
"""
Expand All @@ -48,25 +47,22 @@ class Device(Base):
)
status: Mapped[enum.Enum] = mapped_column(
Enum(
"AVAILABLE",
"NOT_AVAILABLE",
"available",
"unavailable",
),
nullable=False,
default="NOT_AVAILABLE",
default="unavailable",
)
restart_at: Mapped[datetime.datetime] = mapped_column(
available_at: Mapped[datetime.datetime] = mapped_column(
nullable=True,
)
pending_tasks: Mapped[int] = mapped_column(
pending_jobs: Mapped[int] = mapped_column(
nullable=False,
default=0,
)
n_qubits: Mapped[int] = mapped_column(
nullable=False,
)
n_nodes: Mapped[int] = mapped_column(
nullable=True,
)
basis_gates: Mapped[str] = mapped_column(
String(256),
nullable=False,
Expand All @@ -75,7 +71,7 @@ class Device(Base):
String(64),
nullable=False,
)
calibration_data: Mapped[str]
device_info: Mapped[str]
calibrated_at: Mapped[datetime.datetime]
description: Mapped[str] = mapped_column(
String(128),
Expand Down
12 changes: 6 additions & 6 deletions backend/oqtopus_cloud/provider/routers/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def update_device_status(
return DeviceDataUpdateResponse(message="Device's data updated")


def update_device_pending_tasks(
def update_device_pending_jobs(
device: Device, request: DevicePendingTasksUpdate, db: Session
) -> DeviceDataUpdateResponse | ErrorResponse:
"""
Expand All @@ -88,12 +88,12 @@ def update_device_pending_tasks(
Raises:
BadRequest: If the new number of pending tasks is not provided or is less than 0.
"""
n_pending_tasks = request.nPendingTasks
if n_pending_tasks is None:
n_pending_jobs = request.nPendingTasks
if n_pending_jobs is None:
return BadRequestResponse("nPendingTasks is required")
if n_pending_tasks < 0:
if n_pending_jobs < 0:
return BadRequestResponse("nPendingTasks must be greater than or equal to 0")
device.pending_tasks = n_pending_tasks
device.pending_jobs = n_pending_jobs
db.commit()
return DeviceDataUpdateResponse(message="Device's data updated")

Expand Down Expand Up @@ -166,7 +166,7 @@ def update_device(
if isinstance(request.root, DeviceStatusUpdate):
return update_device_status(device, request.root, db)
elif isinstance(request.root, DevicePendingTasksUpdate):
return update_device_pending_tasks(
return update_device_pending_jobs(
device,
request.root,
db,
Expand Down
2 changes: 1 addition & 1 deletion backend/oqtopus_cloud/provider/schemas/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DevicePendingTasksUpdate(BaseModel):
Literal["DevicePendingTasksUpdate"],
Field(examples=["DevicePendingTasksUpdate"]),
]
n_pending_tasks: Optional[int] = None
n_pending_jobs: Optional[int] = None


class DeviceCalibrationUpdate(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion backend/oqtopus_cloud/user/routers/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_device(
"device_type": "device_type",
"status": "status",
"available_at": "available_at",
"pending_tasks": "n_pending_tasks",
"pending_jobs": "n_pending_jobs",
"n_qubits": "n_qubits",
"n_nodes": "n_nodes",
"basis_gates": "basis_gates",
Expand Down
2 changes: 1 addition & 1 deletion backend/oqtopus_cloud/user/schemas/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DeviceInfo(BaseModel):
"""
Parameter mandatory and valid for 'unavailable' devices
"""
n_pending_tasks: Annotated[Optional[int], Field(None, examples=[8])]
n_pending_jobs: Annotated[Optional[int], Field(None, examples=[8])]
n_qubits: Annotated[Optional[int], Field(None, examples=[39])]
basis_gates: Annotated[
Optional[list[str]],
Expand Down
4 changes: 2 additions & 2 deletions backend/tests/oqtopus_cloud/common/test_model_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def _get_model_dict():
"device_type": "simulator",
"status": "AVAILABLE",
"restart_at": datetime(2023, 1, 2, 12, 34, 56),
"pending_tasks": 8,
"pending_jobs": 8,
"n_qubits": 39,
"n_nodes": 512,
"basis_gates": ["x", "sx", "rz", "cx"],
Expand Down Expand Up @@ -44,7 +44,7 @@ def test_model_to_schema_dict():
"device_type": "deviceType", # transform field name
"status": "status",
"restart_at": "restart_at",
"pending_tasks": "pending_tasks",
"pending_jobs": "pending_jobs",
"n_qubits": "n_qubits",
"n_nodes": "n_nodes",
"basis_gates": "basis_gates",
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/oqtopus_cloud/provider/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def insert_initial_data(db: Session):
device_type="QPU",
status="NOT_AVAILABLE",
restart_at=datetime(2024, 3, 4, 12, 34, 56),
pending_tasks=0,
pending_jobs=0,
n_qubits=64,
n_nodes=0,
basis_gates='["sx", "rx", "rzx90", "id"]',
Expand Down
8 changes: 4 additions & 4 deletions backend/tests/oqtopus_cloud/provider/routers/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
)
from oqtopus_cloud.provider.routers.devices import (
update_device_calibration,
update_device_pending_tasks,
update_device_pending_jobs,
update_device_status,
)
from oqtopus_cloud.provider.schemas.devices import (
Expand Down Expand Up @@ -42,7 +42,7 @@ def _get_model():
"device_type": "QPU",
"status": "AVAILABLE",
"restart_at": datetime(2023, 1, 2, 12, 34, 56),
"pending_tasks": 8,
"pending_jobs": 8,
"n_qubits": 39,
"n_nodes": 512,
"basis_gates": '["x", "sx", "rz", "cx"]',
Expand All @@ -54,7 +54,7 @@ def _get_model():
return Device(**mode_dict)


def test_update_device_pending_tasks(test_db):
def test_update_device_pending_jobs(test_db):
# Arrange
test_db.add(_get_model())
test_db.commit()
Expand All @@ -63,7 +63,7 @@ def test_update_device_pending_tasks(test_db):
request = DevicePendingTasksUpdate(
command="DevicePendingTasksUpdate", nPendingTasks=8
)
actual = update_device_pending_tasks(device=device, request=request, db=test_db)
actual = update_device_pending_jobs(device=device, request=request, db=test_db)
# Assert
expected = DeviceDataUpdateResponse(message="Device's data updated")
assert actual == expected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _get_device_model():
"device_type": "QPU",
"status": "AVAILABLE",
"restart_at": datetime(2023, 1, 2, 12, 34, 56),
"pending_tasks": 8,
"pending_jobs": 8,
"n_qubits": 39,
"n_nodes": 512,
"basis_gates": '["x", "sx", "rz", "cx"]',
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/oqtopus_cloud/provider/routers/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _get_device_model():
"device_type": "QPU",
"status": "AVAILABLE",
"restart_at": datetime(2023, 1, 2, 12, 34, 56),
"pending_tasks": 8,
"pending_jobs": 8,
"n_qubits": 39,
"n_nodes": 512,
"basis_gates": '["x", "sx", "rz", "cx"]',
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/oqtopus_cloud/user/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def insert_initial_data(db: Session):
device_type="QPU",
status="NOT_AVAILABLE",
restart_at=datetime(2024, 3, 4, 12, 34, 56),
pending_tasks=0,
pending_jobs=0,
n_qubits=64,
n_nodes=0,
basis_gates='["sx", "rx", "rzx90", "id"]',
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/oqtopus_cloud/user/routers/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _get_model():
"device_type": "simulator",
"status": "AVAILABLE",
"restart_at": datetime(2023, 1, 2, 12, 34, 56),
"pending_tasks": 8,
"pending_jobs": 8,
"n_qubits": 39,
"n_nodes": 512,
"basis_gates": '["x", "sx", "rz", "cx"]',
Expand Down

0 comments on commit c9012af

Please sign in to comment.