ERROR: LoadError: MethodError: no method matching _init_identity_matrix(::ComponentVector{Float32, Vector{Float32}, Tuple{Axis{…}}}, ::Float64)

Hi,

When using BFGS from Optim.jl I occasionally get the following error message:

ERROR: LoadError: MethodError: no method matching _init_identity_matrix(::ComponentVector{Float32, Vector{Float32}, Tuple{Axis{…}}}, ::Float64)

What I don’t understand is why I am getting this error message when running BFGS when the function, _init_identity_matrix(...) exists in Optim.jl and why am I only sometimes getting this error message and not all the time.

Do you have a reproducible example?

It looks like it might be related to mixing Float32 and Float64 number types.

I don’t really have a reproducible example to share since the error only occurs occasionally, I get the error maybe 1 in 200 simulations.

It’s strange that it would have to do with the floating point format since I don’t change the floating point formats. Why do you think it has to do with that?

Do you have the full error message and stack trace?

I’m guessing this is a bug in Optim, and that it points to:

It probably needs to be _init_identity_matrix(state.x, T(initial_scale)), but your error message will confirm it.

It make sense why it only occasionally happens: because this code is run only when the search direction fails for some reason.

Sure, here is the full error message.

Is there a way to fix this bug?

Is there a way to fix this bug?

A fix will require a PR and a new release.

In the mean time, to work around the issue, use Float64 as your data type. It looks like your x is a ComponentVector with Float32 elements?

A fix will require a PR and a new release.

See Fix _init_identity_matrix in bfgs.jl by odow · Pull Request #1089 · JuliaNLSolvers/Optim.jl · GitHub

2 Likes