diff --git a/ot2_driver/protopiler/config.py b/ot2_driver/protopiler/config.py index 52f9080..5265957 100644 --- a/ot2_driver/protopiler/config.py +++ b/ot2_driver/protopiler/config.py @@ -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 diff --git a/src/ot2_rest_node.py b/src/ot2_rest_node.py index 9de2968..af5bd1a 100644 --- a/src/ot2_rest_node.py +++ b/src/ot2_rest_node.py @@ -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 @@ -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: @@ -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: @@ -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/") @@ -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, @@ -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) @@ -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" @@ -376,15 +381,15 @@ 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() @@ -392,7 +397,8 @@ 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()