Seeing the Order of Process, Task and Module Execution

Now that you have learned how to add and prioritize processes with task lists, as well as assign Basilisk modules to the task for an ordered execution, it is nice to be able to see how the simulation is setup. The SimulationBaseClass defines a method ShowExecutionOrder which will print to the terminal window the process names and priorties as they are setup to be executed. For each process you will see the order with which the tasks will be called, and the order of task modules that will be executed. This is very handy to quickly validate that the simulation is setup as desired.

The sample script below creates two processes called dynamicsProcess and fswProcess. Note that because the fswProcess has a higher priority, it is executed first even though it is added second. The same two modules are added to a range of tasks in different orders and using different priorities.

 2from Basilisk.utilities import SimulationBaseClass
 3from Basilisk.utilities import macros
 4from Basilisk.moduleTemplates import cModuleTemplate
 6def run():
 7    """
 8    Controlling the simulation time
 9    """
11    #  Create a sim module as an empty container
12    scSim = SimulationBaseClass.SimBaseClass()
14    #  create the simulation process
15    dynProcess = scSim.CreateNewProcess("dynamicsProcess")
16    fswProcess = scSim.CreateNewProcess("fswProcess", 10)
18    # create the dynamics task and specify the integration update time
19    fswProcess.addTask(scSim.CreateNewTask("fswTask1", macros.sec2nano(1.)))
20    fswProcess.addTask(scSim.CreateNewTask("fswTask2", macros.sec2nano(2.)))
21    fswProcess.addTask(scSim.CreateNewTask("fswTask3", macros.sec2nano(3.)), 10)
22    dynProcess.addTask(scSim.CreateNewTask("dynamicsTask1", macros.sec2nano(1.)))
23    dynProcess.addTask(scSim.CreateNewTask("dynamicsTask2", macros.sec2nano(5.)), 10)
24    dynProcess.addTask(scSim.CreateNewTask("dynamicsTask3", macros.sec2nano(10.)))
26    # create modules
27    mod1 = cModuleTemplate.cModuleTemplateConfig()
28    mod1Wrap = scSim.setModelDataWrap(mod1)
29    mod1Wrap.ModelTag = "cModule1"
31    mod2 = cModuleTemplate.cModuleTemplateConfig()
32    mod2Wrap = scSim.setModelDataWrap(mod2)
33    mod2Wrap.ModelTag = "cModule2"
35    # add modules to various task lists
36    scSim.AddModelToTask("dynamicsTask1", mod1Wrap, mod1, 4)
37    scSim.AddModelToTask("dynamicsTask1", mod2Wrap, mod2, 5)
38    scSim.AddModelToTask("dynamicsTask2", mod2Wrap, mod2)
39    scSim.AddModelToTask("dynamicsTask2", mod1Wrap, mod1)
40    scSim.AddModelToTask("dynamicsTask3", mod1Wrap, mod1)
41    scSim.AddModelToTask("dynamicsTask3", mod2Wrap, mod2)
43    scSim.AddModelToTask("fswTask1", mod1Wrap, mod1)
44    scSim.AddModelToTask("fswTask1", mod2Wrap, mod2, 2)
45    scSim.AddModelToTask("fswTask2", mod2Wrap, mod2)
46    scSim.AddModelToTask("fswTask2", mod1Wrap, mod1)
47    scSim.AddModelToTask("fswTask3", mod1Wrap, mod1)
48    scSim.AddModelToTask("fswTask3", mod2Wrap, mod2)
50    # print to the terminal window the execution order of the processes, task lists and modules
51    scSim.ShowExecutionOrder()
53    # uncomment this code to show the execution order figure and save it off
54    # fig = scSim.ShowExecutionFigure(False)
55    # fig.savefig("qs-bsk-2b-order.svg", transparent=True, bbox_inches = 'tight', pad_inches = 0)
57    return
60if __name__ == "__main__":
61    run()

To execute the code, this script doesn’t run the simulation itself. Rather, the simulation is setup and configured, and then the ShowExecutionOrder is called:


If you execute this python code you should see the following terminal output:

$ python3
Process Name: fswProcess , priority: 10
Task Name: fswTask3, priority: 10, TaskPeriod: 3.0s
ModuleTag: cModule1, priority: -1
ModuleTag: cModule2, priority: -1
Task Name: fswTask1, priority: -1, TaskPeriod: 1.0s
ModuleTag: cModule2, priority: 2
ModuleTag: cModule1, priority: -1
Task Name: fswTask2, priority: -1, TaskPeriod: 2.0s
ModuleTag: cModule2, priority: -1
ModuleTag: cModule1, priority: -1

Process Name: dynamicsProcess , priority: -1
Task Name: dynamicsTask2, priority: 10, TaskPeriod: 5.0s
ModuleTag: cModule2, priority: -1
ModuleTag: cModule1, priority: -1
Task Name: dynamicsTask1, priority: -1, TaskPeriod: 1.0s
ModuleTag: cModule2, priority: 5
ModuleTag: cModule1, priority: 4
Task Name: dynamicsTask3, priority: -1, TaskPeriod: 10.0s
ModuleTag: cModule1, priority: -1
ModuleTag: cModule2, priority: -1

The method ShowExecutionFigure(True) will perform the same Basilisk process, task and module order extraction process, but display is as a figure. The method returns a copy of the figure so it can be used in auto-documentation features or saved off for future use. For example, adding this command to this sample script will yields the following figure.