Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple instances of a statechart reg #94

Closed
chansdad opened this issue Feb 21, 2020 · 4 comments
Closed

Multiple instances of a statechart reg #94

chansdad opened this issue Feb 21, 2020 · 4 comments
Labels

Comments

@chansdad
Copy link

chansdad commented Feb 21, 2020

I have question . In the documentation elevator or stop watch statecharts are explained. What is the upper limit for statecharts , ex , how many elevators can i create or how many stop watches can i create ? I really like the idea of YAML , and all the features , My use case is more like - creating multiple state machines , each maintaining its own state and able to interact with these state machines also would like to retain the current state between crashes and restarts. For instance , i want to create 1k elevators or 10k elevators and interact with each elevator . Any suggestions?

Thanks

@AlexandreDecan
Copy link
Owner

Hello,

There is no intrinsic limitation on the number of statecharts that Sismic can execute simultaneously. The only limitation will come from the performance of the machine.

To execute many statecharts at once, the easiest way is to store them in a list:

from sismic.io import import_from_yaml
from sismic.interpreter import Interpreter

statechart = import_from_yaml(filepath='elevator.yaml')
interpreters = [Interpreter(statechart) for i in range(10000)]

# Let's send the elevators to different floors
for i, interpreter in enumerate(interpreters):
    interpreter.queue('floorSelected', floor=i % 4)
    interpreter.execute()

# Let's check the current floor
print([i.context['current'] for i in interpreters])

.... this displays [ 0, 1, 2, 3, 0, 1, 2, 3, .....].

@AlexandreDecan
Copy link
Owner

AlexandreDecan commented Feb 22, 2020

also would like to retain the current state between crashes and restarts.

It depends on the complexity of your statecharts. Have a look at the following discussion: #89
More precisely: #89 (comment)

@chansdad
Copy link
Author

chansdad commented Feb 22, 2020

Thanks. This sure seems like something i can use. So my idea is to have multiple elevators running ..and then be able to interact with each elevator from a different program .. while maintaining the state.. also ftom the state chart seems like i retrive operation or event supported using api o Ex in the above example floorSelected is the event or operation. What about parameter type ? Floor selected event expects a parameter of type int. Can i get event parameter types for a event supported as well ? Or is it expected that i know this cause i created the statechart? I will give sismic a try sure it is an intetesting project.

@AlexandreDecan
Copy link
Owner

It is expected that you know these parameters (it should be part of the documented "API" of your statecharts), following Python's spirit. However, there is a way to retrieve the list of supported events for a given statechart with statechart.events_for. It reports about the event names that are used by the statechart, not about the parameters.

Have a look at the second part of https://sismic.readthedocs.io/en/latest/execution.html#using-interpreter for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants