I’m currently hoping to run opentrons_simulate to validate protocol .py files without having to use the Opentrons App so that my workflow is faster. Also, because currently the protocol analysis in the app is giving me an OutOfTipsError (but before I add my CSV, which only specifies a very small amount of work, such that it should definitely not run out of tips).
However, I’m not sure how to run simulations with protocols that need a CSV or custom labware! Has anyone dealt with this issue before?
Install the opentrons python package and run opentrons_simulate my_protocol.py . Keep in mind you probably can’t load the csv at runtime since the actually script runs from the micro-controller in the Opentrons. (unless the csv is actually there).
Also, I have a branch in https://galago.bio/ that implements simulation fully from Galago’s code editor gui (a vscode web clone). Let me know if you want to try it out and I can try and push it to main soon. The benefit of it is that you can inject runtime variables from Galago, these get evaluated and injected into the final python script sent to the opentrons api.
I don’t know about CSVs, but I do simulate with custom labware
I use a linux virtual desktop (WSL) for this and a conda environment.
Make sure the opentrons package is installed in the conda environment
Then in your python robot script I put it like this:
import json
simulate = True
if simulate:
with open(path/custom_labwaredef.json) as labware_file:
labware = json.load(labware_file)
labware_variable = protocol.load_labware_from_definition(labware, deck position, name)
else:
labware_variable = protocol.load_labware(labware, deck position, name)
Then in WSL
opentrons_simulate -L path/to/labwaredefinitions path/to/protocol.py
I think for custom labware the WSL was essential, because windows did not want to work with µL signs, which are in the json files
You can use the -L argument when using Opentrons simulator to add custom labware.
Csv is a little trickier. Here is a method we use, but internally some people have their own programs to build analysis files without having to open the Opentrons app.
def csv_parse(location : str):
"""
This function mimics the Opentrons CSV Parser format.
It reads the CSV file and returns the file contents and the CSVParameter object.
file_csv : Raw file contents
content_csv : CSVParameter object, can be further parsed using parse_as_csv() method and contents method.
"""
from opentrons.protocols.api_support.types import APIVersion
from opentrons import protocol_api
with open(location, "rb") as file:
file_csv = file.read()
content_csv = protocol_api.CSVParameter(contents=file_csv, api_version=APIVersion(2, 28))
return file_csv, content_csv
def run(ctx: protocol_api.ProtocolContext):
#Parameters
TESTING = True
if TESTING:
in_file = '/path/to/file' #Path to the input file
raw_data, filetype = csv_parse(in_file)
sample_csv = filetype.parse_as_csv()
else:
sample_csv = params.sample_csv.parse_as_csv()