Executing a Python script during a simulation

26 views
Skip to first unread message

Randy Heiland

unread,
Jul 2, 2024, 4:28:43 PM7/2/24
to Morpheus users
Are there any examples that demo how one could execute a Python script *during* a simulation, using some sort of trigger to determine when it is invoked? I saw this page: https://morpheus.gitlab.io/courses/drawing-cell-genealogies/executing-external-scripts/, but was hoping for a bit more detail.

If the answer is "yes", my next question will be: where are the docs for the Python API?

thanks, Randy

Lutz Brusch

unread,
Jul 12, 2024, 10:42:24 AM7/12/24
to Morpheus users
Hi Randy,

yes, the Analysis/External plugin can start a Python script repeatedly *during* a simulation. For an example model (starting awk scripts repeatedly) please see https://identifiers.org/morpheus/M0007.

Please also see the GUI's Documentation panel at MorpheusML/Analysis/External, this has three Python examples and offers to "execute shell command periodically or at the end of simulation, e.g. to perform analysis using external command line tools...Use "%" (percentage) to provide global symbols as arguments in the script. For instance the substring "%time" will be replaced with the symbol "time", the current simulation time...The attribute "detach" lets you run the process in the background while continuing simulation. Note that "timeout" with default 30sec is the maximum time the command may run after the simulation finished." 
The attribute "time-step" controls when the script is started and you may test inside the script if other conditions for its execution are fulfilled.

To send more simulation data (than few global symbols) to the script, you need to first write the data to file with a Logger. The script could then run at the same time step after the Logger (as in https://identifiers.org/morpheus/M0007). A proper Python API and documentation thereof remain work in progress.

Best,
Lutz
Reply all
Reply to author
Forward
0 new messages