Skip to content

Commit bfe41ef

Browse files
committed
type
1 parent 5db59a5 commit bfe41ef

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

pylabrobot/liquid_handling/liquid_handler.py

Lines changed: 17 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,9 @@ 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 = [
2551+
tip_spot for tip_rack, _ in rack_list for tip_spot in tip_rack.get_all_items()
2552+
]
25512553

25522554
# 1: Record current tip state
25532555
current_tip_presence_list = [tip_spot.has_tip() for tip_spot in all_tip_spots_list]
@@ -2575,14 +2577,17 @@ def divide_list_into_chunks(
25752577
continue
25762578

25772579
# 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-
)
2580+
def key_for_tip_spot(tip_spot: TipSpot) -> Tuple[str, float]:
2581+
"""Key function to sort tip spots by parent name and x-coordinate."""
2582+
assert tip_spot.parent is not None and tip_spot.location is not None
2583+
return (tip_spot.parent.name, round(tip_spot.location.x, 3))
2584+
2585+
sorted_tip_spots = sorted(all_target_tip_spots, key=key_for_tip_spot)
25812586

25822587
target_tip_clusters_by_parent_x: Dict[Tuple[str, float], List[TipSpot]] = {}
25832588

25842589
for tip_spot in sorted_tip_spots:
2585-
key = (tip_spot.parent.name, round(tip_spot.location.x, 3))
2590+
key = key_for_tip_spot(tip_spot)
25862591
if key not in target_tip_clusters_by_parent_x:
25872592
target_tip_clusters_by_parent_x[key] = []
25882593
target_tip_clusters_by_parent_x[key].append(tip_spot)
@@ -2605,7 +2610,7 @@ def divide_list_into_chunks(
26052610
# by aggregating drop columns i.e. same drop column should not be visited twice!
26062611
if num_channels_available >= 8: # physical constraint of tip_rack's having 8 rows
26072612
merged_target_tip_clusters = merge_sublists(
2608-
target_tip_clusters_by_parent_x.values(), max_len=8
2613+
list(target_tip_clusters_by_parent_x.values()), max_len=8
26092614
)
26102615
else: # by chunking drop tip_spots list into size of available channels
26112616
merged_target_tip_clusters = list(

0 commit comments

Comments
 (0)