Skip to content

Commit

Permalink
multichannel payload debug complete, needs robustness testing
Browse files Browse the repository at this point in the history
  • Loading branch information
caseystone committed Dec 10, 2024
1 parent b8f4897 commit 361a9de
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 45 deletions.
21 changes: 15 additions & 6 deletions ot2_driver/ot2_driver_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,21 @@ def execute(self, run_id: str) -> Dict[str, Dict[str, str]]:
print(f"Could not run play action on {run_id}")
print(execute_run_resp.json())

while self.check_run_status(run_id) not in {
RunStatus.FAILED,
RunStatus.SUCCEEDED,
RunStatus.STOPPED,
}:
time.sleep(1)

while True:
try:
if self.check_run_status(run_id) in {
RunStatus.FAILED,
RunStatus.SUCCEEDED,
RunStatus.STOPPED,
}:
break
else:
time.sleep(1)

except Exception as e:
print(e)
pass

return self.get_run(run_id)

Expand Down
25 changes: 21 additions & 4 deletions ot2_driver/protopiler/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ def check_list_lengths_match(self) -> "Transfer":
"""Make sure that all list fields are the same length, if they are lists"""
iter_len = 0
listable_fields = [
"multi_volume",
"multi_source",
"multi_volume",
"multi_source",
"multi_destination",
"multi_mix_cycles",
"multi_mix_volume",
Expand All @@ -183,8 +183,22 @@ def check_list_lengths_match(self) -> "Transfer":
"multi_blow_out",
"multi_drop_tip",
]

for field in listable_fields:
if isinstance(getattr(self, field), list):

if isinstance(getattr(self, field), str):
if "payload" in getattr(self, field) or ":" in getattr(self,field):
continue # skip this iteration and leave the value that contains a payload as is

else:
setattr(self, field, [getattr(self, field)])

# if not already handled in string block and is not a list
if not isinstance(getattr(self, field), str) and not isinstance(getattr(self, field), list):
# convert the value into a list of of the value
setattr(self, field, [getattr(self, field)])

if isinstance(getattr(self, field), list): # just look to see if you have user entered lists of different lengths
if iter_len == 0:
iter_len = len(getattr(self, field))
elif len(getattr(self, field)) != iter_len:
Expand All @@ -193,8 +207,11 @@ def check_list_lengths_match(self) -> "Transfer":
)
if iter_len > 0:
for field in listable_fields:
if not isinstance(getattr(self, field), list):
if "payload" in getattr(self, field) and isinstance(getattr(self, field), str):
pass
elif not isinstance(getattr(self, field), list):
setattr(self, field, [getattr(self, field)] * iter_len)

return self


Expand Down
59 changes: 25 additions & 34 deletions ot2_driver/protopiler/protopiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def load_config(
)

self.commands = self.config.commands

self._postprocess_commands()

def _postprocess_commands(self) -> None: # Could use more testing
Expand Down Expand Up @@ -242,17 +243,15 @@ def _postprocess_commands(self) -> None: # Could use more testing
peek_elem = command.multi_source
if isinstance(command.multi_source, list): # No mixing and matching
peek_elem = command.multi_source[0]
peek_well = peek_elem.split(":")[-1]

peek_well = peek_elem.split(":")[-1] # 4:payload.source_wells or 4:['A1,'A2']

# check if it follows naming convention`[A-Z,a-z]?[0-9]{1,3}`
# TODO better way to check the naming conventions for the wells
peek_well = peek_well.split(", ")

if len(peek_well) == 1 and "payload" not in peek_well[0]:

# for source
if len(peek_well) == 1 and "payload" not in peek_well[0]: # TESTING added brackets# ISSUE! it's not recognizing payload as in the peek well because it's a list!!!!!!

# PEEK WELL = ['payload.source_wells_1']
# read from file
new_locations = []

Expand All @@ -264,6 +263,9 @@ def _postprocess_commands(self) -> None: # Could use more testing
new_locations.append(f"{orig_deck_location}:{loc}")

command.multi_source = new_locations


# Everything below is for the destination ------------------------------------------------------------
if ":[" in command.multi_destination:
command.multi_destination = self._unpack_multi_alias(
command.multi_destination
Expand Down Expand Up @@ -578,16 +580,6 @@ def yaml_to_protocol(
if reset_when_done:
self._reset()

# TESTING
with open(protocol_out, "r") as f:
print("************************************************************")
print()
content = f.read()
print(content)
print()
print("*************************************************************")
print()


return protocol_out, resource_file_out

Expand All @@ -602,9 +594,6 @@ def _create_commands(self, payload: Optional[Dict]) -> List[str]:
List[str]: python snippets of commands to be run
"""

# TESTING
print(f"PROTOPILER CREATE COMMANDS PAYLoaD: {payload}")

commands = []

# load command templates
Expand Down Expand Up @@ -640,39 +629,41 @@ def _create_commands(self, payload: Optional[Dict]) -> List[str]:

(arg_keys, arg_values) = zip(*command_block.__dict__.items())

# TESTING
print(f"arg values: {arg_values}")
print(f"arg keys: {arg_keys}")

for key, value in payload.items():

# TESTING
print(f"KEY: {key}")
print(f"value: {value}")

if "payload." not in key:
old_key = key
key = f"payload.{key}"

if isinstance(command_block, Multi_Transfer):

arg_values_list = []
# make all lists in arg_values single items
for val in arg_values:
if isinstance(val, list):
val = val[0]
arg_values_list.append(val)

if key in arg_values_list:
idx = arg_values.index(key)
step_arg_key = arg_keys[idx]
setattr(command_block, step_arg_key, value[0])
arg_values_list.append(val) # new list without lists, simple

for i in range(len(arg_values_list)):
if old_key in str(arg_values_list[i]):
idx = i
step_arg_key = arg_keys[idx]

plate_loc = arg_values_list[i].split(":")[0]

formatted_value = []
formatted_value.append(str(plate_loc) + ":" + str(value[0]))

setattr(command_block, step_arg_key, formatted_value)


else:
if key in arg_values:
print("KEY IN ARG VALUES")
idx = arg_values.index(key)
step_arg_key = arg_keys[idx]
# this feels slimy...
setattr(command_block, step_arg_key, value) # TESTING changes the command block based on the payload
setattr(command_block, step_arg_key, value)


if isinstance(command_block, Transfer):
for (
Expand Down
2 changes: 1 addition & 1 deletion src/ot2_rest_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def run_protocol(
elif response_flag == "failed":
state.status[ModuleStatus.READY] = False
state.status[ModuleStatus.ERROR] = True
response = StepResponse
response = StepResponse()
response.status = StepStatus.FAILED
response.error = "an error occurred"
# if resource_config_path:
Expand Down

0 comments on commit 361a9de

Please sign in to comment.