Deck Layouts

Hi, I was wondering how it would be possible to build a deck layout in json, which I would then import into my code, so that carriers and other resources don’t need to be assigned directly in the method-specific file. I know that the example in the PyLabRobot github uses a .json file that is loaded in using:

deck = Deck.load_from_json_file(“myLayout.json”)

but I haven’t seen any documentation about what format the incoming .json file needs to follow, and what the required fields are. Can you please help shed some light on this? Thanks.

1 Like

Thanks for asking!

It is actually quite cumbersome to write the JSON data, and this feature primarily exists for different softwares to be interoperable. I would not recommend writing it by hand. See an example here:

How it works: the JSON consists of many dictionaries, one for each resource. By default each resource discards the type, parent_name, children and location keys and passes all other keys to the initializer of the resource defined in the type field. So when the type field is PlateCarrier, that initializer would be called. All resources defined in the children field are also deserialized, and assigned at their location to the parent resource. A resource subclass can override this behavior by overriding the deserialize method. See the highlighted line for the start of the base method definition: pylabrobot/ at af5fa9b11b4de426bf99b1e8a2bc279bc0aab833 · PyLabRobot/pylabrobot · GitHub

I would suggest doing either of the following:

  1. Defining your layout in a separate Python, and importing that file in your method.
  2. Do #1, but call .save("my_file.json") on the Deck at the end and loading that using load_from_json_file.

Your method may edit the imported layout, of course, so it can just serve as a base layout.

Also, let it be explicit that these methods also work on individual resources, like"specific_resource.json") in one file and my_resource = Resource.load("specific_resource.json") followed by parent_resource.assign_child_resource(my_resource , location=Coordinate(x, y, z)) in another.

Hope that helps!


Thank you, yes this does help! If I wanted to define my layout in a separate Python script, how would I go about doing that efficiently? Is there an example script that I could be pointed to?


This tutorial has an example: Basic liquid handling — PyLabRobot documentation. Also here: Writing robot agnostic methods — PyLabRobot documentation (the linked section). There should be nothing particularly special about doing it in two files versus one.

Please let me know if anything can be improved!