Skip to content

Commit

Permalink
Helpful error messages and progress bar
Browse files Browse the repository at this point in the history
baggepinnen committed May 12, 2019
1 parent 2d5adff commit 565852c
Showing 3 changed files with 31 additions and 10 deletions.
22 changes: 19 additions & 3 deletions Manifest.toml
Original file line number Diff line number Diff line change
@@ -37,6 +37,12 @@ uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[Juno]]
deps = ["Base64", "Logging", "Media", "Profile", "Test"]
git-tree-sha1 = "4e4a8d43aa7ecec66cadaf311fbd1e5c9d7b9175"
uuid = "e5e0dc1b-0480-54bc-9374-aad01c23163d"
version = "0.7.0"

[[LatinHypercubeSampling]]
deps = ["Random", "StatsBase", "Test"]
git-tree-sha1 = "7cd8af9c1c8591b7501e82ae5d6f39fcb826aae9"
@@ -72,11 +78,17 @@ version = "0.5.0"
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[Media]]
deps = ["MacroTools", "Test"]
git-tree-sha1 = "75a54abd10709c01f1b86b84ec225d26e840ed58"
uuid = "e89f7d12-3494-54d1-8411-f7d8b9ae1f27"
version = "0.5.0"

[[Missings]]
deps = ["Dates", "InteractiveUtils", "SparseArrays", "Test"]
git-tree-sha1 = "d1d2585677f2bd93a97cfeb8faa7a0de0f982042"
deps = ["SparseArrays", "Test"]
git-tree-sha1 = "f0719736664b4358aa9ec173077d4285775f8007"
uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
version = "0.4.0"
version = "0.4.1"

[[Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
@@ -101,6 +113,10 @@ uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[Profile]]
deps = ["Printf"]
uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"

[[REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name = "Hyperopt"
uuid = "93e5fe13-2215-51db-baaf-2e9a34fb2712"
author = ["Fredrik Bagge Carlson <[email protected]>"]
version = "0.2.1"
version = "0.2.2"

[deps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Juno = "e5e0dc1b-0480-54bc-9374-aad01c23163d"
LatinHypercubeSampling = "a5e1c1ea-c99a-51d3-a14d-a9a37257b02d"
Lazy = "50d2b5c4-7a5e-59d5-8109-a42b560f39c0"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -16,5 +17,5 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
julia = "1.0"
LatinHypercubeSampling = "1.2"
julia = "1.0"
14 changes: 9 additions & 5 deletions src/Hyperopt.jl
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ export Hyperoptimizer, @hyperopt, @phyperopt, printmin, printmax
export RandomSampler, BlueNoiseSampler, LHSampler, CLHSampler, Continuous, Categorical

using LinearAlgebra, Statistics
using Juno
using Lazy
using MacroTools
using MacroTools: postwalk, prewalk
@@ -50,7 +51,7 @@ function Base.iterate(ho::Hyperoptimizer, state=1)
end

function preprocess_expression(ex)
ex.head == :for || error("Wrong syntax, Use For-loop syntax")
ex.head == :for || error("Wrong syntax, Use For-loop syntax, ex: @hyperopt for i=100, param=LinRange(1,10,100) ...")
params = []
candidates = []
sampler_ = :(RandomSampler())
@@ -62,7 +63,7 @@ function preprocess_expression(ex)
deleteat!(loop,i) # Remove the sampler from the args
continue
end
@capture(loop[i], param_ = list_) || error("Wrong syntax In @hyperopt")
@capture(loop[i], param_ = list_) || error("Wrong syntax, Use For-loop syntax, ex: @hyperopt for i=100, param=LinRange(1,10,100) ...")
push!(params, param)
push!(candidates, list)
i += 1
@@ -76,9 +77,12 @@ macro hyperopt(ex)
params, candidates, sampler_ = preprocess_expression(ex)
quote
ho = Hyperoptimizer(iterations = $(esc(candidates[1])), params = $(esc(params[2:end])), candidates = $(Expr(:tuple, esc.(candidates[2:end])...)), sampler=$(esc(sampler_)))
for $(Expr(:tuple, esc.(params)...)) = ho
res = $(esc(ex.args[2])) # ex.args[2] = Body of the For loop
push!(ho.results, res)
Juno.progress() do id
for $(Expr(:tuple, esc.(params)...)) = ho
res = $(esc(ex.args[2])) # ex.args[2] = Body of the For loop
push!(ho.results, res)
Base.CoreLogging.@logmsg -1 "Hyperopt" progress=$(esc(params[1]))/ho.iterations _id=id
end
end
ho
end

0 comments on commit 565852c

Please sign in to comment.