pfc_execute_code
Execute Python code in the PFC model to query state, create plots, or inspect variables, returning output immediately without tracking or cancellation.
Instructions
Execute Python code synchronously in the running PFC process.
Returns stdout and an optional result variable immediately. Code runs in the PFC main thread; side effects persist.
Scheduling: This tool remains available whether PFC is cycling or idle — you can query model state while a task is running.
Environment: PFC embedded Python 3.6.
Typical uses:
Query model state: ball/wall/contact counts, current cycle
Create and export plots: itasca.command('plot ...')
Read or set properties, inspect variables
Development and REPL-style testing
Unlike pfc_execute_task, this tool is fire-and-return: the response contains the full output. It is NOT tracked by pfc_list_tasks and cannot be interrupted or polled.
WARNING: Avoid blocking calls (model.solve with many cycles, long loops). They block the PFC main thread until completion or timeout, and cannot be cancelled. Use pfc_execute_task for anything that may run longer than a few seconds.
WARNING: This code shares the Python namespace with any running task. Avoid overwriting variables the task depends on (e.g. the callback function or simulation objects). Use unique names for throwaway variables to prevent conflicts.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Python code to execute in PFC user console | |
| timeout | No | Console execution timeout in seconds |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||