# Array parameter setting fails with Int64 parameter type

**URL:** <https://forum.mimiframework.org/t/array-parameter-setting-fails-with-int64-parameter-type/113>\
**Category:** Uncategorized\
**Created:** [February 11, 2020, 4:32pm UTC](https://forum.mimiframework.org/t/array-parameter-setting-fails-with-int64-parameter-type/113 "2020-02-11T16:32:08Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrising](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/jrising/32/7_2.png) [@jrising](https://forum.mimiframework.org/u/jrising)\
**Post date:** [February 11, 2020, 4:32pm UTC](https://forum.mimiframework.org/t/array-parameter-setting-fails-with-int64-parameter-type/113/1 "2020-02-11T16:32:08Z")

</div>

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:

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

```

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

```auto
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!`:

```auto
    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?

---

<div class="post-metadata">

**Author:** ![ckingdon95](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/ckingdon95/32/15_2.png) [@ckingdon95](https://forum.mimiframework.org/u/ckingdon95)\
**Post date:** [February 11, 2020, 6:55pm UTC](https://forum.mimiframework.org/t/array-parameter-setting-fails-with-int64-parameter-type/113/2 "2020-02-11T18:55:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ckingdon95](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/ckingdon95/32/15_2.png) [@ckingdon95](https://forum.mimiframework.org/u/ckingdon95)\
**Post date:** [February 11, 2020, 7:00pm UTC](https://forum.mimiframework.org/t/array-parameter-setting-fails-with-int64-parameter-type/113/3 "2020-02-11T19:00:53Z")

</div>

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?

```auto
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])

```

---

<div class="post-metadata">

**Author:** ![ckingdon95](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/ckingdon95/32/15_2.png) [@ckingdon95](https://forum.mimiframework.org/u/ckingdon95)\
**Post date:** [February 11, 2020, 7:07pm UTC](https://forum.mimiframework.org/t/array-parameter-setting-fails-with-int64-parameter-type/113/4 "2020-02-11T19:07:02Z")

</div>

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:

```auto
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])

```

---

<div class="post-metadata">

**Author:** ![jrising](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/jrising/32/7_2.png) [@jrising](https://forum.mimiframework.org/u/jrising)\
**Post date:** [February 11, 2020, 7:20pm UTC](https://forum.mimiframework.org/t/array-parameter-setting-fails-with-int64-parameter-type/113/5 "2020-02-11T19:20:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ckingdon95](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/ckingdon95/32/15_2.png) [@ckingdon95](https://forum.mimiframework.org/u/ckingdon95)\
**Post date:** [February 11, 2020, 8:46pm UTC](https://forum.mimiframework.org/t/array-parameter-setting-fails-with-int64-parameter-type/113/6 "2020-02-11T20:46:37Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![jrising](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/jrising/32/7_2.png) [@jrising](https://forum.mimiframework.org/u/jrising)\
**Post date:** [February 12, 2020, 1:25pm UTC](https://forum.mimiframework.org/t/array-parameter-setting-fails-with-int64-parameter-type/113/7 "2020-02-12T13:25:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ckingdon95](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/ckingdon95/32/15_2.png) [@ckingdon95](https://forum.mimiframework.org/u/ckingdon95)\
**Post date:** [February 13, 2020, 6:28pm UTC](https://forum.mimiframework.org/t/array-parameter-setting-fails-with-int64-parameter-type/113/8 "2020-02-13T18:28:02Z")

</div>

@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!

---

<div class="post-metadata">

**Author:** ![jrising](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/jrising/32/7_2.png) [@jrising](https://forum.mimiframework.org/u/jrising)\
**Post date:** [February 17, 2020, 3:55pm UTC](https://forum.mimiframework.org/t/array-parameter-setting-fails-with-int64-parameter-type/113/9 "2020-02-17T15:55:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ckingdon95](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/ckingdon95/32/15_2.png) [@ckingdon95](https://forum.mimiframework.org/u/ckingdon95)\
**Post date:** [February 24, 2020, 7:12pm UTC](https://forum.mimiframework.org/t/array-parameter-setting-fails-with-int64-parameter-type/113/10 "2020-02-24T19:12:19Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![jrising](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/jrising/32/7_2.png) [@jrising](https://forum.mimiframework.org/u/jrising)\
**Post date:** [February 25, 2020, 2:11pm UTC](https://forum.mimiframework.org/t/array-parameter-setting-fails-with-int64-parameter-type/113/11 "2020-02-25T14:11:05Z")

</div>

Awesome. Thanks for everything.
