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

Insert scale refactoring #32

Open
jazzsta opened this issue Feb 14, 2023 · 2 comments
Open

Insert scale refactoring #32

jazzsta opened this issue Feb 14, 2023 · 2 comments

Comments

@jazzsta
Copy link

jazzsta commented Feb 14, 2023

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
Copy link
Contributor

pradal commented Feb 14, 2023

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

@jazzsta
Copy link
Author

jazzsta commented Feb 15, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants