MDE: Modelling the DEVS formalism Yentl Van Tendeloo - - PowerPoint PPT Presentation

mde modelling the devs formalism
SMART_READER_LITE
LIVE PREVIEW

MDE: Modelling the DEVS formalism Yentl Van Tendeloo - - PowerPoint PPT Presentation

MDE: Modelling the DEVS formalism Yentl Van Tendeloo Yentl.VanTendeloo@student.ua.ac.be January 24, 2013 1 / 25 The problem: Difficult to comprehend c l a s s Root ( CoupledDEVS ) : def i n i t ( s e l f ) : CoupledDEVS . i n i t ( s e


slide-1
SLIDE 1

MDE: Modelling the DEVS formalism

Yentl Van Tendeloo Yentl.VanTendeloo@student.ua.ac.be January 24, 2013

1 / 25

slide-2
SLIDE 2

The problem: Difficult to comprehend

c l a s s Root ( CoupledDEVS ) : def i n i t ( s e l f ) : CoupledDEVS . i n i t ( s e l f ) s e l f . gen = s e l f . addSubModel ( Generator ( ) ) s e l f . seg1 = s e l f . addSubModel ( RoadSegment () ) s e l f . seg2 = s e l f . addSubModel ( RoadSegment () ) s e l f . seg3 = s e l f . addSubModel ( RoadSegment () ) s e l f . c o l = s e l f . addSubModel ( C o l l e c t o r () ) s e l f . connectPorts ( s e l f . gen . Q send , s e l f . seg1 . Q recv ) s e l f . connectPorts ( s e l f . gen . car out , s e l f . seg1 . c a r i n ) s e l f . connectPorts ( s e l f . seg1 . Q sack , s e l f . gen . Q rack ) s e l f . connectPorts ( s e l f . seg1 . Q send , s e l f . seg2 . Q recv ) s e l f . connectPorts ( s e l f . seg1 . car out , s e l f . seg2 . c a r i n ) s e l f . connectPorts ( s e l f . seg2 . Q sack , s e l f . seg1 . Q rack ) s e l f . connectPorts ( s e l f . seg2 . Q send , s e l f . seg3 . Q recv ) s e l f . connectPorts ( s e l f . seg2 . car out , s e l f . seg3 . c a r i n ) s e l f . connectPorts ( s e l f . seg3 . Q sack , s e l f . seg2 . Q rack ) s e l f . connectPorts ( s e l f . seg3 . car out , s e l f . c o l . c a r i n )

2 / 25

slide-3
SLIDE 3

The problem: Difficult to comprehend

c l a s s Root ( CoupledDEVS ) : def i n i t ( s e l f ) : CoupledDEVS . i n i t ( s e l f ) s e l f . gen = s e l f . addSubModel ( Generator ( ) ) s e l f . seg1 = s e l f . addSubModel ( RoadSegment () ) s e l f . seg2 = s e l f . addSubModel ( RoadSegment () ) s e l f . seg3 = s e l f . addSubModel ( RoadSegment () ) s e l f . c o l = s e l f . addSubModel ( C o l l e c t o r () ) s e l f . connectPorts ( s e l f . gen . Q send , s e l f . seg1 . Q recv ) s e l f . connectPorts ( s e l f . gen . car out , s e l f . seg1 . c a r i n ) s e l f . connectPorts ( s e l f . seg1 . Q sack , s e l f . gen . Q rack ) s e l f . connectPorts ( s e l f . seg1 . Q send , s e l f . seg2 . Q recv ) s e l f . connectPorts ( s e l f . seg1 . car out , s e l f . seg2 . c a r i n ) s e l f . connectPorts ( s e l f . seg2 . Q sack , s e l f . seg1 . Q rack ) s e l f . connectPorts ( s e l f . seg2 . Q send , s e l f . seg3 . Q recv ) s e l f . connectPorts ( s e l f . seg2 . car out , s e l f . seg3 . c a r i n ) s e l f . connectPorts ( s e l f . seg3 . Q sack , s e l f . seg2 . Q rack ) s e l f . connectPorts ( s e l f . seg3 . car out , s e l f . c o l . c a r i n )

Solution: Graphical representation

2 / 25

slide-4
SLIDE 4

The problem: Different simulators

i n t main ( int , char∗∗ argv ){ adevs : : Digraph<Event∗ > dig ; Generator∗ gen = new Generator () ; RoadSegment∗ seg1 = new RoadSegment ( ) ; RoadSegment∗ seg2 = new RoadSegment ( ) ; RoadSegment∗ seg3 = new RoadSegment ( ) ; C o l l e c t o r ∗ c o l = new C o l l e c t o r ( ) ; dig . add ( gen ) ; dig . add ( seg1 ) ; dig . add ( seg2 ) ; dig . add ( seg3 ) ; dig . add ( c o l ) ; dig . couple ( gen , gen− >Q send , seg1 , seg1− >Q recv ) ; dig . couple ( gen , gen− >car out , seg1 , seg1− >c a r i n ) ; dig . couple ( seg1 , seg1− >Q sack , gen , gen− >Q rack ) ; dig . couple ( seg1 , seg1− >Q send , seg2 , seg2− >Q recv ) ; dig . couple ( seg1 , seg1− >car out , seg2 , seg2− >c a r i n ) ; dig . couple ( seg2 , seg2− >Q sack , seg1 , seg1− >Q rack ) ; dig . couple ( seg2 , seg2− >Q send , seg3 , seg3− >Q recv ) ; dig . couple ( seg2 , seg2− >car out , seg3 , seg3− >c a r i n ) ; dig . couple ( seg3 , seg3− >Q sack , seg2 , seg2− >Q rack ) ; dig . couple ( seg3 , seg3− >car out , col , col− >c a r i n ) ; 3 / 25

slide-5
SLIDE 5

The problem: Different simulators

i n t main ( int , char∗∗ argv ){ adevs : : Digraph<Event∗ > dig ; Generator∗ gen = new Generator () ; RoadSegment∗ seg1 = new RoadSegment ( ) ; RoadSegment∗ seg2 = new RoadSegment ( ) ; RoadSegment∗ seg3 = new RoadSegment ( ) ; C o l l e c t o r ∗ c o l = new C o l l e c t o r ( ) ; dig . add ( gen ) ; dig . add ( seg1 ) ; dig . add ( seg2 ) ; dig . add ( seg3 ) ; dig . add ( c o l ) ; dig . couple ( gen , gen− >Q send , seg1 , seg1− >Q recv ) ; dig . couple ( gen , gen− >car out , seg1 , seg1− >c a r i n ) ; dig . couple ( seg1 , seg1− >Q sack , gen , gen− >Q rack ) ; dig . couple ( seg1 , seg1− >Q send , seg2 , seg2− >Q recv ) ; dig . couple ( seg1 , seg1− >car out , seg2 , seg2− >c a r i n ) ; dig . couple ( seg2 , seg2− >Q sack , seg1 , seg1− >Q rack ) ; dig . couple ( seg2 , seg2− >Q send , seg3 , seg3− >Q recv ) ; dig . couple ( seg2 , seg2− >car out , seg3 , seg3− >c a r i n ) ; dig . couple ( seg3 , seg3− >Q sack , seg2 , seg2− >Q rack ) ; dig . couple ( seg3 , seg3− >car out , col , col− >c a r i n ) ;

Solution: Independent language

3 / 25

slide-6
SLIDE 6

Global overview

Source: Hongyan Song. Infrastructure for devs modelling and experimentation. Master’s thesis, McGill University, 2006

4 / 25

slide-7
SLIDE 7

Overview: Modelling

◮ In AToM3 ◮ Compliant to a metamodel ◮ Should have a code generation feature

◮ For intermediate language (Modelica)

◮ Automatically generated environment!

5 / 25

slide-8
SLIDE 8

Intermediate Language: Modelica

Modelling language

◮ Relatively mature ◮ Language features for both continuous and discrete models ◮ Standard library ◮ Re-usability

6 / 25

slide-9
SLIDE 9

Modelica Example

c l a s s Generator extends AtomicDEVS ;

  • utput

DevsPort p out ; GeneratorState s t a t e ( ) ; f u n c t i o n timeAdvance

  • utput

I n t e g e r timespan ; algorithm . . . end timeAdvance ; end Generator ; c l a s s Root extends CoupledDEVS ;

  • utput

DevsPort p out ; P r o c e s s o r i n s 2 ( ) ; equation connect ( i n s 2 . p o u t , p out ) ; end Root ;

7 / 25

slide-10
SLIDE 10

Overview: Verification

◮ Use the µModelica compiler 1 ◮ Statically check the model

◮ No accesses to inaccessible variables

◮ Possibly perform optimisations ◮ Currently (nearly) no verification happens

1Weigao Xu. The design and implementation of the modelica compiler.

Master’s thesis, McGill University, 2005

8 / 25

slide-11
SLIDE 11

Overview: Simulation

◮ Use the PythonDEVS simulator 2 ◮ Save the trace file

◮ Text output ◮ XML output ◮ VCD output 2Jean-S´

ebastien Bolduc and Hans Vangheluwe. The modelling and simulation package pythondevs for classical hierarchical devs. Technical report, MSDL Technical Report, 2001

9 / 25

slide-12
SLIDE 12

Overview: Validation

◮ Compare the output of the simulation to the specifications ◮ Textual simulation traces are unclear ◮ Visualize!

10 / 25

slide-13
SLIDE 13

Overview: Validation (example)

Source: Hongyan Song. Infrastructure for devs modelling and experimentation. Master’s thesis, McGill University, 2006

11 / 25

slide-14
SLIDE 14

Overview: Features

◮ Model reuse

◮ At AToM3 level ◮ At Modelica level ◮ At PythonDEVS level

◮ Clear boundaries ◮ Open structure

12 / 25

slide-15
SLIDE 15

My contribution

◮ Modelling

◮ Updating the existing metamodel ◮ Include experiment data

◮ Verification

◮ Update the µModelica compiler ◮ Introduce a flattening phase 13 / 25

slide-16
SLIDE 16

Modelling in AToM3: metamodel

atomicDevsV2 Attributes:

  • name :: String
  • isVisible :: Boolean
  • classVariables :: List
  • parameters :: List
  • attributes :: List
  • init :: Text
  • extTransition :: Text
  • intTransition :: Text
  • outputFunc :: Text
  • timeAdvance :: Text

coupledDevsV2 Attributes:

  • name :: String
  • isVisible :: Boolean
  • classVariables :: List
  • parameters :: List
  • attributes :: List
  • init :: Text
  • isMainModel :: Boolean

portDevsV2 Attributes:

  • name :: String
  • portType :: Enum

stateDevsV2 Attributes:

  • name :: String
  • initial :: Boolean
  • timeAdvance :: Text
  • output :: Text
  • extAction :: Text
  • intAction :: Text

insDevsV2 Attributes:

  • name :: String
  • type :: String
  • parameters :: Text
  • isVisible :: Boolean

eventDevsV2 Attributes:

  • name :: String
  • classVariables :: List
  • parameters :: List
  • attributes :: List
  • init :: Text
  • str :: Text
  • otherFunc :: Text

DevsState Attributes:

  • name :: String
  • attributes :: List

DevsExperiment Attributes:

  • experimentName :: String
  • model :: String
  • package :: String
  • parameters :: Text
  • end_time :: Float
  • verbose :: Boolean
  • trace :: Boolean

containsPortV2 Actions: > connect < disconnect containsStateV2 Actions: > connect < disconnect internalTransitionV2 Attributes:

  • condition :: Text
  • action :: Text

externalTransitionV2 Attributes:

  • condition :: Text
  • action :: Text

channelV2 Actions: > connect < disconnect < checkValidity containModelV2 Actions: > connect < disconnect hasState Actions: > connect > disconnect

14 / 25

slide-17
SLIDE 17

Modelling in AToM3: example model

Generator Processor Root CoupledProcessor p_out p_in p_out p_in p_out p_out p_in p_in p_out p_in p_out p_out p_in p_out p_out generating timespan := 1; TimeAdvance: Output: evt := Job(0.3); poke(p_out, evt); idle timespan := INFINITY; TimeAdvance: Output: processing timespan := event.jobSize; TimeAdvance: Output: poke(p_out, event); ins_2 Processor : ins_3 Processor : ins_4 Processor : ins_6 CoupledProcessor : ins_7 Generator : Job jobSize type=Float init.value=3.5 Parameters: Attributes: Model: Parameters: End time: Verbose: Trace: Package: Root 100.0 True False Experiment Experiment:

15 / 25

slide-18
SLIDE 18

DEVS: Messages

16 / 25

slide-19
SLIDE 19

Verification: Flattening

◮ What is flattening?

◮ Perform the closure under coupling on a real model ◮ Together with direct connection

◮ Use of flattening

◮ Increased performance ◮ The proof was right! 17 / 25

slide-20
SLIDE 20

Verification: Direct connection

◮ What is direct connection?

◮ Remove the complete hierarchy ◮ Just 1 coupled model ◮ Connections become ’one-step’

◮ Problems! 3

◮ Z functions need to be rewritten ◮ select functions need to be rewritten 3Bin Chen and Hans Vangheluwe. Symbolic flattening of devs models.

In 2010 Summer Simulation Multiconference, SummerSim ’10, pages 209–218, San Diego, CA, USA, 2010. Society for Computer Simulation International

18 / 25

slide-21
SLIDE 21

Verification: Direct connection

19 / 25

slide-22
SLIDE 22

Verification: Compilation

◮ Still need to compile the generated modelica code ◮ Some slight changes were done here

20 / 25

slide-23
SLIDE 23

Evaluation

10 20 30 40 50 60 70 5 10 15 20 25 30 35 40 45 50 Time (s) Width Simulation time of Wide models using the Old PyDEVS Flattened Quadratic Non-Flattened Quadratic 5 10 15 20 25 30 35 40 5 10 15 20 25 30 35 40 45 50 Time (s) Width Simulation time of Wide models using the New PyDEVS Flattened Quadratic Non-Flattened Linear

21 / 25

slide-24
SLIDE 24

Evaluation

1 2 3 4 5 6 7 8 9 10 11 5 10 15 20 25 30 35 40 45 50 Time (s) Depth Simulation time of Deep models using the Old PyDEVS Flattened Quadratic Non-Flattened Constant 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 5 10 15 20 25 30 35 40 45 50 Time (s) Depth Simulation time of Deep models using the New PyDEVS Flattened Linear Non-Flattened Constant

22 / 25

slide-25
SLIDE 25

Evaluation: Gain

These optimisations are simulator-independent!

◮ Optimisations will propagate ◮ Difference depends on the simulator

This comparison was with an optimised simulator 4

4Yentl Van Tendeloo. Research internship 1: Optimizing pydevs.

Technical report, MSDL, 2013

23 / 25

slide-26
SLIDE 26

Future work

Different dimensions

◮ Optimise flattening ◮ Implement Verifications ◮ Implement other back-ends ◮ Some ’details’ were ignored

◮ Z and select function 24 / 25

slide-27
SLIDE 27

Demo

Time for a demo!

25 / 25

slide-28
SLIDE 28

Jean-S´ ebastien Bolduc and Hans Vangheluwe. The modelling and simulation package pythondevs for classical hierarchical devs. Technical report, MSDL Technical Report, 2001. Bin Chen and Hans Vangheluwe. Symbolic flattening of devs models. In 2010 Summer Simulation Multiconference, SummerSim ’10, pages 209–218, San Diego, CA, USA, 2010. Society for Computer Simulation International. Hongyan Song. Infrastructure for devs modelling and experimentation. Master’s thesis, McGill University, 2006. Yentl Van Tendeloo. Research internship 1: Optimizing pydevs. Technical report, MSDL, 2013. Weigao Xu. The design and implementation of the modelica compiler.

25 / 25

slide-29
SLIDE 29

Master’s thesis, McGill University, 2005.

25 / 25