From 2439578360e2eade5b7818ea8ee11d02d3fd5257 Mon Sep 17 00:00:00 2001 From: "Eric S. Tellez" Date: Thu, 21 Jul 2022 19:13:18 -0500 Subject: [PATCH] code refactoring; now ignores configurations raising errors --- Project.toml | 2 +- src/search.jl | 36 ++++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Project.toml b/Project.toml index 7e22955..4deee32 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/search.jl b/src/search.jl index 3352932..86d52d2 100644 --- a/src/search.jl +++ b/src/search.jl @@ -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 @@ -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 """ @@ -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, @@ -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) @@ -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