openalea / mtg

Multiscale Tree Graph datastructure and interfaces
https://mtg.rtfd.io
Other
12 stars 17 forks source link

Insert scale refactoring #32

Open jazzsta opened 1 year ago

jazzsta commented 1 year ago

Hello, apparently in the later versions of python StopIteration exception raises a runtime error. Here there is more on that: https://peps.python.org/pep-0479/

Therefore we have to change the insert_scale method code, in particular line 1099

sup_components = dict((v, next(g.component_roots_iter(v))) for v in sup_vertices)

raises a runtime error and stops execution. I replaced it with

sup_components = dict() for v in sup_vertices: iteratorr = g.component_roots_iter(v) while True: try: sup_components[v] = next(iteratorr) except StopIteration: break

And now it seems to work fine. Can you verify that this is correct ?

pradal commented 1 year ago

Can you give me more context? Do you have a small example to reproduce the error?

jazzsta commented 1 year ago

Let's take the mtg given in the example https://mtg.readthedocs.io/en/latest/_downloads/0717997b5b681c0498e3c9ca16a5bca7/agraf.mtg

and try the script


from openalea.mtg import mtg

g=mtg.MTG('C:\GitModeles//agraf.mtg')

def partition(n,MTG=g):
    if g.node(n).label == 'E1':
        return True
    else:
        return False

g.insert_scale(3,partition,"mm")

It gives

RuntimeError: generator raised StopIteration