# From Modelica source code to Julia

**URL:** <https://discourse.julialang.org/t/from-modelica-source-code-to-julia/80837>\
**Category:** Modelling & Simulations\
**Tags:** fmiexport\
**Created:** [May 10, 2022, 7:24pm UTC](https://discourse.julialang.org/t/from-modelica-source-code-to-julia/80837 "2022-05-10T19:24:03Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![mzhenirovskyy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzhenirovskyy/32/7549_2.png) [@mzhenirovskyy](https://discourse.julialang.org/u/mzhenirovskyy)\
**Post date:** [May 10, 2022, 7:24pm UTC](https://discourse.julialang.org/t/from-modelica-source-code-to-julia/80837/1 "2022-05-10T19:24:03Z")

</div>

Hi All,

Is there any way to import a Model from Modelica-file to Julia lang? I mean I have the model in the Modelica that can be simulated by Dymola. Of course, I can get the fmu compiled file and load it to Julia.

But can I get a Model from the Modelica source code? I’m looking for something like a Modelica lang parser…

Thanks!

---

<div class="post-metadata">

**Author:** ![Sciemon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sciemon/32/20897_2.png) [@Sciemon](https://discourse.julialang.org/u/Sciemon)\
**Post date:** [May 10, 2022, 7:34pm UTC](https://discourse.julialang.org/t/from-modelica-source-code-to-julia/80837/2 "2022-05-10T19:34:05Z")

</div>

Something like that is described in the paper [OpenModelica.jl: A modular and extensible Modelica compiler framework in Julia targeting ModelingToolkit.jl | Modelica Conferences](https://ecp.ep.liu.se/index.php/modelica/article/view/186). However I cannot find the OpenModelica.jl repository although paper says it’s open source.

---

<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:** [May 11, 2022, 4:48am UTC](https://discourse.julialang.org/t/from-modelica-source-code-to-julia/80837/3 "2022-05-11T04:48:48Z")

</div>

> **[GitHub - OpenModelica/OMJulia.jl: Julia scripting OpenModelica interface](https://github.com/OpenModelica/OMJulia.jl)**
>
> Julia scripting OpenModelica interface. Contribute to OpenModelica/OMJulia.jl development by creating an account on GitHub.

Is related but probably not what you are looking for. I guess what you are looking for is closed source or not yet published.

---

<div class="post-metadata">

**Author:** ![mzhenirovskyy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzhenirovskyy/32/7549_2.png) [@mzhenirovskyy](https://discourse.julialang.org/u/mzhenirovskyy)\
**Post date:** [May 11, 2022, 5:01am UTC](https://discourse.julialang.org/t/from-modelica-source-code-to-julia/80837/4 "2022-05-11T05:01:23Z")

</div>

Yep,  
I’m looking for a way to import the equations from the Modelica source to Julia to make it possible to do gradient-based (Jacobian-based) optimization, sensitivity analysis, etc.

---

<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:** [May 11, 2022, 5:05am UTC](https://discourse.julialang.org/t/from-modelica-source-code-to-julia/80837/5 "2022-05-11T05:05:28Z")

</div>

So just try to contact the authors of that paper directly…

---

<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:** [May 11, 2022, 1:36pm UTC](https://discourse.julialang.org/t/from-modelica-source-code-to-julia/80837/6 "2022-05-11T13:36:52Z")

</div>

It’s not released yet. The packages for it are all private right now. The lead author’s thesis defense is next month and it should follow that, but I assume he’s pretty busy getting it all done right now 😅.

---

<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:** [May 11, 2022, 1:38pm UTC](https://discourse.julialang.org/t/from-modelica-source-code-to-julia/80837/7 "2022-05-11T13:38:46Z")

</div>

That’s a Julia interface to OpenModelica, which is different from what (was) called OpenModelica.jl which is a Modelica parser to ModelingToolkit intermediate representation.

---

<div class="post-metadata">

**Author:** ![Sciemon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sciemon/32/20897_2.png) [@Sciemon](https://discourse.julialang.org/u/Sciemon)\
**Post date:** [May 11, 2022, 2:46pm UTC](https://discourse.julialang.org/t/from-modelica-source-code-to-julia/80837/8 "2022-05-11T14:46:35Z")

</div>

I look forward to that release. If the many Modelica libraries became available in MTK in a usable (maybe even modifiable) form, this would be huge.

---

<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:** [May 11, 2022, 3:03pm UTC](https://discourse.julialang.org/t/from-modelica-source-code-to-julia/80837/9 "2022-05-11T15:03:15Z")

</div>

The other thing is that the ModelingToolkit Standard Library is becoming fairly complete to the Modelica Standard Library.

> **[GitHub - SciML/ModelingToolkitStandardLibrary.jl: A standard library of...](https://github.com/SciML/ModelingToolkitStandardLibrary.jl)**
>
> A standard library of components to model the world and beyond - GitHub - SciML/ModelingToolkitStandardLibrary.jl: A standard library of components to model the world and beyond

So while the auto-translation tooling is neat, this will likely be the direction more people will want to go to reduce maintenance and improve flexibility. We’re making sure that the pieces that overlap with the MSL are close enough to make translations simple.

---

<div class="post-metadata">

**Author:** ![Sciemon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sciemon/32/20897_2.png) [@Sciemon](https://discourse.julialang.org/u/Sciemon)\
**Post date:** [May 11, 2022, 3:08pm UTC](https://discourse.julialang.org/t/from-modelica-source-code-to-julia/80837/10 "2022-05-11T15:08:53Z")

</div>

Besides the standard library, there are other extensive domain specific Modelica libraries where translation would help a lot. But I don’t know whether the mentioned “translator” can only translate the standard library or was only tested for the standard library in the paper, but is generally applicable to any Modelica model or whether it makes any difference.

---

<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:** [May 11, 2022, 3:24pm UTC](https://discourse.julialang.org/t/from-modelica-source-code-to-julia/80837/11 "2022-05-11T15:24:54Z")

</div>

> [@Sciemon](#):
>
> Besides the standard library, there are other extensive domain specific Modelica libraries where translation would help a lot.

That’s why some of the stuff we’re working on as part of JuliaSim are proprietary domain-specific libraries, similar to what has been developed in the Modelica universe. Of course, our competitive advantage is that we have complete control over the symbolic and numeric stack to make sure the entire system is optimized for these domains, so 😉 more details on this of course coming later. But yes, the ModelingToolkitStandardLibrary.jl repo serves as a lighthouse to show other developers a good way to build MTK-based component libraries, and then we are building a bunch of such domain-specific component libraries for areas where we see we can innovate and have clear customers.

The translator is something that could in theory work in some cases, for example may on the Modelica Buildings library, but I’m not sure. Some of those libraries are using such specific features that they are supported by Dymola but not OpenModelica, so I think it would take quite a bit to get the more difficult libraries to work in such a system. But we are watching closely how this is evolving (and helping out of course), so we’ll have to see how well the transpilation can do.

---

<div class="post-metadata">

**Author:** ![Sciemon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sciemon/32/20897_2.png) [@Sciemon](https://discourse.julialang.org/u/Sciemon)\
**Post date:** [May 12, 2022, 4:15pm UTC](https://discourse.julialang.org/t/from-modelica-source-code-to-julia/80837/12 "2022-05-12T16:15:33Z")

</div>

I hope that JuliaSim will be a success!

In my domain (power system dynamics) it is actually the industry who pushes the open source approach. Power systems are extremely large, complicated (more and more distributed renewable generation) and operated by various entities (system operators). The interconnected parts interfere with each other. So system operators aim to have open source models to guarantee a certain standard and reliable simulation outcome. It would be chaos (well actually is atm) if each of them uses a different proprietary and closed software.

So far these open source efforts use mainly OpenModelica (though there are efforts in Julia such as PowerSimulationsDynamics.jl). Having a “translator” helps as a first step to switch to SciML and MTK. Whether this is sustainable in the long run in terms of maintenance remains to be seen, but it is at least an argument that can be made when trying to convince OpenModelica users to switch.

---

<div class="post-metadata">

**Author:** ![mzhenirovskyy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzhenirovskyy/32/7549_2.png) [@mzhenirovskyy](https://discourse.julialang.org/u/mzhenirovskyy)\
**Post date:** [May 12, 2022, 4:41pm UTC](https://discourse.julialang.org/t/from-modelica-source-code-to-julia/80837/13 "2022-05-12T16:41:51Z")

</div>

I wish JuliaSim success!

In my area, we have the different (multiphysics) models mostly done in Modelica/Dymola (we use standard Modelica libs) and our main challenge is the optimization of such models (parameters estimations, etc), so it will be great if we can use very advanced Julia mathematical optimization libs.

---

<div class="post-metadata">

**Author:** ![Sciemon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sciemon/32/20897_2.png) [@Sciemon](https://discourse.julialang.org/u/Sciemon)\
**Post date:** [July 1, 2023, 12:54pm UTC](https://discourse.julialang.org/t/from-modelica-source-code-to-julia/80837/14 "2023-07-01T12:54:17Z")

</div>

Are there any updates on the Modelica to Julia compiler/transpiler, i.e. transpiling Modelica code to ModelingToolkit?

---

<div class="post-metadata">

**Author:** ![JKRT](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jkrt/32/37974_2.png) [@JKRT](https://discourse.julialang.org/u/JKRT)\
**Post date:** [April 16, 2024, 11:17am UTC](https://discourse.julialang.org/t/from-modelica-source-code-to-julia/80837/15 "2024-04-16T11:17:23Z")

</div>

Hello,

I am the author of OM.jl. Things are proceeding I am currently working on some new features and standard library functionality, quite recently I managed to get a large subset of the MSL working in the frontend. I have some of this features on experimental branches at the moment. If you are interested in using testing them send me an email and I can help you set it up!

---

<div class="post-metadata">

**Author:** ![mzhenirovskyy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzhenirovskyy/32/7549_2.png) [@mzhenirovskyy](https://discourse.julialang.org/u/mzhenirovskyy)\
**Post date:** [April 17, 2024, 2:06am UTC](https://discourse.julialang.org/t/from-modelica-source-code-to-julia/80837/16 "2024-04-17T02:06:26Z")

</div>

Hi @JKRT , my target pipeline is to convert Modelica files to Julia and then use gradient-based optimization on Julia’s side. Does your Library support gradient-based calculations from Julia based on the ReverseDiff/ForwardDiff?
