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

GraphMachine seems not working for parallel states #627

Closed
seanxlliu opened this issue Aug 9, 2023 · 2 comments
Closed

GraphMachine seems not working for parallel states #627

seanxlliu opened this issue Aug 9, 2023 · 2 comments
Assignees
Labels

Comments

@seanxlliu
Copy link

Thank you for taking the time to report a bug! Your support is essential for the maintenance of this project. Please fill out the following fields to ease bug hunting and resolving this issue as soon as possible:

Describe the bug
Parallel states work with HSM as expected, but failed to generate state diagram with GraphMachine

Minimal working example

from transitions.extensions import LockedHierarchicalGraphMachine as HSM

class Plane:
    def __init__(self):
        states = [
            "NoShow",
            {
                "name": "Docked",
                "parallel": [
                    {"name": "Refuel", "children": ["N", "Y"], 'initial': 'N'},
                    {"name": "Baggage", "children": ["N", "Y"], 'initial': 'N'},
                    {"name": "Meal", "children": ["N", "Y"], 'initial': 'N'},
                ],
            },
        ]

        transitions = [
            ["kickin", "NoShow", "Docked"],
            ["refuel", "Docked_Refuel_N", "Docked_Refuel_Y"],
            ["load_baggage", "Docked_Baggage_N", "Docked_Baggage_Y"],
            ["meal", "Docked_Meal_N", "Docked_Meal_Y"],
            ["leave", "*", "NoShow"],
        ]

        self.machine = HSM(
            model=self,
            states=states,
            transitions=transitions,
            initial="NoShow",
            ignore_invalid_triggers=True,
            use_pygraphviz=False,
            # show_auto_transitions=True
        )


plan = Plane()
roi = plan.get_graph(show_roi=True).draw('state_diagram.png', prog='dot')
plan.kickin()
print(plan.state)
plan.leave()
plan.load_baggage()
print(plan.state)
plan.refuel()
print(plan.state)
plan.meal()
print(plan.state)
plan.kickin()
print(plan.state)

Expected behavior
The diagram should show all defined transitions

Additional context
N/A
state_diagram

@aleneum
Copy link
Member

aleneum commented Sep 18, 2023

Hi @seanxlliu,

i am not sure whether this is still relevant for you: You pass show_roi=True as an option which will only pass 'reachable' from the current state. In state 'NoShow', only 'kickin' and 'leave' can be triggered and thus only 'NoShow' and Docked (and its parallel states) can be reached. If you want the whole graph to be draw, either pass show_roi=False or omit the argument altogether. That being said, show_roi=True is not working well with parallel states as of now since there are some corner cases to consider.

@aleneum
Copy link
Member

aleneum commented May 24, 2024

This has been tackled by #634. I will close this issue for now. Feel free to comment if this is still an issue for you. I will reopen the issue if necessary.

Whole graph (state_diagram.png)

state_diagram

Region of interest (state_diagram_roi.png)

state_diagram_roi

Code

from transitions.extensions import LockedHierarchicalGraphMachine as HSM

class Plane:
    def __init__(self):
        states = [
            "NoShow",
            {
                "name": "Docked",
                "parallel": [
                    {"name": "Refuel", "children": ["N", "Y"], 'initial': 'N'},
                    {"name": "Baggage", "children": ["N", "Y"], 'initial': 'N'},
                    {"name": "Meal", "children": ["N", "Y"], 'initial': 'N'},
                ],
            },
        ]

        transitions = [
            ["kickin", "NoShow", "Docked"],
            ["refuel", "Docked_Refuel_N", "Docked_Refuel_Y"],
            ["load_baggage", "Docked_Baggage_N", "Docked_Baggage_Y"],
            ["meal", "Docked_Meal_N", "Docked_Meal_Y"],
            ["leave", "*", "NoShow"],
        ]

        self.machine = HSM(
            model=self,
            states=states,
            transitions=transitions,
            initial="NoShow",
            ignore_invalid_triggers=True,
            use_pygraphviz=False,
            # show_auto_transitions=True
        )


plan = Plane()
plan.get_graph().draw('state_diagram.png', prog='dot')
plan.get_graph(show_roi=True).draw('state_diagram_roi.png', prog='dot')

@aleneum aleneum closed this as completed May 24, 2024
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