Pluto --- Function barrier

Dear all,

I am sure that this was here solved / asked before, but i have not found the answer.
I am playing with the idea of implementing a visual frontend for Mill / JsonGrinder, which will allow you to upload the training data, tweak a model, and then let you start training. I would like to delay a training, such that it will start after all the stuff like models is finished. Thus, I need something like a barrier. I wanted to implement it using a “Button”, where I would have a start button and the training will start if I change the button. But this does not work, because I cannot assign the value to the variable bind to the button.

Something like:

Cell defining button

md"""
$(@bind go Button("Train!"))
"""

Cell performing training

if go == "Train!"
	Flux.Optimise.train!((x,y) -> loss(model, x, y), ps, repeatedly(minibatch, iterations), opt)
        go = "finished"
end

Does anyone has an idea, how can I achieve this?

Thanks for an answer in advance.

I prefer to use CheckBox for execution barriers - it’s a better fit for Pluto’s reactivity model.

md"""
Train! $(@bind cb CheckBox())
"""
if cb
	"go!"
end
3 Likes

The functionality to delay execution of specific cells (and their dependencies) will be available in Pluto itself soon - you can try it out here (GUI not final, but should be fully operational):

For usage, you could take a look at my PlutoCon talk:

3 Likes

I was watching your talk and I was thinking about the solution. The checkbox is a neat idea. Thanks a lot.

1 Like

Three years later :slight_smile:

I also use the checkbox-way, the main problem is that the checkbox stays activated after enabling it. So in the example by @Tomas_Pevny the training would start as soon as I check “Train”, but if I change some reactive cells above the “Train” checkbox, a training is triggered for every GUI action.

The intended behavior would be: Check the checkbox, start a single training while also deactivating the checkbox (to prevent triggering many trainings). Is this possible?

Or is there a better way to solve this now?

Thanks!

While trying to solve a similar problem I found this thread: PlutoUI: Trigger long computation only after user sets many parameters and confirms

I liked the following:
(each code block a Pluto cell)

using PlutoUI
parameters = (1,2,3)
parameters; @bind trigger CheckBox(default=false)
result = trigger ? sum(parameters) : nothing

This setup means that every time you change parameters the check box will be recreated unchecked, blocking the computation.

2 Likes

Ahh, I see! Nice one!

Thanks!

EDIT: Should be marked as solution IMO.

1 Like