Skip to content

Commit

Permalink
code refactoring; now ignores configurations raising errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sadit committed Jul 22, 2022
1 parent 9fc9949 commit 2439578
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SearchModels"
uuid = "0e966ebe-b704-4a65-8279-db954bfe5da0"
authors = ["Eric S. Tellez"]
version = "0.3.0"
version = "0.3.1"

[deps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Expand Down
36 changes: 20 additions & 16 deletions src/search.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ Evaluates queue of using errfun; the resulting `config => performances` are stor
"""
function evaluate_queue(errfun::Function, evalqueue, population, parallel, tmp)
if parallel === :none
if population === nothing
population = [c => errfun(c) for c in evalqueue]
else
for c in evalqueue
push!(population, c => errfun(c))
for c in evalqueue
try
p = errfun(c)
push!(population, c => p)
catch e
@info e
@info "ignoring configuration due to exception"
end
end

Expand All @@ -118,15 +120,17 @@ function evaluate_queue(errfun::Function, evalqueue, population, parallel, tmp)
end
end

if population === nothing
[k => fetch(v) for (k, v) in tmp]
else
for (k, v) in tmp
push!(population, k => fetch(v))
for (c, perf) in tmp
try
p = fetch(perf)
push!(population, c => p)
catch e
@info e
@info "ignoring configuration due to exception"
end

population
end

population
end

"""
Expand Down Expand Up @@ -203,7 +207,7 @@ it selects at most `maxpopulation` configurations at any iteration (best ones).
function search_models(
errfun::Function,
space::AbstractSolutionSpace,
initialpopulation=32, # it can alos be a list of config seeds
initialpopulation=32, # it can also be a list of config seeds
params::SearchParams=SearchParams();
geterr::Function=identity,
accept_config::Function=config -> true,
Expand All @@ -227,15 +231,15 @@ function search_models(
prev = 0.0
iter = 0

population = nothing
population = Pair[]
tmp = Pair[]
params.verbose && println(stderr, "SearchModels> search params iter=$iter, tol=$(params.tol), initialpopulation=$initialpopulation, maxpopulation=$(params.maxpopulation), bsize=$(params.bsize), mutbsize=$(params.mutbsize), crossbsize=$(params.crossbsize)")

while iter <= params.maxiters
iter += 1
population = evaluate_queue(errfun, evalqueue, population, parallel, tmp)
sort!(population, by=x->geterr(x.second))
inspect_population(space, params, population)
sort!(population, by=x->geterr(x.second))

if params.maxpopulation < length(population)
resize!(population, params.maxpopulation)
Expand All @@ -248,7 +252,7 @@ function search_models(

curr = geterr(population[end].second)
if abs(curr - prev) <= params.tol
params.verbose && println("SearchModels> stop by convergence error=$curr, tol=$(params.tol)")
params.verbose && println("SearchModels> stop by convergence error=$curr, tol=$(params.tol), iter=$iter (of $(params.maxiters))")
return population
end

Expand Down

2 comments on commit 2439578

@sadit
Copy link
Owner Author

@sadit sadit commented on 2439578 Jul 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/64727

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.1 -m "<description of version>" 2439578360e2eade5b7818ea8ee11d02d3fd5257
git push origin v0.3.1

Please sign in to comment.