Big update: PLR is now asynchronous

PyLabRobot is now asynchronous, based on Python’s asyncio. This will make the implementation of complex methods significantly easier.

Each operation can be awaited using await:

await lh.aspirate(...)

or

fut = lh.aspirate(...)
# do something else in between
await fut

In IPython/Jupyter Notebooks, you can use await directly.

In scripts, I recommend using asyncio.run():

import asyncio

async def my_method():
    await lh.aspirate(...)

asyncio.run(my_method())

One of the many neat features of asyncio is gather, which can be used to run two actions simultaneously:

async def pipetting_sequence():
  await lh.aspirate(...)
  await lh.dispense(...)

asyncio.gather([
  pr.read_absorbance(...),
  pipetting_sequence()
])

Depending on the model of robot, running two ‘active operations’ (such as aspirate/dispense) simultaneously might raise an error. This is the case on STAR. You can, however, aspirate while performing ‘passive operations’.

3 Likes

This is amazing! Congrats!

1 Like

This is great Rick, I was actually postponing writing the Klipper backend because it relies on asyncio. This greatly simplifies things.

A quick feedback on my experience with using-the-simulator.ipynb. Everything seems to work except for the following:

  • Cell 21: set_well_volumes is not awaitable, and it raises an error.
  • Cell 32: (tip_car[0].resource) is not awaitable, and a TypeError is also raised.
Bonus: unrelated to asyncio but possibly helpful.
  • The included screenshots seem outdated and led me to some minor confusion.
  • An effect of dropping tips is that they placed back into the tip racks: is this the expected behaviour?
  • The simulator looks a bit off, I’m using Chromium:

Amazing work!

2 Likes

This is great Rick, I was actually postponing writing the Klipper backend because it relies on asyncio. This greatly simplifies things.

Thank you! Great to hear!

  • Cell 21: set_well_volumes is not awaitable, and it raises an error.
  • Cell 32: (tip_car[0].resource) is not awaitable, and a TypeError is also raised

Fixed in fix simulator nb · PyLabRobot/pylabrobot@57c9f51 · GitHub.

The included screenshots seem outdated and led me to some minor confusion.

Fixed in update simulator screenshots · PyLabRobot/pylabrobot@965ee3b · GitHub.

An effect of dropping tips is that they placed back into the tip racks: is this the expected behaviour?

Yes. discard_tips is to permanently dispose of the tips (thinking about renaming this to dispose_tips).

The simulator looks a bit off, I’m using Chromium:

Fixed in fix hamilton star simulator layout · PyLabRobot/pylabrobot@8357907 · GitHub. (I should really figure out a way to add UI & unit tests to the simulator…)

Thanks a lot for reporting these!

1 Like