Skip to content

Commit 972bb86

Browse files
authored
remove resources assignment callbacks from lh (#704)
1 parent 17b613f commit 972bb86

File tree

7 files changed

+4
-94
lines changed

7 files changed

+4
-94
lines changed

pylabrobot/liquid_handling/backends/backend.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
SingleChannelDispense,
2020
)
2121
from pylabrobot.machines.backend import MachineBackend
22-
from pylabrobot.resources import Deck, Resource, Tip
22+
from pylabrobot.resources import Deck, Tip
2323
from pylabrobot.resources.tip_tracker import TipTracker
2424

2525

@@ -70,24 +70,6 @@ async def setup(self):
7070
"""Set up the robot. This method should be called before any other method is called."""
7171
assert self._deck is not None, "Deck not set"
7272

73-
async def assigned_resource_callback(self, resource: Resource):
74-
"""Called when a new resource was assigned to the robot.
75-
76-
This callback will also be called immediately after the setup method has been called for any
77-
resources that were assigned to the robot before it was set up. The first resource will always
78-
be the deck itself.
79-
80-
Args:
81-
resource: The resource that was assigned to the robot.
82-
"""
83-
84-
async def unassigned_resource_callback(self, name: str):
85-
"""Called when a resource is unassigned from the robot.
86-
87-
Args:
88-
resource: The name of the resource that was unassigned from the robot.
89-
"""
90-
9173
@property
9274
@abstractmethod
9375
def num_channels(self) -> int:

pylabrobot/liquid_handling/backends/chatterbox.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
SingleChannelAspiration,
1919
SingleChannelDispense,
2020
)
21-
from pylabrobot.resources import Resource, Tip
21+
from pylabrobot.resources import Tip
2222

2323

2424
class LiquidHandlerChatterboxBackend(LiquidHandlerBackend):
@@ -58,12 +58,6 @@ def serialize(self) -> dict:
5858
def num_channels(self) -> int:
5959
return self._num_channels
6060

61-
async def assigned_resource_callback(self, resource: Resource):
62-
print(f"Resource {resource.name} was assigned to the liquid handler.")
63-
64-
async def unassigned_resource_callback(self, name: str):
65-
print(f"Resource {name} was unassigned from the liquid handler.")
66-
6761
async def pick_up_tips(self, ops: List[Pickup], use_channels: List[int], **backend_kwargs):
6862
print("Picking up tips:")
6963
header = (

pylabrobot/liquid_handling/backends/saver_backend.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,6 @@ def serialize(self) -> dict:
3131
async def send_command(self, command: str, data: Dict[str, Any]):
3232
self.commands_received.append({"command": command, "data": data})
3333

34-
async def assigned_resource_callback(self, *args, **kwargs):
35-
self.commands_received.append(
36-
{
37-
"command": "assigned_resource_callback",
38-
"args": args,
39-
"kwargs": kwargs,
40-
}
41-
)
42-
43-
async def unassigned_resource_callback(self, *args, **kwargs):
44-
self.commands_received.append(
45-
{
46-
"command": "unassigned_resource_callback",
47-
"args": args,
48-
"kwargs": kwargs,
49-
}
50-
)
51-
5234
async def pick_up_tips(self, *args, **kwargs):
5335
self.commands_received.append({"command": "pick_up_tips", "args": args, "kwargs": kwargs})
5436

pylabrobot/liquid_handling/backends/serializing_backend.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
SingleChannelAspiration,
2121
SingleChannelDispense,
2222
)
23-
from pylabrobot.resources import Resource, Tip
23+
from pylabrobot.resources import Tip
2424
from pylabrobot.serializer import serialize
2525

2626
if sys.version_info >= (3, 8):
@@ -57,18 +57,6 @@ async def stop(self):
5757
def serialize(self) -> dict:
5858
return {**super().serialize(), "num_channels": self.num_channels}
5959

60-
async def assigned_resource_callback(self, resource: Resource):
61-
await self.send_command(
62-
command="resource_assigned",
63-
data={
64-
"resource": resource.serialize(),
65-
"parent_name": (resource.parent.name if resource.parent else None),
66-
},
67-
)
68-
69-
async def unassigned_resource_callback(self, name: str):
70-
await self.send_command(command="resource_unassigned", data={"resource_name": name})
71-
7260
async def pick_up_tips(self, ops: List[Pickup], use_channels: List[int]):
7361
serialized = [
7462
{

pylabrobot/liquid_handling/backends/serializing_backend_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ async def test_dispense96(self):
221221
async def test_move(self):
222222
to = Coordinate(600, 200, 200)
223223
await self.lh.move_plate(self.plate, to=to)
224-
self.assertEqual(len(self.backend.sent_commands), 4) # move + resource unassign + assign
224+
self.assertEqual(len(self.backend.sent_commands), 2) # pickup and drop
225225
self.assertEqual(
226226
self.backend.get_first_data_for_command("pick_up_resource"),
227227
{

pylabrobot/liquid_handling/backends/websocket.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from pylabrobot.liquid_handling.backends.serializing_backend import (
2121
SerializingBackend,
2222
)
23-
from pylabrobot.resources import Resource
2423

2524
if TYPE_CHECKING:
2625
import websockets.legacy
@@ -172,24 +171,6 @@ def wait_for_connection(self):
172171
while not self.has_connection():
173172
time.sleep(0.1)
174173

175-
async def assigned_resource_callback(self, resource: Resource):
176-
# override SerializingBackend so we don't wait for a response
177-
await self.send_command(
178-
command="resource_assigned",
179-
data={
180-
"resource": resource.serialize(),
181-
"parent_name": (resource.parent.name if resource.parent else None),
182-
},
183-
wait_for_response=False,
184-
)
185-
186-
async def unassigned_resource_callback(self, name: str):
187-
# override SerializingBackend so we don't wait for a response
188-
await self.send_command(
189-
command="resource_unassigned",
190-
data={"resource_name": name, "wait_for_response": False},
191-
)
192-
193174
async def send_command(
194175
self,
195176
command: str,

pylabrobot/liquid_handling/liquid_handler.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,6 @@ def __init__(
147147
self.backend: LiquidHandlerBackend = backend # fix type
148148

149149
self.deck = deck
150-
# register callbacks for sending resource assignment/unassignment to backend
151-
self.deck.register_did_assign_resource_callback(self._send_assigned_resource_to_backend)
152-
self.deck.register_did_unassign_resource_callback(self._send_unassigned_resource_to_backend)
153150

154151
self.head: Dict[int, TipTracker] = {}
155152
self.head96: Dict[int, TipTracker] = {}
@@ -180,10 +177,6 @@ async def setup(self, **backend_kwargs):
180177
self.head = {c: TipTracker(thing=f"Channel {c}") for c in range(self.backend.num_channels)}
181178
self.head96 = {c: TipTracker(thing=f"Channel {c}") for c in range(96)}
182179

183-
self._send_assigned_resource_to_backend(self.deck)
184-
for resource in self.deck.children:
185-
self._send_assigned_resource_to_backend(resource)
186-
187180
self._resource_pickup = None
188181

189182
def serialize_state(self) -> Dict[str, Any]:
@@ -239,16 +232,6 @@ def callback(*args, **kwargs):
239232
t.start()
240233
t.join()
241234

242-
def _send_assigned_resource_to_backend(self, resource: Resource):
243-
"""This method is called when a resource is assigned to the deck, and passes this information
244-
to the backend."""
245-
self._run_async_in_thread(self.backend.assigned_resource_callback, resource)
246-
247-
def _send_unassigned_resource_to_backend(self, resource: Resource):
248-
"""This method is called when a resource is unassigned from the deck, and passes this
249-
information to the backend."""
250-
self._run_async_in_thread(self.backend.unassigned_resource_callback, resource.name)
251-
252235
def summary(self):
253236
"""Prints a string summary of the deck layout."""
254237

0 commit comments

Comments
 (0)