Skip to content

error handling: option 1 (PoC) #507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed

error handling: option 1 (PoC) #507

wants to merge 3 commits into from

Conversation

rickwierenga
Copy link
Member

we've been thinking about ways of adding error handling. this is one possible approach.

it might be easier to understand and play around with the toy example here: https://gist.github.com/rickwierenga/f53281dfcc4bcb5b3e92a4fa5d15163e. it shows the thought

one downside is that with real PLR (not the toy above), writing real error handlers gets quite involved. see the example in this PR.

Trying it out

Here's a simple reproducible example

# Simple test backend based on LiquidHandlerChatterboxBackend
# that will raise an error for tip spot A1
from pylabrobot.liquid_handling.backends.chatterbox import LiquidHandlerChatterboxBackend
class AnnoyBackend(LiquidHandlerChatterboxBackend):
  async def pick_up_tips(self, ops, use_channels, **backend_kwargs):
    if ops[0].resource.get_identifier() == "A1":
      raise ChannelizedError(
        {0: "A1 is not supported"},
      )
    await super().pick_up_tips(ops, use_channels, **backend_kwargs)

# LH setup
from pylabrobot.liquid_handling import LiquidHandler
from pylabrobot.resources.hamilton import STARDeck
backend = AnnoyBackend()
lh = LiquidHandler(backend=backend, deck=STARDeck())
await lh.setup()

# setting up deck
from pylabrobot.resources import TIP_CAR_480_A00, HTF
tip_car = TIP_CAR_480_A00("tip_car")
tip_car[0] = tip_rack = HTF("tips")
lh.deck.assign_child_resource(tip_car, rails=1)

# setting an error handler on LH and picking up a tip from A1
from pylabrobot.liquid_handling.error_handlers import try_next_tip_spot
with lh.on_fail(ChannelizedError, try_next_tip_spot(iter(tip_rack["B1:H1"]))):
  await lh.pick_up_tips(tip_rack["A1"])

output:

Handling error ChannelizedError(errors={0: 'A1 is not supported'}, ) with: <function try_next_tip_spot.<locals>.handler at 0x106ce91b0>
Retrying with tip spots: [TipSpot(name=tips_tipspot_0_1, location=Coordinate(007.200, 059.300, -83.500), size_x=9.0, size_y=9.0, size_z=0, category=tip_spot)] and use channels: [0]
Picking up tips:
pip#  resource             offset           tip type     max volume (µL)  fitting depth (mm)   tip length (mm)  filter    
  p0: tips_tipspot_0_1     0,0,0            HamiltonTip  1065             8                    95.1             Yes     

@rickwierenga rickwierenga changed the title PoC: error handling error handling: option 1 (PoC) May 30, 2025
@rickwierenga
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant