The simulation should be able to step through the model simulation, rather than just run all the code. This is necessary for the "debugger mode" we want to build.
This requires that we have control over the steps of the simulation. In the current version, the user provides a script that creates the model and runs it, and the app does not know or control what happens inside the script.
I think the most sensible option is to check the output value of the script. So the user would write a script like:
model = actr.ACTRModel()
# model configuration...
model
When we run this script, model will be returned as the output of runPythonAsync. We can check that this is an ACTRModel instance. From there, it would be fairly straightforward to create model.simulation() and call simulation.step().
Alternative, the user could write a complete script like this:
model = actr.ACTRModel()
# model configuration...
sim = model.simulation()
sim.run()
Which would be run without the simulation GUI.
An alternative, more out-there solution is to allow users to write scripts like the second one, but somehow control the execution flow through Javascript. (More like an actual debugger.)
You might be able to achieve this by creating a wrapper around pyactr that handles the interaction with Javascript. So to the user, if appears as if they're just using pyactr, but they're really working with a custom subclass.
For instance, the script below would add some calls to inform the Javascript environment about the model being created and stepped through. (ACTRModels don't have a step() method, but you get the idea.)
from pyactr import ACTRModel as _ACTRModel
class ACTRModel(_ACTRModel):
def __init__(self, *args, **kwargs):
simulation_env.register_model(self)
super(*args, **kwargs)
def step(self, *args, **kwargs):
simulation_env.register_step(self)
super(*args, **kwargs)
This script is pretty straightforward, but if we also want to control execution flow from the GUI, this would be a lot more complicated. In the step() method, you would need to wait for a message from the GUI that you can continue. (Python scripts already run in a separate thread, so I think this is doable?)
The simulation should be able to step through the model simulation, rather than just run all the code. This is necessary for the "debugger mode" we want to build.
This requires that we have control over the steps of the simulation. In the current version, the user provides a script that creates the model and runs it, and the app does not know or control what happens inside the script.
I think the most sensible option is to check the output value of the script. So the user would write a script like:
When we run this script,
modelwill be returned as the output ofrunPythonAsync. We can check that this is anACTRModelinstance. From there, it would be fairly straightforward to createmodel.simulation()and callsimulation.step().Alternative, the user could write a complete script like this:
Which would be run without the simulation GUI.
An alternative, more out-there solution is to allow users to write scripts like the second one, but somehow control the execution flow through Javascript. (More like an actual debugger.)
You might be able to achieve this by creating a wrapper around pyactr that handles the interaction with Javascript. So to the user, if appears as if they're just using pyactr, but they're really working with a custom subclass.
For instance, the script below would add some calls to inform the Javascript environment about the model being created and stepped through. (ACTRModels don't have a
step()method, but you get the idea.)This script is pretty straightforward, but if we also want to control execution flow from the GUI, this would be a lot more complicated. In the
step()method, you would need to wait for a message from the GUI that you can continue. (Python scripts already run in a separate thread, so I think this is doable?)