wouterkool / attention-learn-to-route

Attention based model for learning to solve different routing problems
MIT License
1.04k stars 337 forks source link

Runtime Error in Python 3.8 #16

Closed mlisicki closed 3 years ago

mlisicki commented 4 years ago

After switching to Python 3.8 I'm getting "RuntimeError: class not set defining 'BatchBeam' as <class 'utils.beam_search.BatchBeam'>. Was classcell propagated to type.new?"

After reading this post https://stackoverflow.com/questions/41343263/provide-classcell-example-for-python-3-6-metaclass and doing some initial debugging I'm guessing there should be some more arguments passed to super() method whenever you use it. It seems that all the classes deriving from NamedTuple are affected.

mlisicki commented 4 years ago

A minimal example that causes the error:

from typing import NamedTuple

class SuperTuple(NamedTuple):
    def __getitem__(self, key):
        return super(SuperTuple, self).__getitem__(key)
emeccc commented 3 years ago

@mlisicki I am getting the same error as yours after switching to Python 3.8. How did you solve this problem?

wouterkool commented 3 years ago

@mlisicki thanks for your investigations! Where you able to solve it in the end?

gabisurita commented 3 years ago

I was able to run the basic example by changing:

return super(SuperTuple, self).__getitem__(key)

With only:

return self[key]

Not sure if I've broke anything else though. I'll try to validate it a bit more and maybe open a PR.

wouterkool commented 3 years ago

Thanks for notifying this issue and proposing solutions. The code was intended to have the getitem functionality fall back to default when the objects are not indexed with slices or tensors. While the suggestions by @gabisurita fixes the error message by removing super, the self[key] has actually no effect (since it is never reached currently) but would cause an infinite recursion. Therefore, I implemented an assert instead.