Skip to content

KeyError: 'agedge: no key' #258

Closed
Closed
@fpettinari

Description

@fpettinari

On Windows 10 & Python 2.7
After MANY installation errors with pygraphviz I've come to this one which it seems I'm not able to solve by myself:

  File "C:\Python27\lib\site-packages\transitions\extensions\diagrams.py", line 332, in __init__
    model.get_graph()
  File "C:\Python27\lib\site-packages\transitions\extensions\diagrams.py", line 345, in _get_graph
    else Graph(self).get_graph(title)
  File "C:\Python27\lib\site-packages\transitions\extensions\diagrams.py", line 172, in get_graph
    self._add_edges(self.machine.events.copy(), fsm_graph)
  File "C:\Python27\lib\site-packages\transitions\extensions\diagrams.py", line 130, in _add_edges
    container.add_edge(src, dst, **edge_attr)
  File "C:\Python27\lib\site-packages\pygraphviz\agraph.py", line 478, in add_edge
    eh = gv.agedge(self.handle, uh, vh, str(key), _Action.find)
KeyError: 'agedge: no key'

it seems it is caused by some transitions configurations like this:

	['any_trigger', 'same_state', 'same_state'],

or

	['anything', '*', 'any_state'],

Activity

aleneum

aleneum commented on Sep 29, 2017

@aleneum
Member

Hello @fedpet,

this is a reoccurring problem of pygraphviz under Windows. It has been reported before (#133), asked before at SO and also reported to pygraphviz (pygraphviz/pygraphviz#88) and networkx (networkx/networkx#2012). Since the issue has been closed in the pygraphviz tracker, I assume that it might be fixed in pygraphviz version 1.4rc1. In a pull request (#217) a user mentions a workaround for that issue.

Long story short: afaik we cannot do much about it since it seems to be related to pygraphviz and Windows, not transitions.

fpettinari

fpettinari commented on Sep 29, 2017

@fpettinari
Author

the error only happens when I try to draw reflexive transitions or ones which have '*' as the source.
btw if the problem is pygraphviz then what version are you officially using?
I see the repo examples are working..

edit.
I cloned and installed pygraphviz and it should be version 1.5.dev
same error

edit.
tried with version 1.4rc1.. same error

aleneum

aleneum commented on Sep 30, 2017

@aleneum
Member

btw if the problem is pygraphviz then what version are you officially using?

It shouldn't matter (we have used a couple of versions) as the issue is exclusive to Windows. Our test servers run Ubuntu 14.04 and I work with OSX Sierra (both use pygraphviz 1.3.1 currently). I have also used transitions on Ubuntu 16.04. Never had this issue. This code:

from transitions.extensions import GraphMachine

states = ['first', 'second']
transitions = [
    ['any_trigger', 'first', 'first'],
    ['anything', '*', 'second'],
]

machine = GraphMachine(states=states, transitions=transitions, initial='first',
                       auto_transitions=False, show_conditions=True)

machine.get_graph().draw('fsm.png', prog='dot')

produces this result:

fsm

I assume this would not work in your environment.

pygraphviz and it should be version 1.5.dev same error.. tried with version 1.4rc1.. same error

Bummer, it seems like they closed the issue without actually fixing it then. Thanks for giving it a try.

aleneum

aleneum commented on Sep 30, 2017

@aleneum
Member

I am trying to set up a Windows CI test job but installing pygraphviz does not play very nice.

@fedpet: How did you install pygraphviz? Unfortunately, using pip after installing Graphviz finishes but I end up with DLL import errors (event though PATH is set correctly). The only way I got it to work was by using the unofficial binary builds that are suggested occasionally but this does not look like a way suitable for an automatic build process.

aleneum

aleneum commented on Oct 1, 2017

@aleneum
Member

Nevermind, PATH has not been set correctly. Our tests fail on Windows as you can see here. I also added some try/catch phrases in the dev-appveyor branch to get some error messages. As mentioned in the above referenced issues/posts this error occurs only when source and destination of an edge are the same. I tried to omit extra attributes like labels but this does not work as well.

I do not see what we could do differently given the fact that we have no platform specific code and tests do succeed on Linux and OSX. If you have any suggestions about how to approach this issue I am all ears.

fpettinari

fpettinari commented on Oct 1, 2017

@fpettinari
Author

hi aleneum, thank you for your support.

transitions = [
    ['any_trigger', 'first', 'first'],
    ['anything', '*', 'second'],
]

I assume this would not work in your environment.
this error occurs only when source and destination of an edge are the same

Exactly

@fedpet: How did you install pygraphviz? [...]
Nevermind, PATH has not been set correctly

This. I'm not using unofficial binaries. Glad to see you found the problem :)

Your answer suggests me the problem may be on pygraphviz or graphviz side.

If you have any suggestions about how to approach this issue I am all ears.

A minimal code example demonstrating this bug would be needed to be able to open a proper bug report on pygraphviz/pygraphviz or graphviz-issue-tracker

aleneum

aleneum commented on Oct 2, 2017

@aleneum
Member

Hi @fedpet,

I added a minimal test to dev-appveyor:

import pygraphviz as pgv

from unittest import TestCase

class TestGraphviz(TestCase):

    def test_self_reference(self):
        G = pgv.AGraph()
        G.add_node('a')
        G.add_edge('a', 'a')
        print(G)

Status *nix: works
Status Windows: fails with Graphviz 2.38.0.1, pygraphviz 1.3.1

aleneum

aleneum commented on Mar 20, 2020

@aleneum
Member

For everyone having similar issues in 2020:

I tried the minimal example (ref) and the graph (ref) with Graphviz 2.41 64-bit from here (link is also mentioned on the Graphviz page here) and pygraphviz 1.6.dev0 with the patch mentioned here (see this discussion).

Both seem to work. If you experience issues with pygraphviz you can use transitions with the graphviz package as mentioned in the ReadMe:

from transitions.extensions import GraphMachine as Machine
m = Model()
# when you want to use graphviz explicitely
machine = Machine(model=m, use_pygraphviz=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @aleneum@fpettinari

        Issue actions

          KeyError: 'agedge: no key' · Issue #258 · pytransitions/transitions