Contributions to Meta-Modeling Tools and Methods Adrian Pop Programming Environments Laboratory

advertisement
Contributions to Meta-Modeling
Tools and Methods
Adrian Pop
Programming Environments Laboratory
Outline
ƒ Product Design Environments
ƒ Meta-Modeling
ƒ Modelica Meta-Model
ƒ Invasive Composition of Modelica
ƒ Model-driven Product Design using Modelica
ƒ Meta-Programming
ƒ Debugging of Natural Semantics Specifications
ƒ Conclusions and Future Work
2
Domain Specific Environments
Gearbox
Complex
physical
products
demultiplex
C8=0.12
Difficult
manual
process
C4=0.12
bearing2
bearing1
C6=0.12
bearing4
Compilers
C12=0.12
Design
environments
Model editors
shaftS=2e-3
shaftS1=2e-3
S
S
Debuggers
C5=0.12
C11=0.12
planetary1=110/50
planetary2=110/50
planetary3=120/44
Simulators
3
Research Objectives
ƒ Context
ƒ Model-driven product design environments
ƒ Modeling and simulation
ƒ Modelica Framework
ƒ Objective
ƒ Efficient development of such environments
ƒ Meta-modeling and meta-programming
tools and methods
4
Modelica
C4=0.12
bearing2
bearing1
C12=0.12
bearing4
C6=0.12
Declarative language
Multi-domain modeling
Everything is a class
Visual component
programming
C8=0.12
ƒ
ƒ
ƒ
ƒ
demultiplex
ƒ Modelica
shaftS=2e-3
shaftS1=2e-3
S
S
C5=0.12
C11=0.12
planetary1=110/50
planetary2=110/50
planetary3=120/44
ƒ Modelica Association
ƒ http://www.modelica.org
5
Meta-Modeling
World
The Modeling Space
Meta-Meta Model
Meta Model
Model
Physical system
6
Meta-Programming
MetaModelica and
Natural Semantics
Specification
formalisms
Abstraction
Meta- Meta Model
Meta-Model1
Model1
Model2
Meta-Model2
...
Model3
Modelica
language
specifications
Modelica
models
Meta-programming:
transformation
7
Outline
ƒ Product Design Environments
ƒ Meta-Modeling
ƒ Modelica Meta-Model
ƒ Purpose
ƒ Definition and Applications
ƒ Problems
ƒ Invasive Composition of Modelica
ƒ Model-driven Product Design using Modelica
ƒ Meta-Programming
ƒ Debugging of Natural Semantics Specifications
ƒ Conclusions and Future Work
8
Modelica Community
ƒ Fast growing model base
ƒ Needs flexible stand-alone tools for:
ƒ
ƒ
ƒ
ƒ
ƒ
ƒ
analysis of models (checkers and validators)
pretty printing (un-parsing)
interchange with other modeling languages
query and transformation of models
imposing code style guidelines
documentation generation (Html, SVG, MathML, etc)
Need of better support:
ƒ easy access to the language structure
ƒ interoperability, flexibility
9
Modelica Meta-Model
ƒ Store the structure (Abstract Syntax) of the
Modelica language using an alternative
representation
ƒ Create tools that use this alternative
representation
ƒ The alternative representation should
ƒ be easy accessible from any programming language
ƒ be easy to transform, query and manipulate
ƒ Support validation through a meta-model
XML has all these properties
10
ModelicaXML Representation
Modelica
code
Modelica Parser
Modelica
XML
class Test "comment"
modelicaxml
Real x;
Real xdot;
definition
equation
xdot = der(x);
component
end Test;
equation
component
<modelicaxml>
<definition ident= "Test"
comment="comment">
<component ident="x" type="Real"
visibility="public" />
<component ident="xdot" type="Real"
visibility="public" />
<equation>...</equation>
</definition>
</modelicaxml>
11
Validation using Modelica Meta-Model
ƒ provides a vocabulary for
creating models
ƒ imposes constraints over
the model structure
ƒ is used to validate models
modelicaxml
definition
equation
component
equation
12
ModelicaXML Representation - Applications
ƒ Applications of ModelicaXML Representation
ƒ
ƒ
ƒ
ƒ
ƒ
Interoperability and transformation
Easy access from any programming language
Query facilities
Documentation generation
Validation of models using the meta-model
13
Outline
ƒ Product Design Environments
ƒ Meta-Modeling
ƒ Modelica Meta-Model
ƒ Invasive Composition of Modelica
ƒ Invasive Software Composition
ƒ Modelica Composition
ƒ Applications
ƒ Model-driven Product Design using Modelica
ƒ Meta-Programming
ƒ Debugging of Natural Semantics Specifications
ƒ Conclusions and Future Work
14
Invasive Software Composition
ƒ Composition of black
box components
ƒ Hard to adapt
components to context
ƒ Generates possibly
inefficient systems
ƒ Invasive Software Composition
ƒ Composition system can see inside the components
ƒ Components are hidden behind a composition interface
Components are composed using a composition language
ƒ Components can be configured by changing their actual
code at variation points (boxes and hooks) defined by the
component model
15
Invasive Composition for Modelica
The Compost System
Composition
Programs
ModelicaComponent Model
Composed
System
ModelicaXML
Template
Components
Defines
ƒModelicaBoxes
ƒModelicaHooks
Modelica Models
ƒ The benefit of Invasive Modelica Composition
ƒ
ƒ
ƒ
ƒ
Generation of different version of models from product specifications
Automatic configuration of models using external sources
Fine grain support for library developers
Refactoring, reverse engineering, etc
16
Modelica Component Model – Boxes
XMLBox
Defines a set of templates
for each language structure
ModelicaXMLBox
ModelicaContainer
0..*
ModelicaElement
ModelicaComponent
ModelicaClass
ModelicaType
ModelicaModel
ModelicaPackage
ModelicaEquationSection
ModelicaRecord
ModelicaFunction
ModelicaAlgorithmSection
ModelicaBlock
ModelicaConnector
17
Example Box Hierarchy
<definition ident="Engine" restriction="class">
<component visibility="public” variability="parameter"
type="Integer" ident="cylinders">
<modification_equals>
<integer_literal value="4"/>
</modification_equals>
</component>
<component visibility="public" type="Cylinder" ident="c">
<array_subscripts>
<component_reference ident="cylinders"/>
</array_subscripts>
</component>
</definition>
class Engine
ModelicaClass
ModelicaComponent
parameter Integer
cylinders = 4;
Cylinder c[cylinders];
end Engine;
ModelicaComponent
18
Modelica Component Model – Hooks
Hook
DeclaredHook
ImplicitHook
XMLImplicitHook
XMLDeclaredHook
ModelicaModifierHook
ModelicaParameterHook
ModelicaRealHook
Other Modelica Hooks
ModelicaIntegerHook
ModelicaStringHook
19
Example: Hooks
<component visibility="public” variability="parameter"
type="Integer" ident="cylinders">
<modification_equals>
<integer_literal value="4"/>
ModelicaParameterHook
</modification_equals>
name
</component>
parameter Integer
cylinders = 4;
value
<definition ident=”NewEngine" restriction="class">
<extends type=”Engine”>
class NewEngine
....
extends Engine;
</definition>
....
end NewEngine;
<definition ident=”Engine” restriction="class">
<extract>
<component>..</component> ...
</extract>
</definition>
20
Composition Programs: Mixin
ModelicaCompositionSystem cs =
new ModelicaCompositionSystem();
ModelicaClass resultBox =
cs.createModelicaClass(”Result.mo.xml”);
ModelicaClass firstMixin =
cs.createModelicaClass(”Class1.mo.xml”);
ModelicaClass secondBox =
cs.createModelicaClass(”Class2.mo.xml”);
resultBox.mixin(firstMixin);
resultBox.mixin(secondMixin);
resultBox.print();
21
Outline
ƒ Product Design Environments
ƒ Meta-Modeling
ƒ Modelica Meta-Model
ƒ Invasive Composition of Modelica
ƒ Model-driven Product Design using Modelica
ƒ Product Design based on Function-Means decomposition
ƒ Integration with Modelica for Early Design Validation
ƒ Meta-Programming
ƒ Debugging of Natural Semantics Specifications
ƒ Conclusions and Future Work
22
Model-Driven Product Design
ƒ Product design
ƒ product concept modeling and evaluation
ƒ physical modeling and simulation
ƒ Need for integration of
ƒ conceptual modeling tools and
ƒ modeling and simulation tools
23
Example: design phases of an Aircraft Product
ƒ Aircraft conceptual model in FMDesign
ƒ decomposition of the aircraft into functions and
means
ƒ mapping between means and Modelica
simulation components
ƒ simulation of various design choices
ƒ choosing the best design choice using the
simulation results
24
FMDesign – Conceptual Product Design
Courtesy of Olof Johansson. Developed in cooperation with Peter Krus, IKP
25
Simulation Components for an Aircraft Product
26
A Framework for Product Design
27
Framework Integration Tools
ƒ ModelicaDB – Modelica Model Database
ƒ is populated with simulation models by importing their
ModelicaXML representation
ƒ is a simulation models repository
ƒ provides search and organizational features
ƒ flexibility, scalability and collaborative development
28
Framework Integration Tools (cont)
ƒ The Selection and Configuration Tool
ƒ searches ModelicaDB for simulation models
ƒ calls modeling tools for creating/editing simulation
models
ƒ configuration dialogs for selected simulation models
for specific means implementation
ƒ The Automatic Model Generator Tool
ƒ generates Modelica models of the product
ƒ calls external simulation tools for simulation
ƒ feeds the simulation results back to the designer to
help him/her choose the best design choice
29
Architecture Overview
F = Function
M = Means
Requirements
Database
Product Concept
Design Tool
(FMDESIGN)
Reference Links
Means
Evaluations
Product Concept Design
Database
F1
M1a
F1a.1
F1a.2
M1b
Operation
Cases
M1c
Engineering
Design
System X
F1a.3
Selection and Configuration
Tool
Simulation
Evaluation
Optimisation
Automatic
Model
Generator
Tool
ModelicaXML
Generated
Models
Modelica
Simulation
Source code
Modelica Model
Database
30
Outline
ƒ Product Design Environments
ƒ Meta-Modeling
ƒ Modelica Meta-Model
ƒ Invasive Composition of Modelica
ƒ Model-driven Product Design using Modelica
ƒ Meta-Programming
ƒ Debugging of Natural Semantics Specifications
ƒ Natural Semantics and Relational Meta-Language
ƒ Debugging framework
ƒ Conclusions and Future Work
31
ModelicaXML Representation - Problems
ƒ Problems
ƒ XML can only express syntax
ƒ No easy way to automatically handle semantics
ƒ Possible solutions when expressing semantics
ƒ use markup languages developed by Semantic Web to
express some of the Modelica semantics
ƒ use other formalisms like Natural Semantics
32
Meta-Programming
ƒ Meta-Programs
ƒ programs that manipulate other programs
ƒ Natural Semantics, a formalism widely used for
specification of programming language aspects
ƒ type systems
ƒ static, dynamic and translational semantics
ƒ few implementations in real systems
ƒ Relational Meta-Language (RML)
ƒ a system for generating efficient executable code from
Natural Semantics specifications
ƒ fast learning curve, used in teaching and specification
of languages such as: Java, Modelica, MiniML, etc.
ƒ previously no support for debugging
33
Natural Semantics vs. Relational Meta-Language
Natural Semantics formalism
integers:
v ∈ Int
expressions (abstract syntax):
e ∈ Exp ::= v
| e1 + e 2
| e1 − e 2
| e1* e 2
| e1 / e 2
| −e
(1) v ⇒ v
(2)
Relational Meta-Language
module exp1:
(* Abstract syntax of language Exp1 *)
datatype Exp = INTconst of int
| ADDop of Exp * Exp
| SUBop of Exp * Exp
| MULop of Exp * Exp
| DIVop of Exp * Exp
| NEGop of Exp
relation eval: Exp => int
end
relation eval: Exp => int =
axiom eval(INTconst(ival)) => ival
rule eval(e1) => v1 & eval(e2) => v2 & v1 + v2 => v3
----------------------------------------------eval( ADDop(e1, e2) ) => v3
rule eval(e1) => v1 & eval(e2) => v2 & v1 - v2 => v3
----------------------------------------------eval( SUBop(e1, e2) ) => v3
...
end (* eval *)
e 1⇒ v 1 e 2 ⇒ v 2 v1+v2 ⇒ v3
e 1+ e 2 ⇒ v 3
34
The Need for RML Debugging
ƒ Facilitate language learning
ƒ run, stop and inspect features
ƒ Large specifications are hard to debug
ƒ Example: OpenModelica compiler
ƒ 43 packages
ƒ 57083 lines of code and counting
ƒ 4054 functions
ƒ 132 data structures
35
Debugger Implementation - Overview
module Dump
with “absyn.rml”
relation dump: Absyn.Program => ()
...
RML
Compiler
External
Program
Database
RML Data Browser
ANSI-C
RML Debugging
Emacs Mode
Linking with the
RML
debugging runtime
Executable
with
Debugging
36
Debugger Implementation - Instrumentation
(* Evaluation semantics of Exp1 *)
relation eval: Exp => int =
axiom eval(INTconst(ival)) => ival
rule
eval(e1) => v1 &
eval(e2) => v2 &
v1 + v2 => v3
--------------------------eval( ADDop(e1, e2) ) => v3
(* Evaluation semantics of Exp1 *)
relation eval: Exp => int =
axiom eval(INTconst(ival)) => ival
rule
...
end (* eval *)
) &
RML.debug_push_in01("e1",e1) &
RML.debug(...) &
eval(e1) => (v1) &
RML.debug_push_out01("v1",v1) &
RML.debug_push_in01("e2",e2) &
RML.debug(...) => () &
eval(e2) => (v2) &
RML.debug_push_out01("v2",v2) &
RML.debug_push_in02("v1",v1,"v2",v2
RML.debug(...) &
RML.int_add(v1,v2) => (v3)
-----------------------------------
---eval(ADDop(e1,e2)) => (v3)
...
end (* eval *)
37
Debugger Functionality (1)
Breakpoints
Stepping and Running
38
Debugger Functionality (2)
ƒ Additional functionality
ƒ viewing status information
ƒ printing backtrace
information (stack trace)
ƒ printing call chain
ƒ setting debugger defaults
ƒ getting help
Examining data
ƒprinting variables
ƒsending variables to an
external browser
39
Browser for RML Data Structures (1)
Variable value
inspection
Current Execution
Point
40
Browser for RML Data Structures (2)
Data structure
browsing
Data structure
definition
41
Conclusions
ƒ Meta-Modeling
ƒ Alternative Modelica Representation (ModelicaXML)
ƒ Conform to a Meta-Model for Modelica
ƒ Invasive Composition of Modelica
ƒ Model configuration and adaptation
ƒ Based on ModelicaXML and a Component Model for Modelica
ƒ Model-driven Product Design using Modelica
ƒ Integration of conceptual product modeling with modeling and
simulation tools
ƒ Flexibility, scalability
ƒ Uses ModelicaXML as a middleware
ƒ Meta-Programming
ƒ Debugging of Natural Semantics Specifications
ƒ large specification debugging (OpenModelica Compiler)
ƒ Debugging of MetaModelica models
42
Future Work
ƒ Meta-Modelica Compiler
ƒ Unified equation-based meta-modeling and meta-programming
specification language for both:
ƒ language models and physical system models
ƒ Work in progress, first version based on RML
ƒ Compilation of a Modelica extended with features such as:
ƒ pattern matching, tree structures, lists, tuples, etc.
ƒ More Meta-Modeling capabilities (constraints on models, etc)
ƒ Improvement of the debugging framework
ƒ Experimenting with an Eclipse-IDE that integrates these tools
ƒ Add new features to the Relational Meta-Language system
43
End
Thank you!
Questions?
44
Resources
ƒ ModelicaXML and ModelicaOWL
ƒ http://www.ida.liu.se/~adrpo/modelica/xml
ƒ http://www.ida.liu.se/~adrpo/modelica/owl
ƒ The Invasive Composition System Compost
ƒ http://www.the-compost-system.org/
ƒ Relational Meta-Language (RML)
ƒ http://www.ida.liu.se/~pelab/rml
ƒ MetaModelica Compiler (MMC)
ƒ http://www.ida.liu.se/~adrpo/mmc
ƒ Licentiate Thesis
ƒ http://www.ida.liu.se/~adrpo/lic
45
Thesis Structure
Meta-Modeling
RML Specification of Modelica
Thesis Structure
Chapter 1 – Introduction
Chapter 2 – ModelicaXML, the Meta-Model of Modelica
Chapter 3 – Invasive Composition of Modelica using COMPOST and ModelicaXML
Chapter 4 – Integration of Product Design Tools with Modeling and Simulation Tools
Chapter 5 – Comparison between Modelica Libraries and Ontologies
Chapter 6 – Debugging framework for RML
Chapter 7 – Related research contributions
Chapter 6
RML
System
Debugging
Product Concept
C Code
Product
Design
Tools
C
Compiler
Composition
Program
Chapter 4
Modelica Database
COMPOST
Open
Modelica
Compiler
Chapter 3
Virtual Product
XML
Tools
ModelicaXML
C Code
Chapter 2
Modelica
Parser
Modelica
C
Compiler
Modeling
and
Simulation
Tools
Modelica
Simulation
Meta-Programming
46
Download