Skip to content

Commit bfb6265

Browse files
committed
type
1 parent 5db59a5 commit bfb6265

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

pylabrobot/liquid_handling/liquid_handler.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,10 +2477,10 @@ async def consolidate_tip_inventory(self, tip_racks: List[TipRack]):
24772477
visits to the same drop columns.
24782478
"""
24792479

2480-
def merge_sublists(lists: List[List[int]], max_len: int) -> List[List[int]]:
2480+
def merge_sublists(lists: List[List[TipSpot]], max_len: int) -> List[List[TipSpot]]:
24812481
"""Merge adjacent sublists if combined length <= max_len, without splitting sublists."""
2482-
merged: List[List[int]] = []
2483-
buffer: List[int] = []
2482+
merged: List[List[TipSpot]] = []
2483+
buffer: List[TipSpot] = []
24842484

24852485
for sublist in lists:
24862486
if len(sublist) == 0:
@@ -2499,8 +2499,8 @@ def merge_sublists(lists: List[List[int]], max_len: int) -> List[List[int]]:
24992499
return merged
25002500

25012501
def divide_list_into_chunks(
2502-
list_l: List[Any], chunk_size: int
2503-
) -> Generator[List[Any], None, None]:
2502+
list_l: List[TipSpot], chunk_size: int
2503+
) -> Generator[List[TipSpot], None, None]:
25042504
"""Divides a list into smaller chunks of a specified size.
25052505
25062506
Parameters:
@@ -2523,7 +2523,7 @@ def divide_list_into_chunks(
25232523
continue # ignore non-partially-filled tip_racks
25242524

25252525
tipspots_w_tips = [
2526-
tip_spot for has_tip, tip_spot in zip(tip_status, tip_rack.children) if has_tip
2526+
tip_spot for has_tip, tip_spot in zip(tip_status, tip_rack.get_all_items()) if has_tip
25272527
]
25282528

25292529
# Identify model by hashed unique physical characteristics
@@ -2547,7 +2547,7 @@ def divide_list_into_chunks(
25472547
for model, rack_list in clusters_by_model.items():
25482548
print(f"Consolidating: - {', '.join([rack.name for rack, _ in rack_list])}")
25492549

2550-
all_tip_spots_list = [tip_spot for tip_rack, _ in rack_list for tip_spot in tip_rack.children]
2550+
all_tip_spots_list = [tip_spot for tip_rack, _ in rack_list for tip_spot in tip_rack.get_all_items()]
25512551

25522552
# 1: Record current tip state
25532553
current_tip_presence_list = [tip_spot.has_tip() for tip_spot in all_tip_spots_list]
@@ -2575,14 +2575,16 @@ def divide_list_into_chunks(
25752575
continue
25762576

25772577
# 4: Cluster target tip_spots by BOTH parent tip_rack & x-coordinate
2578-
sorted_tip_spots = sorted(
2579-
all_target_tip_spots, key=lambda tip: (tip.parent.name, round(tip.location.x, 3))
2580-
)
2578+
def key_for_tip_spot(tip_spot: TipSpot) -> Tuple[str, float]:
2579+
"""Key function to sort tip spots by parent name and x-coordinate."""
2580+
assert tip_spot.parent is not None and tip_spot.location is not None
2581+
return (tip_spot.parent.name, round(tip_spot.location.x, 3))
2582+
sorted_tip_spots = sorted(all_target_tip_spots, key=key_for_tip_spot)
25812583

25822584
target_tip_clusters_by_parent_x: Dict[Tuple[str, float], List[TipSpot]] = {}
25832585

25842586
for tip_spot in sorted_tip_spots:
2585-
key = (tip_spot.parent.name, round(tip_spot.location.x, 3))
2587+
key = key_for_tip_spot(tip_spot)
25862588
if key not in target_tip_clusters_by_parent_x:
25872589
target_tip_clusters_by_parent_x[key] = []
25882590
target_tip_clusters_by_parent_x[key].append(tip_spot)
@@ -2605,7 +2607,7 @@ def divide_list_into_chunks(
26052607
# by aggregating drop columns i.e. same drop column should not be visited twice!
26062608
if num_channels_available >= 8: # physical constraint of tip_rack's having 8 rows
26072609
merged_target_tip_clusters = merge_sublists(
2608-
target_tip_clusters_by_parent_x.values(), max_len=8
2610+
list(target_tip_clusters_by_parent_x.values()), max_len=8
26092611
)
26102612
else: # by chunking drop tip_spots list into size of available channels
26112613
merged_target_tip_clusters = list(

0 commit comments

Comments
 (0)