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

Cells with @bind value run twice #275

Closed
fonsp opened this issue Aug 12, 2020 · 10 comments
Closed

Cells with @bind value run twice #275

fonsp opened this issue Aug 12, 2020 · 10 comments
Assignees
Labels
almost closed enhancement New feature or request reactivity The Pluto programming paradigm

Comments

@fonsp
Copy link
Owner

fonsp commented Aug 12, 2020

From @GiggleLiu in #262:

Thanks for you suggestion @fonsp , there is not error anymore with PlutoUI.

But there is still an issue. The last cell is refreshed multiple times when I update a cell. This is not desired because the last cell is expensive to evaluate in my application.

The cells causing multiple update looks like

The Controller

if optimizer == "ADAM"
	md"""
η (learning rate) = $(@bind adam_η Slider(0.0:0.001:1.0; default=0.01))
$(html"<br>")
β1 = $(@bind adam_β1 Slider(0.0:0.001:1.0; default=0.9))

β2 = $(@bind adam_β2 Slider(0.0:0.0001:1.0; default=0.999))

[help on ADAM](https://ruder.io/optimizing-gradient-descent/index.html#adam)
"""
elseif optimizer == "SPSA"
	md"""learning rate = ``c/m^γ`` (``m`` is the step)
$(html"<br>")
c = $(@bind spsa_γ Slider(0:0.001:1.0; default=0.02))

γ = $(@bind spsa_ξ Slider(0.01:0.001:1.0; default=0.101))
$(html"<br>")
gradient search range = ``a/(m+A)^α``
$(html"<br>")
a = $(@bind spsa_δ Slider(0.01:0.001:1.0; default=0.1))

α = $(@bind spsa_α Slider(0.01:0.001:1.0; default=0.602))
$(html"<br>")
A = $(@bind spsa_A Slider(0.0:0.1:50.0; default=5.0))

[help on SPSA](https://pdfs.semanticscholar.org/bf67/0fb6b1bd319938c6a879570fa744cf36b240.pdf)
"""
elseif optimizer == "AdaGrad"
	md"""
η (learning rate) = $(@bind adagrad_η Slider(0.0:0.001:1.0; default=0.01))

[help on AdaGrad](https://ruder.io/optimizing-gradient-descent/index.html#adagrad)
"""
elseif optimizer == "MGD"
	md"""
learning rate = ``c/m^γ`` (``m`` is the step)
$(html"<br>")
c = $(@bind mgd_γ Slider(0.0:0.001:1.0; default=0.02))
$(html"<br>")
γ = $(@bind mgd_ξ Slider(0.01:0.001:1.0; default=0.101))
$(html"<br>")
gradient search range = ``a/(m+A)^α``
$(html"<br>")
a = $(@bind mgd_δ Slider(0.01:0.001:1.0; default=0.1))
$(html"<br>")
α = $(@bind mgd_α Slider(0.01:0.001:1.0; default=0.602))
$(html"<br>")
A = $(@bind mgd_A Slider(0.0:0.1:50.0; default=5.0))
$(html"<br>")
population = $(@bind mgd_k Slider(0:1:50; default=5))

[help on MGD](https://arxiv.org/pdf/2004.04197.pdf)
"""
elseif optimizer == "CMAES"
	md"""
population = $(@bind cmaes_npopulation NumberField(0:1:50; default=5))
offsprings = $(@bind cmaes_noffsprings NumberField(0:1:250; default=25))
$(html"<br>")
σ0 (initial variance) = $(@bind cmaes_σ0 Slider(0.01:0.001:2.0; default=0.2))
$(html"<br>")
τ = $(@bind cmaes_τ Slider(1.0:0.01:10.0; default=3.3))
``τ_c`` = $(@bind cmaes_τ_c Slider(1.0:0.1:500.0; default=100.0))
``τ_σ`` = $(@bind cmaes_τ_σ Slider(1.0:0.01:10.0; default=3.3))

[help on CMAES](https://arxiv.org/abs/1604.00772)
"""
else
	error("can not find optimizer: $optimizer")
end

The Cell refreshed multiple times

optiter = let
	x0 = copy(initial_params)
	if optimizer == "AdaGrad" || optimizer == "ADAM"
		if autodiff == "finitediff"
			adconfig = FiniteDiffConfig(ad_δ)
		elseif autodiff == "SPSA"
			adconfig = SimulataneousPerturbation(ad_δ, ad_nbatch)
		elseif autodiff == "RSGF"
			adconfig = RSGFConfig(ad_δ, ad_nbatch)
		else
			error("autodiff $autodiff unknown")
		end
	end
	if optimizer == "CMAES"
		cmaes(loss, x0; npopulation=cmaes_npopulation, noffsprings=cmaes_noffsprings, σ0=Float64(cmaes_σ0), τ=Float64(cmaes_τ), τ_σ=Float64(cmaes_τ_σ), τ_c=Float64(cmaes_τ_c), bounds=bounds)
	elseif optimizer == "SPSA"
		spsa(loss, x0; δ=spsa_δ, ξ=spsa_ξ, α=spsa_α, γ=spsa_γ, A=spsa_A, order=1, bounds=bounds)
	elseif optimizer == "ADAM"
		adam(loss, x0; η=adam_η, autodiff=adconfig, bounds=bounds)
	elseif optimizer == "AdaGrad"
		adagrad(loss, x0; η=adagrad_η, autodiff=adconfig, bounds=bounds)
	elseif optimizer == "MGD"
		mgd(loss, x0; γ=mgd_γ, δ=mgd_δ, ξ=mgd_ξ, α=mgd_α, k=mgd_k, A=mgd_A, bounds=bounds)
	end
end;

optimizer_selector

Originally posted by @GiggleLiu in #262 (comment)

@fonsp fonsp changed the title Cell with @bind value run twice Cells with @bind value run twice Aug 12, 2020
@fonsp
Copy link
Owner Author

fonsp commented Aug 12, 2020

(Note to self: JuliaPluto/PlutoUI.jl#3 makes this a lot easier)

@fonsp fonsp added enhancement New feature or request reactivity The Pluto programming paradigm labels Aug 12, 2020
@fonsp fonsp self-assigned this Aug 12, 2020
@lungben
Copy link
Contributor

lungben commented Aug 14, 2020

I am running into the same issue - I have a rather long analysis depending on 6 PlutoUI elements. When opening the notebook, this analysis is executed 7 times.
Is there any short-term workaround for this issue? Like somehow grouping the UI elements together that they trigger only one update?

@fonsp
Copy link
Owner Author

fonsp commented Aug 14, 2020

Can't think of anything - it might actually be easier to fix this problem than to design a workaround

@fonsp
Copy link
Owner Author

fonsp commented Aug 14, 2020

Oh well one workaround is to not use PlutoUI but html"<input>", so that those initial runs give missing instead of the first value - that way your analysis errors the first time instead of doing a lengthy run.

@fonsp
Copy link
Owner Author

fonsp commented Aug 14, 2020

I fixed it! Try it out by using Pluto's master branch

@GiggleLiu
Copy link
Contributor

Thank you! @fonsp

@lungben
Copy link
Contributor

lungben commented Aug 14, 2020

@fonsp perfect, thank you very much!

@fonsp fonsp reopened this Oct 15, 2020
@Sh4pe
Copy link

Sh4pe commented Oct 16, 2020

I do still experience this issue. After running a notebook with some really lengthy and expensive calculations that all ultimately depend on some values selected by Select and Checkbox elements from PlutoUI, these select and checkbox cells are triggered again and the subsequent cells also run again. Even more than once.

After some time, it "stabilizes", i.e. all cells are done. Haven't counted, but some cells are executed 4+ times I think.

Note that this error started when I updated from v0.11.14 to v0.12.4 - i.e. in the same notebook, this re-running did not happend when I used v0.11.14.

@fonsp fonsp closed this as completed in e3204f2 Oct 16, 2020
@fonsp
Copy link
Owner Author

fonsp commented Oct 16, 2020

@GiggleLiu it's fixed again!

@GiggleLiu
Copy link
Contributor

🎉 🎉 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
almost closed enhancement New feature or request reactivity The Pluto programming paradigm
Projects
None yet
Development

No branches or pull requests

4 participants