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

Batch update for parameter values #24

Closed
jbednar opened this issue Sep 4, 2018 · 7 comments
Closed

Batch update for parameter values #24

jbednar opened this issue Sep 4, 2018 · 7 comments
Assignees

Comments

@jbednar
Copy link
Member

jbednar commented Sep 4, 2018

The reactivity that comes from watching parameter values is really helpful, but it causes problems when changing a lot of parameter values at once. E.g. for this code:

from time import sleep
import param, panel as pp
pp.extension()

defaults = dict(a=0.2, b=0.4, c=0.6, d=0.8)

class C(param.Parameterized):
    a = param.Magnitude(defaults["a"])
    b = param.Magnitude(defaults["b"])
    c = param.Magnitude(defaults["c"])
    d = param.Magnitude(defaults["d"])
    
    reset_ = param.Action(lambda x: x.reset())
    
    @param.depends('a', 'b', 'c', 'd')
    def view(self):
        sleep(1)
        return "<H2>"+str((self.a, self.b, self.c, self.d))+"</H2>"

    def reset(self):
        self.set_param(**defaults)

c=C(name="")
pp.Row(c,pp.Column("<H1>Current&nbsp;values:</H2>", c.view))

image

If I press the "Reset" button, it changes the four parameters one... by... one..., calling the view() function each time. Here view() is just a sleep call, but in practice in my real code it's a lengthy computation to plot something complicated, which is where I noticed the issue. Oddly, in my real code I also was able to watch the widget values update one by one, but here the widgets are failing to be updated by the reset call even though the parameter values have changed:

image

Note: this code depends on #21 so that the view() return type is representable, but I saw the problems with other Pane types before that PR.

@philippjfr
Copy link
Member

Isn't this meant to be a param issue, that's assigned to either @ceball or @jlstevens ?

@philippjfr
Copy link
Member

To be clear I'm happy to leave this open since I will have to make use of the new capabilities that will be added to param here, but the majority of changes will happen at the param level.

@jbednar
Copy link
Member Author

jbednar commented Sep 4, 2018

Let's treat the assignment to you as a prompt for you to explain those issues. For me, it is a Panel issue, because that's how I'm encountering it; it only occurs when I pass the view method to a Panel Row or Column, because that's presumably what sets up the underlying value watching. I haven't studied that code in Panel, but it sounds like you're saying that it's simply using the underlying Parameter mechanisms for watching, which is fine, but I don't know enough about how that part works to file an issue on Param. Assuming you do, please reformulate what I'm showing above to reveal what's really going on at the Param level where it can be addressed, then make such an issue on Param and refer to it here. Then we can leave this Panel issue open until the corresponding changes to Param have been made and we can then try the above code again with Panel to see if the issue has been solved.

@philippjfr
Copy link
Member

philippjfr commented Sep 4, 2018

Currently you subscribe to a parameter change like this:

parameterized.param.watch(callback, 'parameter_a')

i.e. you supply a callback that gets executed when the 'parameter_a' changes. The signature for that callback must be:

def callback(change):
    ...

where change is a param change object which describes what attribute changed and what the old and new values for that parameter are. In order to be able to batch parameter updates and callbacks we need something like this:

parameterized.param.watch(callback, ['parameter_a', 'parameter_b'])

def callback(*changes):
   ...

where changes would potentially be a list of change events, which can be processed together.

@jbednar
Copy link
Member Author

jbednar commented Sep 4, 2018

Presumably there would also need to be a mechanism to set parameters in batch, for such a callback with multiple changes ever to be generated? Maybe the param.set_params() method would need to support that.

@jlstevens
Copy link
Contributor

jlstevens commented Sep 4, 2018

I agree this needs changes at the param level but the issue is most clearly exposed when using panel. Personally I think set_params is the right place to batch changes for watched parameters and param will need to generalize the sort of callbacks that can have watch set on them as Philipp points out above.

I am happy to work on this if I am assigned this task!

@philippjfr
Copy link
Member

Now implemented.

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

3 participants