Error in initial_population of Evolutionary.jl

Hello everybody,
I’m having a weird issue using the package Evolutionary.jl.
I tried to write a minimal example of my problem but unluckily, being too much simplified, the issue does not appear. Anyway, I’ll try to explain you the question.
I wrote my optimization problem following the examples reported in the Evolutionary package, in particular this one.
Being relatively long and structured, many parts of the code (such as the objective function) are wrote in external functions that are included at the beginning of the script, anyway, this shouldn’t be a problem for the solver.
I defined my objective function (OF in the code below) and tested it with many random values of the variables to optimize and it always provided correct results (i.e. it never returned NaN or errors).
I only have boundary constraints, therefore I defined them with lb and ub and then I wrote

c = WorstFitnessConstraints(Evolutionary.ConstraintBounds(lb, ub, [], []), [])
mthd = GA(populationSize = 20, ɛ = 0.03, crossoverRate = 0.8, mutationRate = 0.1, selection = rouletteinv, crossover = singlepoint, mutation = scramble)
opts = Evolutionary.Options(iterations = 40)
opt_res = Evolutionary.optimize(OF, c, mthd, opts)

Now, when the last line is executed, Julia provides this error:

ERROR: MethodError: no method matching zero(::Type{Any})
Closest candidates are:
  zero(::Type{Union{Missing, T}}) where T at missing.jl:105
  zero(::Type{Missing}) at missing.jl:103
  zero(::Type{LibGit2.GitHash}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\LibGit2\src\oid.jl:220
 [1] zero(::Type{Any}) at .\missing.jl:105
 [2] zeros(::Type{Any}, ::Tuple{Int64}) at .\array.jl:505
 [3] zeros(::Type{Any}, ::Int64) at .\array.jl:500
 [4] (::Evolutionary.var"#13#14"{DataType})(::Int64) at .\none:0
 [5] iterate at .\generator.jl:47 [inlined]
 [6] _all(::Base.var"#239#241", ::Base.Generator{Array{Int64,1},Evolutionary.var"#13#14"{DataType}}, ::Colon) at .\reduce.jl:819
 [7] all at .\reduce.jl:815 [inlined]
 [8] Dict(::Base.Generator{Array{Int64,1},Evolutionary.var"#13#14"{DataType}}) at .\dict.jl:130
 [9] initial_population(::GA, ::NLSolversBase.ConstraintBounds{Any}) at C:\Users\umber\.julia\packages\Evolutionary\Ub02D\src\api\utilities.jl:132     
 [10] optimize(::Function, ::WorstFitnessConstraints{Any,Array{Any,1}}, ::NLSolversBase.ConstraintBounds{Any}, ::GA, ::Evolutionary.Options{Nothing}) at C:\Users\user1\.julia\packages\Evolutionary\Ub02D\src\api\optimize.jl:33
 [11] optimize(::Function, ::WorstFitnessConstraints{Any,Array{Any,1}}, ::GA, ::Evolutionary.Options{Nothing}) at C:\Users\user1\.julia\packages\Evolutionary\Ub02D\src\api\optimize.jl:28

I’m not very sure about what is going wrong, I’d say that someting fails in the creation of the initial population but I can’t figure how to solve the issue.
Does anyone have any idea of what is happening?

Update: error has been solved, the issue was that lb and ub vectors were provided as Type Any. Changed to Float64.
In case it colud be useful to anyone, Evolutionary seems to not work with

c = WorstFitnessConstraints(Evolutionary.ConstraintBounds(lb, ub, [], []), [])

Changed with

const_calc(vars) = [0.0]
lc = [-Inf]
uc = [Inf]
c = WorstFitnessConstraints(Evolutionary.ConstraintBounds(lb, ub, lc, uc), const_calc)

and a complete run has been successfully performed.

Shameless plug: try CMAEvolutionStrategy.jl in case you are unhappy with the simplified version of CMA-ES in Evolutionary.jl :slight_smile:

Thanks a lot for the advice! Any suggestion for evolutionary algorithm packages in Julia is very appreciated, I’ll try it for sure.

1 Like