# Writing robot agnostic methods#

This document describes best practices for writing methods that are agnostic to the robot backend.

This is a work in progress. Please contribute!

## Keeping the layout separate from the protocol#

It is recommended to keep the layout of the deck separate from the protocol. This allows you to easily change the layout of the deck without having to change the protocol.

from pylabrobot.liquid_handling import LiquidHandler, STAR
from pylabrobot.resources import Deck, TipRack, Plate

# Write a method that creates a deck and defines its layout.
def make_deck() -> Deck:
deck = Deck()

deck.assign_child_resource()
deck.assign_child_resource()

return deck

# Instantiate the liquid handler using a deck and backend.
deck = make_deck()
backend = STAR()
lh = LiquidHandler(backend=backend, deck=deck)

# Get references to the resources you need. Use type hinting for autocompletion.
tip_rack: TipRack = lh.get_resource('tip_rack')
plate: Plate = lh.get_resource('plate')

# the protocol...
lh.pick_up_tip(tip_rack["A1"])


## Strictness checking#

Strictness checking is a feature that allows you to specify how strictly you want the LiquidHandler to enforce the protocol. The following levels are available:

You can set the strictness level for the entire protocol using pylabrobot.liquid_handling.strictness.set_strictness().

from pylabrobot.liquid_handling import Strictness, set_strictness

set_strictness(Strictness.IGNORE)
lh.pick_up_tips(my_tip_rack["A1"], illegal_argument=True) # will log on debug level

set_strictness(Strictness.WARN)
lh.pick_up_tips(my_tip_rack["A1"], illegal_argument=True) # will warn

set_strictness(Strictness.STRICT)
lh.pick_up_tips(my_tip_rack["A1"], illegal_argument=True) # will raise a TypeError