Skip to content

Commit

Permalink
Merge pull request #45 from AD-SDL/admin_actions
Browse files Browse the repository at this point in the history
Admin actions
  • Loading branch information
tginsbu1 authored Nov 19, 2024
2 parents 265d335 + a237942 commit 4e8681e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
18 changes: 17 additions & 1 deletion ot2_driver/protopiler/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,23 @@ def check_list_lengths_match(self) -> "Transfer":
if iter_len > 0:
for field in listable_fields:
if not isinstance(getattr(self, field), list):
setattr(self, field, [getattr(self, field)] * iter_len)
get_field = getattr(self, field)
if isinstance(get_field, str) and ":[" in get_field:
print(get_field)
print(get_field.split(":")[-1])
s = get_field.split(":")[-1]
print("right here thanks")
try:
print(s.strip("[]").split(","))
except Exception as e:
print(e)
test = s.strip("[]").split(",")
if iter_len != len(test):
raise ValidationError(
"Multiple iterables of different lengths found, cannot determine dimension to iterate over"
)
else:
setattr(self, field, [getattr(self, field)] * iter_len)
return self


Expand Down
28 changes: 17 additions & 11 deletions src/ot2_rest_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import requests
import yaml
from fastapi import UploadFile
from fastapi.datastructures import State
from typing_extensions import Annotated
from urllib3.exceptions import ConnectTimeoutError
Expand Down Expand Up @@ -67,10 +68,12 @@ def connect_robot(state: State):
try:
print(state.ip)
state.ot2 = OT2_Driver(OT2_Config(ip=state.ip))
state.status = ModuleStatus.IDLE
state.status[ModuleStatus.READY] = True
state.status[ModuleStatus.INIT] = False

except ConnectTimeoutError as connection_err:
state.status = ModuleStatus.ERROR
state.status[ModuleStatus.READY] = False
state.status[ModuleStatus.ERROR] = True
print("Connection error code: " + connection_err)

except HTTPError as http_error:
Expand All @@ -83,7 +86,8 @@ def connect_robot(state: State):
print("Connection error code: " + str(conn_err))

except Exception as error_msg:
state.status = ModuleStatus.ERROR
state.status[ModuleStatus.READY] = False
state.status[ModuleStatus.ERROR] = True
print("-------" + str(error_msg) + " -------")

else:
Expand Down Expand Up @@ -272,7 +276,6 @@ def ot2_startup(state: State):

state.node_name = state.name
state.ip = state.ot2_ip
state.status = "UNKNOWN"
temp_dir = Path.home() / ".wei" / ".ot2_temp"
temp_dir.mkdir(exist_ok=True)
state.resources_folder_path = str(temp_dir / state.node_name / "resources/")
Expand All @@ -289,6 +292,7 @@ def ot2_startup(state: State):
def run_protocol(
state: State,
action: ActionRequest,
protocol: Annotated[UploadFile, "Protocol File"],
use_existing_resources: Annotated[
bool, "Whether to use the existing resource file or restart"
] = False,
Expand Down Expand Up @@ -336,7 +340,7 @@ def run_protocol(
)

if response_flag == "succeeded":
state.status = ModuleStatus.IDLE
state.status[ModuleStatus.READY] = True
Path(logs_folder_path).mkdir(parents=True, exist_ok=True)
with open(Path(logs_folder_path) / f"{run_id}.json", "w") as f:
json.dump(state.ot2.get_run_log(run_id), f, indent=2)
Expand All @@ -346,14 +350,15 @@ def run_protocol(
# if resource_config_path:
# response.resources = str(resource_config_path)
elif response_flag == "stopped":
state.status = ModuleStatus.IDLE
state.status[ModuleStatus.READY] = True
Path(logs_folder_path).mkdir(parents=True, exist_ok=True)
with open(Path(logs_folder_path) / f"{run_id}.json", "w") as f:
json.dump(state.ot2.get_run_log(run_id), f, indent=2)
return StepFileResponse(status=StepStatus.FAILED, files={"log": f.name})

elif response_flag == "failed":
state.status = ModuleStatus.ERROR
state.status[ModuleStatus.READY] = False
state.status[ModuleStatus.ERROR] = True
response = StepResponse
response.status = StepStatus.FAILED
response.error = "an error occurred"
Expand All @@ -376,23 +381,24 @@ def pause(state: State):
"""pauses the ot2 run"""
if state.run_id is not None:
state.ot2.pause(state.run_id)
state.status = ModuleStatus.PAUSED
state.status[ModuleStatus.PAUSED] = True


@rest_module.resume()
def resume(state: State):
"""resumes paused ot2_run"""
if state.run_id is not None and state.status == ModuleStatus.PAUSED:
if state.run_id is not None and state.status[ModuleStatus.PAUSED]:
state.ot2.resume(state.run_id)
state.status = ModuleStatus.BUSY
state.status[ModuleStatus.PAUSED] = False


@rest_module.cancel()
def cancel(state: State):
"""cancels ot2 run"""
if state.run_id is not None:
state.ot2.cancel(state.run_id)
state.status = ModuleStatus.READY
state.status[ModuleStatus.PAUSED] = False
state.status[ModuleStatus.CANCELLED] = True


rest_module.start()

0 comments on commit 4e8681e

Please sign in to comment.