Skip to content

Control simulation steps #8

Description

@lukavdplas

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?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    pyactr-modelRelated to the pyactr model itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions