Run SIMO Condition

Run a SIMO condition from a task file.

Demonstrates importing a SIMA task file (stask) and running a specific condition using the SIMA Runtime Engine (SRE).

Requirements:
  • Environment variable SRE_EXE which points to the SIMA executable

  • Input file: ‘input/simo/simo.stask’

Example

>>> python run_simo_condition.py
main()[source]

Run a SIMO simulation condition using SRE.

Imports a predefined SIMA task file and runs a specific condition. Clears the workspace before running for a clean execution environment.

Source Code

run_simo_condition.py
 1"""Run a SIMO condition from a task file.
 2
 3Demonstrates importing a SIMA task file (stask) and running a specific 
 4condition using the SIMA Runtime Engine (SRE).
 5
 6Requirements:
 7    - Environment variable `SRE_EXE` which points to the SIMA executable
 8    - Input file: 'input/simo/simo.stask'
 9
10Example:
11    >>> python run_simo_condition.py
12"""
13import os
14import shutil
15from pathlib import Path
16
17from simapy.sre import SIMA
18
19
20def main():
21    """Run a SIMO simulation condition using SRE.
22    
23    Imports a predefined SIMA task file and runs a specific condition.
24    Clears the workspace before running for a clean execution environment.
25    """
26    ws = Path("output/simo/condition")
27    if ws.exists():
28        shutil.rmtree(ws, ignore_errors=True)
29    os.makedirs(ws, exist_ok=True)
30
31    stask = Path("input/simo/simo.stask")
32
33    commands = []
34    commands.append("--import")
35    commands.append("file=" + str(stask.absolute()))
36    commands.append("--condition")
37    commands.append("task=BouncingBalls")
38    commands.append("condition=conditionSet")
39    commands.append("runType=dynamic")
40
41    # Requires that the environment is set, but an alternative path may be given
42    exe = os.getenv("SRE_EXE")
43    sima = SIMA(exe=exe)
44    sima.run(ws, commands)
45    
46    print(f"SIMO condition executed successfully. Results in {ws}")
47
48
49if __name__ == "__main__":
50    main()