-
Notifications
You must be signed in to change notification settings - Fork 25
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
parametric
conflicts with certain usages of customized __init_subclass__
#105
Comments
Can you provide a runnable MWE? |
Sure! one moment |
import abc
import jax.tree_util as jtu
from plum import parametric
class Pytree:
def __init_subclass__(cls, **kwargs):
jtu.register_pytree_node(
cls,
cls.flatten,
cls.unflatten,
)
@abc.abstractmethod
def flatten(self):
raise NotImplementedError
@classmethod
def unflatten(cls, data, xs):
return cls(*data, *xs)
@parametric
class Wrapper(Pytree):
def flatten():
return (), ()
Wrapper[int] Even if there's not a convenient idiom using |
I suspect the issue lies in this line which is run after the concrete class There should be a way to ensure that the proper class is passed there... |
Right - this is a bit of a weird setting (in the sense that I wonder if I could do something on my end to get around it. |
Maybe just changing that line in plum to |
Thanks for any help! |
Yes, this fixes it. I'm preparing a PR. from plum import parametric
register = set()
class Pytree:
def __init_subclass__(cls, **kwargs):
if cls in register:
raise ValueError("duplicate")
else:
register.add(cls)
@parametric
class Wrapper(Pytree):
pass
Wrapper[int] |
By the way, may I ask you to share (a gist?) your PyTree code with |
Sure, one moment. |
Or -- rather, what do you want that is different than the MWE I posted above? |
Ah ok, that's what you do? |
Ah right -- I define Nothing fancy with introspection -- just custom |
Hi!
I'm using JAX, and also using
plum
-- in my library, I've define a mixin class calledPytree
which automatically implements the Pytree interface for classes which mix it in.It's quite simple:
If I wish to use this mixin, and
parametric
-- I'm in for problems, I get duplicate registration:I'm not exactly sure why this occurs, but I'm hoping to find a fix -- because I'd like to use parametric classes to guide some of the dispatch in my library functions.
The text was updated successfully, but these errors were encountered: