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

allow_refs and rx() expr not working in nested Parameterized #972

Open
samimia-swks opened this issue Oct 29, 2024 · 0 comments
Open

allow_refs and rx() expr not working in nested Parameterized #972

samimia-swks opened this issue Oct 29, 2024 · 0 comments

Comments

@samimia-swks
Copy link

param 2.1.1, python 3.12.1

I am trying to assign reactive expressions to parameters defined with allow_refs=True in the __init__() of the Parameterized class, similiar to what you can achieve with param.depends(). This is not clearly documented but it seems like it should work and in fact it does for simple examples. But once you start nesting Parameterized classes it stops working.

This works:
 

# %%
class SVConst(param.Parameterized):
    i = param.Number(1, allow_refs=True, nested_refs=True)
    f = param.Number(None, allow_refs=True, nested_refs=True)

    def __init__(self, **params):
        super().__init__(**params)
        self.f = self.param.i.rx() / 10

sv = SVConst()

sv.i = 20
print(sv.f)

We get sv.f = 2.0 as expected. So far so good.

Now we add a level of hierarchy:

# %%
class IPConsts(param.Parameterized):
    const1 = param.ClassSelector(class_=SVConst, default=SVConst(), allow_refs=True, nested_refs=True)
    const2 = param.ClassSelector(class_=SVConst, default=SVConst(), allow_refs=True, nested_refs=True)
    const3 = param.ClassSelector(class_=SVConst, default=SVConst(), allow_refs=True, nested_refs=True)

    def __init__(self, **params):
        super().__init__(**params)
        self.const3.i = self.const1.param.i.rx() + self.const2.param.i.rx()

ip = IPConsts()

ip.const1.i = 10
ip.const2.i = 40
print(ip.const3.i)
print(ip.const3.f)

We get ip.const3.i = 50 as expected (40 + 10).
But ip.const3.f is 0.1, but I expected it to be 5.0, i.e. 50 / 10.

Seems like a bug?

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

1 participant