Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Inline Python Script

Table of contents

How libyt Loads Inline Python script and Runs Python Functions?

The inline Python script and the simulation executable should be placed in the same location. libyt imports inline Python script only once at initialization stage when calling yt_initialize.

Each MPI process runs the same Python script. The imported script will also serve as the namespace. All of our in situ Python analysis are done inside this namespace.

The namespace contains function objects in the script. We can use yt_run_Function and yt_run_FunctionArguments to call them during simulation process.

What Happens if the Python Function Crashed?

If libyt is compiled in normal mode, it is not fault-tolerant to Python, so the whole simulation will shut down.

Use interactive mode (-DINTERACTIVE_MODE=ON) or jupyter kernel mode (-DJUPYTER_KERNEL=ON) if we want our in situ Python analysis to be fault-tolerant.

Can I Update Python Functions Defined in the Script?

We can only update Python functions in interactive mode (-DINTERACTIVE_MODE=ON) or jupyter kernel mode (-DJUPYTER_KERNEL=ON).

Since every new added Python object is maintained inside inline Python script’s namespace, you can update a Python function by re-define the function again, so that the old function is overwritten. (See Interactive Python Prompt, Reloading Script, and Jupyter Notebook Access.)