# Reproducibility of problems in Modelling Toolkit (MTK)

**URL:** <https://discourse.julialang.org/t/reproducibility-of-problems-in-modelling-toolkit-mtk/128216>\
**Category:** Modelling & Simulations\
**Tags:** question, package, modelingtoolkit\
**Created:** [April 19, 2025, 11:29am UTC](https://discourse.julialang.org/t/reproducibility-of-problems-in-modelling-toolkit-mtk/128216 "2025-04-19T11:29:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [April 19, 2025, 11:29am UTC](https://discourse.julialang.org/t/reproducibility-of-problems-in-modelling-toolkit-mtk/128216/1 "2025-04-19T11:29:06Z")

</div>

We are trying to cache the simplified model of an MTK model in a file. Currently we using the `serialize()` function of base Julia.

Observation: The serialized file is different each time we generate it, even if the original DAE system is the same.

Is this to-be-expected? Is there a way to avoid that?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [April 19, 2025, 11:43am UTC](https://discourse.julialang.org/t/reproducibility-of-problems-in-modelling-toolkit-mtk/128216/2 "2025-04-19T11:43:41Z")

</div>

What is different? Can you show the diff?

---

<div class="post-metadata">

**Author:** ![Bart\_van\_de\_Lint](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bart_van_de_lint/32/212161_2.png) [@Bart\_van\_de\_Lint](https://discourse.julialang.org/u/Bart_van_de_Lint)\
**Post date:** [April 20, 2025, 2:39pm UTC](https://discourse.julialang.org/t/reproducibility-of-problems-in-modelling-toolkit-mtk/128216/3 "2025-04-20T14:39:43Z")

</div>

I think this is to be expected if we serialize the `ODEProblem`, as this has runtime-generated functions. I think the file should be the same every time if we serialize the `ODEProblemExpr`.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [April 20, 2025, 3:23pm UTC](https://discourse.julialang.org/t/reproducibility-of-problems-in-modelling-toolkit-mtk/128216/4 "2025-04-20T15:23:18Z")

</div>

The RGFs should also be the same expression each time, because (a) it uses the same code path as `ODEProblemExpr` and (b) it’s required for compilation caching that no gensym is used and you get equivalent expressions when repeated.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [April 22, 2025, 4:57pm UTC](https://discourse.julialang.org/t/reproducibility-of-problems-in-modelling-toolkit-mtk/128216/5 "2025-04-22T16:57:48Z")

</div>

I could share two .xz files with you, and you could try to create a diff. But I cannot share them here on discourse, because discourse does not allow that. This are binary files, a diff does not tell me anything.

```julia
ufechner@framework:~/repos/KiteModels.jl/data$ ls -la *.xz
-rw-rw-r-- 1 ufechner ufechner 1397856 apr 22 18:37 prob_dynamic_1.11_3_seg.bin.bak.xz
-rw-rw-r-- 1 ufechner ufechner 1396680 apr 22 18:47 prob_dynamic_1.11_3_seg.bin.xz

```

This are MTK problems created from identical input, saved using the Julia base function `serialize()`.

Any suggestion?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [April 22, 2025, 5:44pm UTC](https://discourse.julialang.org/t/reproducibility-of-problems-in-modelling-toolkit-mtk/128216/6 "2025-04-22T17:44:19Z")

</div>

Are the texts the same?

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [April 22, 2025, 5:51pm UTC](https://discourse.julialang.org/t/reproducibility-of-problems-in-modelling-toolkit-mtk/128216/7 "2025-04-22T17:51:01Z")

</div>

I mean, the files are different, how shall I know if the texts are the same? I do not know what you mean with “the texts”.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [April 22, 2025, 5:57pm UTC](https://discourse.julialang.org/t/reproducibility-of-problems-in-modelling-toolkit-mtk/128216/8 "2025-04-22T17:57:17Z")

</div>

ODEProblemExpr gives you a Julia expression. Are the two cases from different expressions?
