Mimi Framework

Array parameter setting fails with Int64 parameter type

I feel like I must be missing something, since I think the functionality I want here (having parameter arrays that aren’t floats) is widely used. But it doesn’t seem to be working.

I would like to define a parameter as taking an array of integers. But when I say:

order::Int64 = Parameter(index=[region], unit="none")

and then try to set it with an array of integers, I get the error:

Mismatched datatype of parameter connection: Component: <ComponentId Main.ClimateTemperature> (Float64), Parameter: order (Int64)

The error message is confusing, but it’s trying to say “I expect an array of Int64, but you’ve given my an array of Float64”. (NB: my parameter was an array of Int64 at the set_param! step.) So the problem is not in the parameter definition, but in the parameter-setting process.

Digging in a bit more, a likely culprit is this line in set_external_param!:

    value = convert(Array{md.number_type}, value)

That line is there to support models with a number_type like Number, so that we can do automatic differentiation. But shouldn’t we stop that conversion if the parameter has a specified type?

Hey James, this definitely looks like a bug to me. What version of Mimi are you using?

I just tried the following example on Mimi v0.9.4 and v0.9.5, and didn’t get an error. Do you know what’s different in your example?

using Mimi

@defcomp foo begin
    x::Int64 = Parameter(index=[time])
end

m = Model()
set_dimension!(m, :time, 3)
add_comp!(m, foo)
set_param!(m, :foo, :x, [1,2,3])

Aha! I replicated the error, it only happens when the index isn’t :time… very weird… I will look into this! The following example now produces the error:

using Mimi

@defcomp bar begin
    x::Int64 = Parameter(index=[regions])
end

m = Model()
set_dimension!(m, :time, 3)
set_dimension!(m, :regions, [:a, :b])
add_comp!(m, bar)
set_param!(m, :bar, :x, [1,2])

You beat me to it. I didn’t realize that it was from my :region index, but that’s what I am using in my case.

Hey James, pretty sure I found the problem. There was indeed an outdated type conversion happening only for non-time external parameters (they were being converted to the model’s number type regardless of whether or not there was a different type specified). I think we will release a new version with this fix, but for now if you want to try it out, it’s fixed on a branch called “param-type-v0.9.6”. Let me know if you have any more problems with it!

Thank you! I have possibly thrown a wrench into your plans, but we can figure it out over there.

@jrising David would prefer if you could test out the branch to make sure it solves your problem before we release the new version. The branch you should try is called param-type-v0.9.6, which is slightly different than the branch that the current pull request is on (that one contains other breaking changes that won’t be released until 1.0, but we want to release a 0.9.6 with just this bug fix for you). Whenever you have time, would you mind testing out your code on this new branch? thanks!

Just tested, and that fixes it! Thanks for your help.

@jrising we released a new version! if you update Mimi, you should get v0.9.6, which will be the same version you tested out.

Awesome. Thanks for everything.