
Integrated Debugging of Modelica Models Adrian Pop, Martin Sjölund, Adeel Asghar, Peter Fritzson and Francesco Casella Linköping University Post Print N.B.: When citing this work, cite the original article. Original Publication: Adrian Pop, Martin Sjölund, Adeel Asghar, Peter Fritzson and Francesco Casella, Integrated Debugging of Modelica Models, 2014, Modeling, Identification and Control, (35), 2, 93-107. http://dx.doi.org/10.4173/mic.2014.2.3 Copyright: Norsk Forening for Automatisering (Norwegian Society of Automatic Control) http://www.nfaplassen.no/ Postprint available at: Linköping University Electronic Press http://urn.kb.se/resolve?urn=urn:nbn:se:liu:diva-109729 Modeling, Identification and Control, Vol. 35, No. 2, 2014, pp. 93{107, ISSN 1890{1328 Integrated Debugging of Modelica Models A. Pop 1 M. Sj¨olund 1 A. Asghar 1 P. Fritzson 1 F. Casella 2 1Department of Computer and Information Science, Link¨opingUniversity, 581 83 Link¨oping,Sweden. E-mail: fadrian.pop,martin.sjolund,adeel.asghar,[email protected] 2Dipartimento di Elettronica, Informazione e Bioingegneria, Politecnico di Milanodi Milano, Via Ponzio 34/5, 20133 Milano, Italy. E-mail: [email protected] Abstract The high abstraction level of equation-based object-oriented (EOO) languages such as Modelica has the drawback that programming and modeling errors are often hard to find. In this paper we present integrated static and dynamic debugging methods for Modelica models and a debugger prototype that addresses sev- eral of those problems. The goal is an integrated debugging framework that combines classical debugging techniques with special techniques for equation-based languages partly based on graph visualization and interaction. To our knowledge, this is the first Modelica debugger that supports both equation-based transforma- tional and algorithmic code debugging in an integrated fashion. Keywords: Modelica, Debugging, Modeling and Simulation, Transformations, Equations 1 Introduction mized so heavily that it is hard to tell the origin of an equation during runtime. This work proposes and Advanced development of today's complex products implements a prototype of a method that is efficient requires integrated environments and equation-based with less than one percent overhead, yet manages to object-oriented declarative (EOO) languages such as keep track of all the transformations/operations that Modelica (Fritzson, 2014; Modelica Association, 2012, the compiler performs on the model. 2013) for modeling and simulation. The increased ease Modelica models often contain functions and algo- of use, the high abstraction level, and the expressivity rithm sections with algorithmic code. The fraction of of such languages are very attractive properties. How- algorithmic code is increasing since Modelica, in addi- ever, these attractive properties come with the draw- tion to equation-based modeling, is also used for em- back that programming and modeling errors are often bedded system control code as well as symbolic model hard to find. transformations in applications using the MetaModel- To address these issues we present static (compile- ica language extension. time) and dynamic (run-time) debugging methods for Our earlier work in debuggers for the algorithmic Modelica models and a debugger prototype that ad- subset of Modelica used high-level code instrumenta- dresses several of those problems. The goal is an in- tion techniques which are portable but turned out to tegrated debugging framework that combines classi- have too much overhead for large applications. The cal debugging techniques with special techniques for new dynamic algorithmic code debugger is the first equation-based languages partly based on graph visu- Modelica debugger that can operate without high-level alization and user interaction. code instrumentation. Instead, it communicates with a The static transformational debugging functionality low-level C-language symbolic debugger to directly ex- addresses the problem that model compilers are opti- tract information from a running executable, set and doi:10.4173/mic.2014.2.3 c 2014 Norwegian Society of Automatic Control Modeling, Identification and Control remove breakpoints, etc. This is made possible by the and provides explanations regarding the origin of prob- new bootstrapped OpenModelica compiler which keeps lematic code. The dynamic (run-time) debugging al- track of a detailed mapping from the high level Mod- lows interactive inspection of large executable models, elica code down to the generated C code compiled to stepping through algorithmic parts of the models, set- machine code. ting breakpoints, inspecting and modifying data struc- The dynamic algorithmic code debugger is opera- tures and the execution stack. tional, supports both standard Modelica data struc- An integrated approach is proposed where the map- tures and tree/list data structures, and operates effi- ping from generated code to source code provided by ciently on large applications such as the OpenModelica the static transformational debugging is used by the compiler with more than 200 000 lines of code. dynamic debugger to relate run-time errors to the The attractive properties of high-level object- original model sources. To our knowledge no other oriented equation-based languages come with the draw- open-source or commercial Modelica tool currently back that programming and modeling errors are often supports static transformational debugging and algo- hard to find. For example, in order to simulate models rithmic code debugging of an equation-based object- efficiently, Modelica simulation tools perform a large oriented (EOO) language. amount of symbolic manipulation in order to reduce The paper is structured as follows: Section2 gives the complexity of models and prepare them for effi- a background to debugging techniques, Section3 an- cient simulation. By removing redundancy, the gener- alyzes sources of errors and faults, Section4 proposes ation of simulation code and the simulation itself can an integrated static and dynamic debugging approach, be sped up significantly. The drawback of this perfor- Section5 presents the static transformational debug- mance gain is that error-messages often are not very ging method and implementation, whereas Section6 user-friendly due to symbolic manipulation, renaming presents the algorithmic code debugging functionality. and reordering of variables and equations. For exam- Conclusions and future work are given in Section7. ple, the following error message says nothing about the variables involved or its origin: 2 Debugging techniques for EOO Error solving non-linear system 2 Languages time = 0.002 residual[0] = 0.288956 In the context of debugging declarative equation-based x[0] = 1.105149 object-oriented (EOO) languages such as Modelica, residual[1] = 17.000400 both the static (compile-time) and the dynamic (run- x[1] = 1.248448 time) aspects have to be addressed. ... The static aspect of debugging EOO languages deals with inconsistencies in the underlying system of equa- It is usually hard for a typical user of the Modelica tions: tool to determine what symbolic manipulations have been performed and why. If the tool only emits a bi- 1. Errors related to the transformations of the mod- nary executable this is almost impossible. Even if the els to an optimized flattened system of equations tool emits source code in some programming language suitable for numeric solution. For example sym- (typically C), it is still quite hard to understand what bolic solutions leading to division by a constant kind of equation system was produced by the symbolic zero stemming from a singular system of equations transformation process. This makes it difficult to un- or (very rarely) errors in the symbolic transforma- derstand where the model can be changed in order to tions themselves. improve the speed or stability of the simulation. Some tools allow the user to export the description of the 2. Overconstrained models (too many equations) or translated system of equations (Casella et al., 2009; underconstrained models (too few equations). The Parrotto et al., 2010), but this is not enough. Af- number of variables needs to be equal to the equa- ter symbolic manipulation, the resulting equations no tions is required for solution. longer need to contain the same variables or structure The dynamic (run-time) aspect of debugging EOO lan- as the original equations. guages addresses run-time errors that may appear due This work proposes and develops a combination of to faults in the model: static and dynamic debugging techniques to address these problems. The static (compile-time) transforma- 1. model configuration: when the parameters values tional debugging efficiently traces the symbolic trans- and start attributes for the model simulation are formations throughout the model compilation process incorrect. 94 Pop et.al., \Integrated Debugging of Modelica Models" 2. model specification: when the equations and algo- If some equation can be solved symbolically, without rithm sections that specify the model behavior are resorting to numerical solvers, then the symbolic solu- incorrect. tion code should be equipped with diagnostics to han- dle errors as well. 3. algorithmic code: when the functions called from In the next section we give causes of errors that can equations return incorrect results. appear during the model simulation. Methods for both static and dynamic (run-time) de- 3.1 Errors in the evaluation of expressions bugging of EOO languages such as Modelica have
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages16 Page
-
File Size-