Writing Python for Revolution
This page describes Revolution release 4.0.0.
On this page
Hi, I'm Revo
Ask me anything about Revolution. My answers link the pages they come from.
Python runs in a schedule as a step:
Run Python holds its code in the step, and
Run Python Script runs a saved script.
Either way the code drives the run through revo, a library generated for your system. It has one
function per schedule operation, option classes for named options such as stores and locations, a
method for each device command under revo.devices, and revo.parameters for the schedule’s
parameters (see Schedule parameters in Python).
The names on this page are examples. Your system’s own operation functions, option classes and device commands come from its devices, so take the real names from the editor’s completions.
A revo call is a real step
Section titled “A revo call is a real step”Each revo call runs its operation as a real step on the schedule thread that is running the Python
block, with the normal operator recovery.
The call returns None, except a device command shown -> Any, which returns the JSON value the
command gives back (None in fast simulation). Other results are read back through state, usually
revo.parameters. For a Hamilton Venus device in Python SDK mode, the device’s sdk_client method
gives the script the device’s SDK session (see Drive a Hamilton Venus device).
Handle a failed operation
Section titled “Handle a failed operation”When an operation fails and the operator chooses to fail it, the call raises revo.OperationError
with the controller’s error text, and the block can catch it. An abort raises BlockInterrupted, a
BaseException, in the block. except Exception: does not catch it and the block ends. A bare
except: or except BaseException: does catch it, and the block then keeps running, so re-raise it
or do not catch it. A block that fails as a whole offers no Retry.
import revo
def main() -> None: try: revo.seal_plate(temperature=175) except revo.OperationError as error: print(f"Sealing failed and the operator failed it: {error}") return print("Sealed.")
if __name__ == "__main__": main()Report progress and read a failure
Section titled “Report progress and read a failure”What a block prints is kept with each run of its step, and the operator is not shown it. For a Run Python step, open Runs of this step and their output under the step’s Code in the schedule editor. For a Run Python Script step, open the script’s Executions in Python Scripts.
revo.log_message(text) raises a notification for the operator while the block runs. It is the
Log Message step run from Python, so it takes
the same message type: revo.log_message(text, message_type="Warning") raises a warning, and
message_type="Error" fails the call. Use it for anything the operator should see during the run.
When a block fails, its error notification names the Python exception, and the notification’s details hold the Python traceback, with the line of the block that failed.
import revo
revo.log_message("Sealing the plate.")revo.seal_plate(temperature=175)Pass a named option
Section titled “Pass a named option”Option classes subclass str. Pass a member by its Python name, or call the class with the
option’s real name: both stand for the same option, so an option the class does not list is still
passed by its real name.
import revo
by_member = revo.Store.Hotel_1by_real_name = revo.Store("Hotel 1")assert by_member == by_real_name
revo.store_labware(store=by_real_name)Run a device command
Section titled “Run a device command”A device command is a method under revo.devices, for example
revo.devices.Sealer.set_temperature(temperature=175). A command that is not surfaced as a method
still runs through revo.device_operation(device, command, **arguments): device is the device’s
real name, command is the command’s name, and each keyword argument sets the driver argument of
that name.
A device command does not claim its device, just as a Device Operation step does not, so the thread’s events show no Claim for it. To keep other threads off the device while a block uses it, put the Python block and the other threads’ steps that use the device in Mutex Sequences with the same name.
import revo
revo.device_operation("Sealer 1", "SetTemperature", temperature=175)Set a plate’s barcode
Section titled “Set a plate’s barcode”revo.set_labware_barcode(object_name, barcode) runs the
Set Labware Barcode step: it gives labware the
thread holds a barcode, named by its labware name. A barcode the step refuses fails the call as any
failed operation does. To read a barcode into a schedule parameter, use
revo.get_labware_barcode(object_name, parameter_name), the
Get Labware Barcode step.
import revo
revo.set_labware_barcode(revo.Labware("Assay plate"), "AP-000123")Drive a Hamilton Venus device
Section titled “Drive a Hamilton Venus device”A Hamilton Venus device in Python SDK mode keeps a session of the Hamilton Venus Python SDK open,
and the device’s class in revo.devices has an sdk_client method that lets a script use it.
sdk_client(client_type) returns a stand-in for the SDK client: client_type is the SDK’s client
class for the instrument, such as VantageClient or StarClient. The class only types the
stand-in, for completions; it is never created. Each method call runs on the device’s session as a
revo call and returns the SDK’s own result, or None in fast simulation. A failed call raises the
SDK’s own exception, or a VenusSdkError, which is a RuntimeError, when that exception can’t be
rebuilt in the script. Reading a result needs the SDK installed where the script runs.
from hamilton_venus import StarClientfrom revo.devices import Vantage
star = Vantage.sdk_client(StarClient)position = star.get_deck_position("FRAG_96_1")star.aspirate(...) # the SDK's own argumentsHere Vantage is the device’s class in revo.devices, named after the device.
- No robot reaches onto the deck while a call runs, but one may between two calls: a script claims no deck location. To keep robots off the deck for a whole protocol, put the Python block and the schedule steps that transfer onto or off the deck in a Mutex Sequence with the same name.
- Any SDK method can be called except those that start, stop or re-initialise the SDK client or the instrument, or replace its deck layout. That includes transports and adding or removing labware: labware a script moves with the SDK is not tracked by Revolution, and keeping Revolution’s record right is the script’s job.
- Each call may take up to the device’s Venus SDK Script Call Timeout (s). A call that runs out of time faults the device until it is initialised again. An error the SDK raises goes back to the script. It also faults the device, as the call may have stopped part-way through a move, unless the method only reads the deck (see Faults).
- The SDK session runs in the Python interpreter Revolution runs Python blocks with.
What a block shares
Section titled “What a block shares”- Every Python block on a schedule thread shares that thread’s namespace: a name one block sets is visible to the blocks after it on the same thread.
- Both Python steps can link a device (Drives a Device and Device). The block reads its name
as
revo.DEVICE_NAME, andrevo.DEVICE_SIMULATEDis true when that device is simulated or the system is in Simulation mode. The device is not claimed for the block. - Planning a schedule never runs the Python: the step takes its Simulation Duration, so set it to the code’s real running time.