-
Notifications
You must be signed in to change notification settings - Fork 7
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 State Machine Support #15
Comments
Hello @danieljlevine, are you talking about different state machines (with individual transitions and states) or models (stateful instances using the same states/transitions)?
You can pass The frontend code is pretty naive. It will connect to a websocket (at
Right now, the CSS class |
Additionally,
|
I suppose what I'm requesting is the display of several instances of the state machine (perhaps this is the state of independent models governed by the state machine I define) on the WebPage. It looks like pytransitions supports the multiple models. If I passed multiple models in to the constructor as in the pytransitions example, would transitions-gui display both models? (I suppose I could just try it.) |
In 27ea90c, I implemented handling of mutliple models. You can pass custome css-like style selectors based on model classes and model names. See examples/multiple.py. It's not polished though. If two models are in the same state, only one selector in |
if running multiple instances of tornado in threads becomes an issue, I will have a look into whether threading can be limited to one server thread which can be reused by multiple |
I see, so with different models they are shown on the same state machine. Originally, I was thinking I'd have numerous replicated models being shown and identified, as opposed to having them all collapsed on to a single visualized machine. Maybe another way to do this is to be able to show a list of model IDs adorning the states they are presently in in their respective models? You are doing that nicely with colors here, but I suppose with a large number of models, this won't work so well (perhaps my idea won't either with even larger numbers of models, but it's a start). Is there a way to name my models with a string or number and have that appear within the state the model presently has. Perhaps I'd use the state entering and leaving callbacks to remove/add the ids from/to the state? I suppose while I'm at it perhaps I'd do the same for the transition to show which model id is using the transition at that moment. Thoughts? |
What if I used parallel states instead to represent the different models in parallel? I could label each parallel machine with the model id (where the example uses "numbers" and "greek") and move along independently. My state machines are HSMs, so hopefully I can still do that. Maybe that's what I want. |
I think both approaches (state node extended with model names or legend entries extended with model states) are feasible. See https://js.cytoscape.org/ for a better idea about how to edit graphs. Nodes are edited in WebMachine.selectState. Currently, only classes are set and removed. If you have an idea how to edit labels instead (or in addition to) altering classes, let me know. |
I usually try to find the simplest FSM architecture that gets the job done. Parallel states can be a solution but can also result in quite complex configurations. If you have instances that share states and transitions (e.g. agents, NPCs), I'd go for multiple models and simple machine. If instances rather act as components (e.g. robot arm, leg, head), I'd choose parallel states. |
Thanks for the advice. I suppose I should consider the state annotation with the ids. |
Trying out the graph_css parameter. I would have thought that I could pass graph_css=[] to the NestedWebMachine constructor and have it not doing anything different. Instead it halts with Exception <class 'ValueError'>. Is graph_css supported in NestedWebMachine? I assumed, yes. It barfed on my agent_css list, so I'm just simplifying. Removing the graph_css makes it not throw the exception. |
Changed it to just a WebMachine and it still didn't work. Must be missing something subtle here. Also tried setting graph_css=None with same issue. |
Running your multiple.py example produces the same issue, but more useful output (to you perhaps): ValueError: Passing arguments dict_keys[['graph_css']] caused an inheritance error: object init() takes exactly one argument (the instance to initialize). I wonder if I'm not using your latest code somehow... |
Did you install |
I'd expect the same. |
So, I did install transitions and transitions-gui initially and it worked until using this graph_css feature. So I did the uninstall of transitions-gui. It doesn't seem to have helped it to start working. Here's the message I get from your multiple.py pasted into my jupyter notebook:TypeError Traceback (most recent call last) TypeError: object.init() takes exactly one argument (the instance to initialize) During handling of the above exception, another exception occurred: ValueError Traceback (most recent call last) ~/miniconda3/lib/python3.8/site-packages/transitions_gui/web.py in init(self, *args, **kwargs) ~/miniconda3/lib/python3.8/site-packages/transitions/extensions/markup.py in init(self, *args, **kwargs) ~/miniconda3/lib/python3.8/site-packages/transitions/core.py in init(self, model, states, initial, transitions, send_event, auto_transitions, ordered_transitions, ignore_invalid_triggers, before_state_change, after_state_change, name, queued, prepare_event, finalize_event, model_attribute, **kwargs) ValueError: Passing arguments dict_keys(['graph_css']) caused an inheritance error: object.init() takes exactly one argument (the instance to initialize) I see in web.py you pop the web arguments and send things along to the super class. Which looks like it finds its way to markup.py, but it doesn't seem to pop the graph_css arguments before passing things along to the super class and that's where I believe graph_css is unepexpected and things go wrong in core.py. |
Oh, is the problem that I have done a pip install transitions in order to put pytransitions into ~/miniconda3? I think for my particular environment, I need the correct pytransitions to be found under ~/miniconda3. So perhaps I need to pip uninstall transitions, then git clone your transitions repo then somehow install that latest source into ~/miniconda3. Does that makes sense for this to behave differently (correctly)? If so, I see I can do something like changing into the pytransition directory with setup.py and do: python3 setup.py install Would that install it into ~/miniconda3? Guess I'll give it a tray and see what happens. |
The above did what I expected and installed transitions into ~/miniconda3. But no difference in bahavior. So I looked at the MarkupMachine code. It seems to be reference a "markup" parameter as opposed to a "graph_css" parameter you are using in the multiple.py example. Perhaps your latest code isn't pushed? I changed "graph_css" to "markup" and got further along in the process. However, then it complained with: ~/miniconda3/lib/python3.8/site-packages/transitions-0.8.6-py3.8.egg/transitions/extensions/markup.py in init(self, *args, **kwargs) TypeError: pop expected at most 1 argument, got 2 |
you still use an installed version of |
git clone https://github.com/pytransitions/transitions-gui.git
cd transitions-gui
pip install -r requirements.txt
# [1]
python examples/multiple.py and make sure that you dont have an older version of |
this basically means that |
Ok, about to follow your git clone to install transitions-gui from source. I was able to pip uninstall a few transitions-gui modules. I also pip uninstalled transitions. So, now do I clone the source for transitions and install that from source and then do the same as you describe for transitions-gui? |
|
Ok, I believe I have everything working as intended. Am I using the source because what we're working with hasn't been released? Just want to make sure I'm following why I'm doing it this way as opposed to using pip install. |
I created a new dev branch dev-multimodels since all these updates to |
Ok, still working with what I've got her now on my models. I see the legends for my models. Background color doesn't seem to be getting applied for some reason. I'll keep looking at it. Thanks for getting me straightened out! |
I'm really liking the model names in the states they occupy. I gave a demo of it and people were pretty excited about what they saw. How can I turn off the legend? It doesn't seem to be necessary for my needs, since color doesn't mean much other than recent change. Also, it would seem that my nested FSM doesn't color the activated transition when the transition is between sub-states of a state. Other transitions get colored fine as far as I can recall. |
This has been merged with #40 |
I'm interested in displaying the state of multiple state machines simultaneously on the same web page. It would seem that each of the transitions-gui instances starts it's own web server. I suppose, I could use different ports for this. Any chance there's already a way to do this using a single server? I'm headed towards a hundred independent state machines (for character states, as an example). The other method that occurs to me is to perhaps use the parallel state machine.
Also is there a way to color the state machine by the state it is presently in?
The text was updated successfully, but these errors were encountered: