# Make MCS @defmcs accept constrained distributions?

**URL:** <https://forum.mimiframework.org/t/make-mcs-defmcs-accept-constrained-distributions/21>\
**Category:** Uncategorized\
**Created:** [February 27, 2019, 10:51pm UTC](https://forum.mimiframework.org/t/make-mcs-defmcs-accept-constrained-distributions/21 "2019-02-27T22:51:53Z")\
**Posts on this page:** 17\
**Page:** 2

<div class="post-metadata">

**Author:** ![hbenveniste](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@hbenveniste](https://forum.mimiframework.org/u/hbenveniste)\
**Post date:** [March 5, 2019, 2:05am UTC](https://forum.mimiframework.org/t/make-mcs-defmcs-accept-constrained-distributions/21/21 "2019-03-05T02:05:20Z")

</div>

Thanks all, this is super helpful!

---

<div class="post-metadata">

**Author:** ![hbenveniste](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@hbenveniste](https://forum.mimiframework.org/u/hbenveniste)\
**Post date:** [March 8, 2019, 9:43pm UTC](https://forum.mimiframework.org/t/make-mcs-defmcs-accept-constrained-distributions/21/22 "2019-03-08T21:43:00Z")

</div>

Hi again, sorry for the delayed feedback. I still have the same issue after pulling Richard’s changes on my master branch and using the Mimi master branch: I still get the error  
`ERROR: UndefVarError: ReshapedDistribution not defined`.  
How come the new `ReshapedDistribution` structure does not seem to be recognized even if I pulled it on my computer?

Also when I comment out l.30: `alpha = Mimi.ReshapedDistribution([5, 5], Dirichlet(25,1))`, I still get as error:  
`ERROR: MethodError: no method matching set_models!(::MonteCarloSimulation, ::MarginalModel)`.

I suppose this means that the new version of Mimi is not correctly pulled?

---

<div class="post-metadata">

**Author:** ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)\
**Post date:** [March 9, 2019, 1:54am UTC](https://forum.mimiframework.org/t/make-mcs-defmcs-accept-constrained-distributions/21/23 "2019-03-09T01:54:05Z")

</div>

I can look into this if you push it, sorry it’s causing you trouble. Just so I understand the state of your environment, we’ve now released `Mimi0.7.0`, so you should be able to `]free Mimi` and work with the latest tagged version now.

---

<div class="post-metadata">

**Author:** ![hbenveniste](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@hbenveniste](https://forum.mimiframework.org/u/hbenveniste)\
**Post date:** [March 9, 2019, 6:28pm UTC](https://forum.mimiframework.org/t/make-mcs-defmcs-accept-constrained-distributions/21/24 "2019-03-09T18:28:36Z")

</div>

Thanks a lot Lisa! Just pushed. I still get the `UndefVarError: ReshapedDistribution not defined` error, even after doing `]free Mimi`.

But everything else works; when I comment the `Mimi.ReshapedDistribution` part out (l.30), I got everything running.

---

<div class="post-metadata">

**Author:** ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)\
**Post date:** [March 10, 2019, 11:45pm UTC](https://forum.mimiframework.org/t/make-mcs-defmcs-accept-constrained-distributions/21/25 "2019-03-10T23:45:30Z")

</div>

Great, I’ll take a look tomorrow or tonight, and give you an update on an easier way for you to work wth FUND per recent updates as soon as I complete that. Should make your folder structure way simpler.

---

<div class="post-metadata">

**Author:** ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)\
**Post date:** [March 11, 2019, 10:00pm UTC](https://forum.mimiframework.org/t/make-mcs-defmcs-accept-constrained-distributions/21/26 "2019-03-11T22:00:11Z")

</div>

@hbenveniste I’m sorry I didn’t think of this earlier, but I think your error is actually very small! In general, the list of “exported” functions by Mimi is small, because those are the ones we try extremely hard not to “break” in future releases. Often, more advanced users like you want to use functions that are not exported, meaning that you cannot directly use them without importing them. There are a few ways to do that. One way is just to prefix the function with `Mimi.`, i.e. `Mimi.ReshapedDistribution`. If there is something you are doing quite often, and that is annoying, you can directly import more functions. For example, the beginning of `test_reshaping.jl` looks like this:

```auto
using Mimi
using Distributions
using Query
using DataFrames
using IterTools
using DelimitedFiles

using Test

using Mimi: reset_compdefs, modelinstance, compinstance, 
            get_var_value, OUTER, INNER, ReshapedDistribution

```

For you, you would basically need to put both of these lines in

```auto
using Mimi # brings in all exported functions, you already do this
using Mimi: ReshapedDistribution # brings in ReshapedDistribution

```

Then you can use `ReshapedDistribution` wherever want without the `Mimi.` prefix!

---

<div class="post-metadata">

**Author:** ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)\
**Post date:** [March 11, 2019, 10:14pm UTC](https://forum.mimiframework.org/t/make-mcs-defmcs-accept-constrained-distributions/21/27 "2019-03-11T22:14:07Z")

</div>

Shoot, you did already do this! Ok then I think you must be running an old version of Mimi, what happens when you type `]st Mimi`? Let’s make sure you have the latest version by typing using `]up`, which will update all of your packages. Then `]st` should show that you have `[e4e893b0] Mimi v0.8.0`.

You will need to

- change `@defmcs` to `@defsim`
- change `run_mcs` to `run_sim`

Then try to run it, it should work but I"ll double check on my machine now.

---

<div class="post-metadata">

**Author:** ![hbenveniste](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@hbenveniste](https://forum.mimiframework.org/u/hbenveniste)\
**Post date:** [March 11, 2019, 10:22pm UTC](https://forum.mimiframework.org/t/make-mcs-defmcs-accept-constrained-distributions/21/28 "2019-03-11T22:22:07Z")

</div>

Thanks Lisa! I did already try to updates packages multiple times, but I still am on `[e4e893b0] Mimi v0.6.4`. I’m not sure why that’s happening?

---

<div class="post-metadata">

**Author:** ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)\
**Post date:** [March 11, 2019, 10:33pm UTC](https://forum.mimiframework.org/t/make-mcs-defmcs-accept-constrained-distributions/21/29 "2019-03-11T22:33:29Z")

</div>

Oh well that’s certainly the problem! Hm that’s really strange, can you send me the full list of what comes out when you do `]st`?

---

<div class="post-metadata">

**Author:** ![hbenveniste](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@hbenveniste](https://forum.mimiframework.org/u/hbenveniste)\
**Post date:** [March 11, 2019, 10:35pm UTC](https://forum.mimiframework.org/t/make-mcs-defmcs-accept-constrained-distributions/21/30 "2019-03-11T22:35:49Z")

</div>

```auto
    Status `C:\Users\Helene\.julia\environments\v1.0\Project.toml`
  [336ed68f] CSV v0.4.3
  [a93c6f00] DataFrames v0.17.1
  [31c24e10] Distributions v0.16.4
  [89b67f3b] ExcelFiles v0.9.1
  [f67ccb44] HDF5 v0.11.0
  [4138dd39] JLD v0.9.1
  [e4e893b0] Mimi v0.6.4
  [76087f3c] NLopt v0.5.1
  [2913bbd2] StatsBase v0.29.0
  [0ae4a718] VegaDatasets v0.5.0
  [112f6efa] VegaLite v0.6.0
```

---

<div class="post-metadata">

**Author:** ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)\
**Post date:** [March 11, 2019, 11:02pm UTC](https://forum.mimiframework.org/t/make-mcs-defmcs-accept-constrained-distributions/21/31 "2019-03-11T23:02:49Z")

</div>

Alright well to start you should upgrade to Julia v1.1, which is required by `Mimi v0.8.0`, so do that now.

---

<div class="post-metadata">

**Author:** ![hbenveniste](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@hbenveniste](https://forum.mimiframework.org/u/hbenveniste)\
**Post date:** [March 11, 2019, 11:08pm UTC](https://forum.mimiframework.org/t/make-mcs-defmcs-accept-constrained-distributions/21/32 "2019-03-11T23:08:47Z")

</div>

no other way to do it than just downloading directly Julia v1.1 right?

---

<div class="post-metadata">

**Author:** ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)\
**Post date:** [March 11, 2019, 11:20pm UTC](https://forum.mimiframework.org/t/make-mcs-defmcs-accept-constrained-distributions/21/36 "2019-03-11T23:20:01Z")

</div>

For VSCode, when you open it you will probably see this at the bottom:  
 ![25%20PM](https://canada1.discourse-cdn.com/flex031/uploads/mimiframework/original/1X/ecaefda52f6d4a4ecdee4a1b4ca21aa7961c6895.png)

---

<div class="post-metadata">

**Author:** ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)\
**Post date:** [March 11, 2019, 11:26pm UTC](https://forum.mimiframework.org/t/make-mcs-defmcs-accept-constrained-distributions/21/37 "2019-03-11T23:26:30Z")

</div>

If you click on `Julia env: v1.x` you will get a drop down menu like this:

 ![54%20PM](https://canada1.discourse-cdn.com/flex031/uploads/mimiframework/original/1X/befc3ab7235b9e1d398d00697277d27477c18c37.png)

---

<div class="post-metadata">

**Author:** ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)\
**Post date:** [March 11, 2019, 11:26pm UTC](https://forum.mimiframework.org/t/make-mcs-defmcs-accept-constrained-distributions/21/38 "2019-03-11T23:26:36Z")

</div>

Click on the `v1.1` option, and then go delete the folder of `v1.0` to avoid confusion later. Now if you run `cmd + enter` on a line to run it, you should see a command line window and `]` should give you something like ! `(v1.1) pkg>`.

Let me know how all of this goes, happy to help you along. You’ll need to re-add any packages you were using with `]add Mimi; add Distributions` etc.

---

<div class="post-metadata">

**Author:** ![hbenveniste](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@hbenveniste](https://forum.mimiframework.org/u/hbenveniste)\
**Post date:** [March 11, 2019, 11:36pm UTC](https://forum.mimiframework.org/t/make-mcs-defmcs-accept-constrained-distributions/21/39 "2019-03-11T23:36:25Z")

</div>

Yay it works! Thanks all!

---

<div class="post-metadata">

**Author:** ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)\
**Post date:** [March 11, 2019, 11:56pm UTC](https://forum.mimiframework.org/t/make-mcs-defmcs-accept-constrained-distributions/21/40 "2019-03-11T23:56:44Z")

</div>

Oh that’s great news! Let me know if there’s any trouble, I had issues with VSCode reverting to Julia `v1.0` until I (1) changed the binary path and (2) deleted that `environments/v1.0` folder.

[Previous page](https://forum.mimiframework.org/t/make-mcs-defmcs-accept-constrained-distributions/21.md?page=1)
