Open PhilipVinc opened 1 year ago
Hmm, this is not an ideal solution, but explicitly importing DenyList
seems to resolve the error:
from plum import dispatch
from flax.core.scope import Filter, DenyList
@dispatch
def f(a: Filter):
return 2
f(1)
Could you check whether that correctly works within netket
?
Yes, importing in the session DensyList
makes it work.
Importing DenyList
in the netket package itself (not in the session) does not work.
I imagine that this is because typing
is for some reason evaluating the signature in the current scope instead of the scope where the lazy thing is defined...
Do you or our bearish friend have any idea of what to do? Or is this a bug in flax? I'm not very familiar with those string-y signatures...
I imagine that this is because typing is for some reason evaluating the signature in the current scope instead of the scope where the lazy thing is defined...
I think something like this is going on, though I'm not 100% sure.
When I'm home I'll try the netket
example to see if that can be made to work!
As a simple reproducer in netket you can use
import netket as nk
hi=nk.hilbert.Spin(0.5); ma=nk.models.RBM()
vs=nk.vqs.ExactState(hi, ma)
vs.expect_and_grad(nk.operator.spin.sigmam(hi, 0))
The error is triggered by this definition and possibly others using this CollectionFilter
(which is not needed, btw.. it's a keyword argument anyway, it was just there for correctly documenting what type it should be).
Still this is an annoying bug... I think there should be a way to treat these lazy declarations correctly...
@PhilipVinc Are this issue and #80 still current, or have you managed to resolve the problems since?
I fixed it in netket by importing the definition of that type, but I think it's not a good solution and therefore this is still a bug
Glad to hear that you've fixed it by importing the definition. I agree that this should just work, but I'm also not sure how that could be done. Let's leave the issue open then.
MWE reduced from #80 .
The bug appears to arise because
Filter
defined inflax
(see here) is defined with a forward reference, but it's then defined so I would expect this to work?