mde: modelling the devs formalism -...

29
MDE: Modelling the DEVS formalism Yentl Van Tendeloo [email protected] January 24, 2013 1 / 25

Upload: vuongdien

Post on 09-Jul-2018

231 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

MDE: Modelling the DEVS formalism

Yentl Van [email protected]

January 24, 2013

1 / 25

Page 2: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

The problem: Difficult to comprehend

c l a s s Root ( CoupledDEVS ) :de f 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 ( Gene ra to r ( ) )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 . c onnec tPo r t s ( s e l f . gen . Q send , s e l f . seg1 . Q recv )s e l f . c onnec tPo r t s ( s e l f . gen . ca r ou t , s e l f . seg1 . c a r i n )s e l f . c onnec tPo r t s ( s e l f . seg1 . Q sack , s e l f . gen . Q rack )s e l f . c onnec tPo r t s ( s e l f . seg1 . Q send , s e l f . seg2 . Q recv )s e l f . c onnec tPo r t s ( s e l f . seg1 . c a r ou t , s e l f . seg2 . c a r i n )s e l f . c onnec tPo r t s ( s e l f . seg2 . Q sack , s e l f . seg1 . Q rack )s e l f . c onnec tPo r t s ( s e l f . seg2 . Q send , s e l f . seg3 . Q recv )s e l f . c onnec tPo r t s ( s e l f . seg2 . c a r ou t , s e l f . seg3 . c a r i n )s e l f . c onnec tPo r t s ( s e l f . seg3 . Q sack , s e l f . seg2 . Q rack )s e l f . c onnec tPo r t s ( s e l f . seg3 . c a r ou t , s e l f . c o l . c a r i n )

Solution: Graphical representation

2 / 25

Page 3: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

The problem: Difficult to comprehend

c l a s s Root ( CoupledDEVS ) :de f 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 ( Gene ra to r ( ) )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 . c onnec tPo r t s ( s e l f . gen . Q send , s e l f . seg1 . Q recv )s e l f . c onnec tPo r t s ( s e l f . gen . ca r ou t , s e l f . seg1 . c a r i n )s e l f . c onnec tPo r t s ( s e l f . seg1 . Q sack , s e l f . gen . Q rack )s e l f . c onnec tPo r t s ( s e l f . seg1 . Q send , s e l f . seg2 . Q recv )s e l f . c onnec tPo r t s ( s e l f . seg1 . c a r ou t , s e l f . seg2 . c a r i n )s e l f . c onnec tPo r t s ( s e l f . seg2 . Q sack , s e l f . seg1 . Q rack )s e l f . c onnec tPo r t s ( s e l f . seg2 . Q send , s e l f . seg3 . Q recv )s e l f . c onnec tPo r t s ( s e l f . seg2 . c a r ou t , s e l f . seg3 . c a r i n )s e l f . c onnec tPo r t s ( s e l f . seg3 . Q sack , s e l f . seg2 . Q rack )s e l f . c onnec tPo r t s ( s e l f . seg3 . c a r ou t , s e l f . c o l . c a r i n )

Solution: Graphical representation

2 / 25

Page 4: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

The problem: Different simulators

i n t main ( i n t , cha r∗∗ a rgv ){adevs : : Digraph<Event∗> d i g ;Gene ra to r∗ gen = new Gene ra to r ( ) ;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 ( ) ;d i g . add ( gen ) ;d i g . add ( seg1 ) ;d i g . add ( seg2 ) ;d i g . add ( seg3 ) ;d i g . add ( c o l ) ;d i g . c oup l e ( gen , gen−>Q send , seg1 , seg1−>Q recv ) ;d i g . c oup l e ( gen , gen−>ca r ou t , seg1 , seg1−>c a r i n ) ;d i g . c oup l e ( seg1 , seg1−>Q sack , gen , gen−>Q rack ) ;d i g . c oup l e ( seg1 , seg1−>Q send , seg2 , seg2−>Q recv ) ;d i g . c oup l e ( seg1 , seg1−>ca r ou t , seg2 , seg2−>c a r i n ) ;d i g . c oup l e ( seg2 , seg2−>Q sack , seg1 , seg1−>Q rack ) ;d i g . c oup l e ( seg2 , seg2−>Q send , seg3 , seg3−>Q recv ) ;d i g . c oup l e ( seg2 , seg2−>ca r ou t , seg3 , seg3−>c a r i n ) ;d i g . c oup l e ( seg3 , seg3−>Q sack , seg2 , seg2−>Q rack ) ;d i g . c oup l e ( seg3 , seg3−>ca r ou t , co l , co l−>c a r i n ) ;

Solution: Independent language

3 / 25

Page 5: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

The problem: Different simulators

i n t main ( i n t , cha r∗∗ a rgv ){adevs : : Digraph<Event∗> d i g ;Gene ra to r∗ gen = new Gene ra to r ( ) ;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 ( ) ;d i g . add ( gen ) ;d i g . add ( seg1 ) ;d i g . add ( seg2 ) ;d i g . add ( seg3 ) ;d i g . add ( c o l ) ;d i g . c oup l e ( gen , gen−>Q send , seg1 , seg1−>Q recv ) ;d i g . c oup l e ( gen , gen−>ca r ou t , seg1 , seg1−>c a r i n ) ;d i g . c oup l e ( seg1 , seg1−>Q sack , gen , gen−>Q rack ) ;d i g . c oup l e ( seg1 , seg1−>Q send , seg2 , seg2−>Q recv ) ;d i g . c oup l e ( seg1 , seg1−>ca r ou t , seg2 , seg2−>c a r i n ) ;d i g . c oup l e ( seg2 , seg2−>Q sack , seg1 , seg1−>Q rack ) ;d i g . c oup l e ( seg2 , seg2−>Q send , seg3 , seg3−>Q recv ) ;d i g . c oup l e ( seg2 , seg2−>ca r ou t , seg3 , seg3−>c a r i n ) ;d i g . c oup l e ( seg3 , seg3−>Q sack , seg2 , seg2−>Q rack ) ;d i g . c oup l e ( seg3 , seg3−>ca r ou t , co l , co l−>c a r i n ) ;

Solution: Independent language

3 / 25

Page 6: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Global overview

Source: Hongyan Song. Infrastructure for devs modelling and experimentation.

Master’s thesis, McGill University, 20064 / 25

Page 7: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Overview: Modelling

I In AToM3

I Compliant to a metamodelI Should have a code generation feature

I For intermediate language (Modelica)

I Automatically generated environment!

5 / 25

Page 8: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Intermediate Language: Modelica

Modelling language

I Relatively mature

I Language features for both continuous and discrete models

I Standard library

I Re-usability

6 / 25

Page 9: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Modelica Example

c l a s s Gene ra to rextends AtomicDEVS ;output DevsPort p out ;Gene r a t o rS t a t e s t a t e ( ) ;

f u n c t i o n t imeAdvanceoutput I n t e g e r t imespan ;

a lgo r i thm. . .

end t imeAdvance ;end Gene ra to r ;

c l a s s Rootextends CoupledDEVS ;output DevsPort p out ;P r o c e s s o r i n s 2 ( ) ;

equat ionconnect ( i n s 2 . p o u t , p out ) ;

end Root ;

7 / 25

Page 10: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Overview: Verification

I Use the µModelica compiler 1

I Statically check the modelI No accesses to inaccessible variables

I Possibly perform optimisations

I Currently (nearly) no verification happens

1Weigao Xu. The design and implementation of the modelica compiler.Master’s thesis, McGill University, 2005

8 / 25

Page 11: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Overview: Simulation

I Use the PythonDEVS simulator 2

I Save the trace fileI Text outputI XML outputI VCD output

2Jean-Sebastien Bolduc and Hans Vangheluwe. The modelling andsimulation package pythondevs for classical hierarchical devs.Technical report, MSDL Technical Report, 2001

9 / 25

Page 12: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Overview: Validation

I Compare the output of the simulation to the specifications

I Textual simulation traces are unclear

I Visualize!

10 / 25

Page 13: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Overview: Validation (example)

Source: Hongyan Song. Infrastructure for devs modelling and experimentation.

Master’s thesis, McGill University, 2006

11 / 25

Page 14: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Overview: Features

I Model reuseI At AToM3 levelI At Modelica levelI At PythonDEVS level

I Clear boundaries

I Open structure

12 / 25

Page 15: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

My contribution

I ModellingI Updating the existing metamodelI Include experiment data

I VerificationI Update the µModelica compilerI Introduce a flattening phase

13 / 25

Page 16: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

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

insDevsV2Attributes:

- 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

Page 17: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Modelling in AToM3: example model

Generator

Processor

Root

CoupledProcessor

p_out

p_in

p_out

p_in

p_out

p_outp_inp_in p_out

p_in

p_out

p_outp_in

p_outp_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

ExperimentExperiment:

15 / 25

Page 18: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

DEVS: Messages

16 / 25

Page 19: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Verification: Flattening

I What is flattening?I Perform the closure under coupling on a real modelI Together with direct connection

I Use of flatteningI Increased performanceI The proof was right!

17 / 25

Page 20: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Verification: Direct connection

I What is direct connection?I Remove the complete hierarchyI Just 1 coupled modelI Connections become ’one-step’

I Problems! 3

I Z functions need to be rewrittenI 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

Page 21: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Verification: Direct connection

19 / 25

Page 22: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Verification: Compilation

I Still need to compile the generated modelica code

I Some slight changes were done here

20 / 25

Page 23: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Evaluation

0

10

20

30

40

50

60

70

0 5 10 15 20 25 30 35 40 45 50

Tim

e (

s)

Width

Simulation time of Wide models using the Old PyDEVS

FlattenedQuadratic

Non-FlattenedQuadratic

0

5

10

15

20

25

30

35

40

0 5 10 15 20 25 30 35 40 45 50

Tim

e (

s)

Width

Simulation time of Wide models using the New PyDEVS

FlattenedQuadratic

Non-FlattenedLinear

21 / 25

Page 24: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Evaluation

0

1

2

3

4

5

6

7

8

9

10

11

0 5 10 15 20 25 30 35 40 45 50

Tim

e (

s)

Depth

Simulation time of Deep models using the Old PyDEVS

FlattenedQuadratic

Non-FlattenedConstant

0.25

0.26

0.27

0.28

0.29

0.3

0.31

0.32

0.33

0 5 10 15 20 25 30 35 40 45 50

Tim

e (

s)

Depth

Simulation time of Deep models using the New PyDEVS

FlattenedLinear

Non-FlattenedConstant

22 / 25

Page 25: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Evaluation: Gain

These optimisations are simulator-independent!

I Optimisations will propagate

I 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

Page 26: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Future work

Different dimensions

I Optimise flattening

I Implement Verifications

I Implement other back-endsI Some ’details’ were ignored

I Z and select function

24 / 25

Page 27: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Demo

Time for a demo!

25 / 25

Page 28: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Jean-Sebastien Bolduc and Hans Vangheluwe.The modelling and simulation package pythondevs for classicalhierarchical 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 forComputer 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

Page 29: MDE: Modelling the DEVS formalism - msdl.cs.mcgill.camsdl.cs.mcgill.ca/.../Yentl.VanTendeloo/presentation/presentation.pdf · MDE: Modelling the DEVS formalism Yentl Van Tendeloo

Master’s thesis, McGill University, 2005.

25 / 25