Experimentation with a Prototype OpenModelica Compiler in ...

23
Experimentation with a Prototype OpenModelica Compiler in Julia John Tinnerholm, Adrian Pop, and Martin Sjölund

Transcript of Experimentation with a Prototype OpenModelica Compiler in ...

Page 1: Experimentation with a Prototype OpenModelica Compiler in ...

Experimentation with a Prototype OpenModelica Compiler in JuliaJohn Tinnerholm, Adrian Pop, and Martin Sjölund

Page 2: Experimentation with a Prototype OpenModelica Compiler in ...

Motivation

Page 3: Experimentation with a Prototype OpenModelica Compiler in ...

Motivation

• Integration with the Julia ecosystem

• Provide a standard-compliant Modelica environment in Julia

– Larger OpenSource community

– Supporting VSS/Multi-mode DAE models within standard Modelica

• Outsourcing implementation language development

• Enable separate use of OpenModelica Compiler packages

– Utilizing Julia package manager

– Tool development without a monolithic compiler

2020-02-03 3Experimentation with a Prototype OpenModelica Compiler in Julia

Page 4: Experimentation with a Prototype OpenModelica Compiler in ...

Julia

• A new programming language by Jeff Bezanson, Stefan Karpinski and Viral B. Shah

• A language for Numerical and Symbolic Computation

• Many libraries for Linear Algebra, Differential Equations, Fast Fourier Transforms etc.

• H. Wilkinson Prize for Numerical Software in 2019

• Already in use for equation-based-modelling, Modia.jl

– Support for Multi-Mode DAE Models, however non standard-compliant

• OMJulia for interoperability with OpenModelica

2020-02-03 4Experimentation with a Prototype OpenModelica Compiler in Julia

Page 5: Experimentation with a Prototype OpenModelica Compiler in ...

The MetaModelica to Julia translator

Page 6: Experimentation with a Prototype OpenModelica Compiler in ...

The MetaModelica to Julia translator

• Translated from the old OpenModelica frontend

• Maps MetaModelicapackages to Julia modules

• Difficulties with certain syntactical constructs

– Circular packages

– Uniontypes with static methods

2020-02-03 6Experimentation with a Prototype OpenModelica Compiler in Julia

uniontype Equationrecord EQ_IF

Exp ifExp;list<EquationItem> equationTrueItems;list<tuple<Exp,list<EquationItem>>> elseIfBranches;list<EquationItem> equationElseItems;

end EQ_IF;

record EQ_EQUALSExp leftSide;Exp rightSide;

end EQ_EQUALS;// ...

Page 7: Experimentation with a Prototype OpenModelica Compiler in ...

The MetaModelica to Julia translator

2020-02-03 7Experimentation with a Prototype OpenModelica Compiler in Julia

• Continuous integration of features

• Supporting parallel development of the existing compiler

Page 8: Experimentation with a Prototype OpenModelica Compiler in ...

MetaModelica via Metaprogramming

• Julia’s AST macros makes language extensions easy

• Structural elements such as inheritance, uniontypes match and matchcontinue are provided

2020-02-03 8Experimentation with a Prototype OpenModelica Compiler in Julia

@Uniontype Equation begin@Record EQ_IF beginifExp::ExpequationTrueItems::List{EquationItem}elseIfBranches::List{Tuple{Exp,List{EquationItem}}}

equationElseItems::List{EquationItem}end

@Record EQ_EQUALS beginleftSide::ExprightSide::Expend# ...end

uniontype Equationrecord EQ_IFExp ifExp;list<EquationItem> equationTrueItems;list<tuple<Exp,list<EquationItem>>> elseIfBranches;list<EquationItem> equationElseItems;

end EQ_IF;

record EQ_EQUALSExp leftSide;Exp rightSide;

end EQ_EQUALS;// ...

end

Page 9: Experimentation with a Prototype OpenModelica Compiler in ...

MetaModelica.jl

• Compiler runtime

– MetaModelica.jl

– Pattern-matching

– Immutable List

– Uniontypes

• Possible to use as a standalone package

2020-02-03 9Experimentation with a Prototype OpenModelica Compiler in Julia

@Uniontype Equation begin@Record EQ_IF beginifExp::ExpequationTrueItems::List{EquationItem}elseIfBranches::List{Tuple{Exp,List{EquationItem}}}

equationElseItems::List{EquationItem}end

@Record EQ_EQUALS beginleftSide::ExprightSide::Expend# ...end

Page 10: Experimentation with a Prototype OpenModelica Compiler in ...

OMParser.jl

• The AST is constructed in ANTLR using C the foreign function interface of Julia

– Capable of parsing any Modelica library (tested with MSL 3.2.3)

• Somewhat smaller memory footprint

– Better data sharing

2020-02-03 10

Page 11: Experimentation with a Prototype OpenModelica Compiler in ...

OMCompiler.jl

• Translated from the current frontend

• Able to parse and translate:

– Absyn IR

– SCode IR

– DAE IR

2020-02-03 11Experimentation with a Prototype OpenModelica Compiler in Julia

Page 12: Experimentation with a Prototype OpenModelica Compiler in ...

OMCompiler.jl

• Generated Julia DAE IR compatible with existingMetaModelica DAE IR

• Somewhat smaller memory footprint

2020-02-03 12Experimentation with a Prototype OpenModelica Compiler in Julia

dae = DAE.DAE_LIST(Cons {

DAE.Element

}(DAE.COMP("HelloWorld", Cons {

DAE.Element

}(DAE.VAR(DAE.CREF_IDENT("x", DAE.T_REAL(Nil {

Any

}()), Nil {

Any

}()), DAE.VARIABLE(), DAE.BIDIR(), DAE.NON_PARALLEL(), DAE.PUBLIC(), DAE.T_REAL(Nil {

Any

}()), nothing, Nil {

Any

...

Any

}()), SOME {

SCode.Comment

} (SCode.COMMENT(nothing, nothing))), Nil {

Any

}()))

Page 13: Experimentation with a Prototype OpenModelica Compiler in ...

Future work

Page 14: Experimentation with a Prototype OpenModelica Compiler in ...

Future work

• Translating the new high performance frontend

• A Simulation runtime

• OMBackend.jl

• Investigate possible integration with:

– Modia.jl

– DifferentialEquations.jl

2020-02-03 14Experimentation with a Prototype OpenModelica Compiler in Julia

Page 15: Experimentation with a Prototype OpenModelica Compiler in ...

About the dragon?

Page 16: Experimentation with a Prototype OpenModelica Compiler in ...

Future work

• Dragon

– LLVM

• Cogwheels

– Modelica

• Colors?

– Julia

2020-02-03 16Experimentation with a Prototype OpenModelica Compiler in Julia

Page 17: Experimentation with a Prototype OpenModelica Compiler in ...

www.liu.se

Questions?

Page 18: Experimentation with a Prototype OpenModelica Compiler in ...

References

Elmqvist, H., Henningsson, T., & Otter, M. (2017). Innovations for Future Modelica. Proceedings of the 12th International Modelica Conference, Prague, Czech Republic, May 15-17, 2017, 132, 693–702. https://doi.org/10.3384/ecp17132693

Zimmer, D. (2010). Equation-based modeling of variable-structure systems. (18924), 219. https://doi.org/10.3929/ethz-a-006053740

2020-02-03 18Experimentation with a Prototype OpenModelica Compiler in Julia

Page 19: Experimentation with a Prototype OpenModelica Compiler in ...

References

Lie, B., Palanisamy, A., Mengist, A., Buffoni, L., Sjölund, M., Asghar, A., … Fritzson, P. (2019). OMJulia: An OpenModelica API for Julia-ModelicaInteraction. Proceedings of the 13th International Modelica Conference, Regensburg, Germany, March 4–6, 2019, 157, 699–708. https://doi.org/10.3384/ecp19157699

2020-02-03 19Experimentation with a Prototype OpenModelica Compiler in Julia

Page 20: Experimentation with a Prototype OpenModelica Compiler in ...

References

Casella, F. (2015). Simulation of Large-Scale Models in Modelica: State of the Art and Future Perspectives. Proceedings of the 11th International Modelica Conference, Versailles, France, September 21-23, 2015, 118, 459–468. https://doi.org/10.3384/ecp15118459

Modeling, V., & Höger, C. (n.d.). Elaborate Control.

VADIM I. UTKIN. (1977). Variable Structure Systems with Sliding Modes. IEEE Transactions on Automatic Control, 22(2), 212–222.

2020-02-03 20Experimentation with a Prototype OpenModelica Compiler in Julia

Page 21: Experimentation with a Prototype OpenModelica Compiler in ...

References

Benveniste, A., Ghorbal, K., Caillaud, B., Otter, M., Elmqvist, H., & Pouzet, M. (2017). Structural analysis of multi-mode DAE systems. HSCC 2017 -Proceedings of the 20th International Conference on Hybrid Systems: Computation and Control (Part of CPS Week), 253–263. https://doi.org/10.1145/3049797.3049806

2020-02-03 21Experimentation with a Prototype OpenModelica Compiler in Julia

Page 22: Experimentation with a Prototype OpenModelica Compiler in ...

References

Benveniste, A., Ghorbal, K., Caillaud, B., Otter, M., Elmqvist, H., & Pouzet, M. (2017). Structural analysis of multi-mode DAE systems. HSCC 2017 -Proceedings of the 20th International Conference on Hybrid Systems: Computation and Control (Part of CPS Week), 253–263. https://doi.org/10.1145/3049797.3049806

Lattner, C., & Adve, V. (2004, March). LLVM: A compilation framework for lifelong program analysis & transformation. In International Symposium on Code Generation and Optimization, 2004. CGO 2004. (pp. 75-86). IEE

2020-02-05 22Experimentation with a Prototype OpenModelica Compiler in Julia

Page 23: Experimentation with a Prototype OpenModelica Compiler in ...

References

https://github.com/OpenModelica/MetaModelica.jl

https://github.com/JKRT/OMCompiler.jl

https://github.com/OpenModelica/Absyn.jl

2020-02-03 23Experimentation with a Prototype OpenModelica Compiler in Julia