transitions icon indicating copy to clipboard operation
transitions copied to clipboard

GraphMachine markup should update if machine structure changes

Open drpjm opened this issue 1 year ago • 6 comments

I am experimenting with modifying HierarchicalGraphMachine for my particular use case: using remove_transition and/or removing states. I noticed that the GraphMachine family does not update its markup when structural changes occur.

Here is some example code I was messing with...

from transitions.extensions import HierarchicalGraphMachine as HGM
states = ['a','b','c']
initial = 'a'
machine = HGM(states=states, initial='a', auto_transitions=False)
machine.add_transition(trigger='t_ab', source='a',dest='b')
machine.add_transition(trigger='t_bc', source='b',dest='c')
machine.add_transition(trigger='t_ca', source='c',dest='a')
machine.get_graph().draw('machine1.png', format="png", prog='dot')

And this produces: machine1

Then I take a couple steps:

machine.t_ab()
machine.t_bc()

machine3 Now I remove a transition for fun:

machine.remove_transition(trigger='t_ca')

The transition is removed correctly (no more t_ca), but the markup still has transition as evidenced in this final graph drawing:

machine4 and by looking at the markup:

machine.markup['transitions']

[{'source': 'a', 'dest': 'b', 'trigger': 't_ab'}, {'source': 'b', 'dest': 'c', 'trigger': 't_bc'}, {'source': 'c', 'dest': 'a', 'trigger': 't_ca'}]

It could be I am doing this wrong, but I would expect that removing a transition or state should update the markup that is used to drive the graph output. If this seems reasonable, where would such a feature be implemented? Thanks!

drpjm avatar Jan 02 '23 20:01 drpjm