model transformation with hierarchical discrete-event control · feng, dissertation talk,...

30
May 6, 2009 Dissertation Talk Model Transformation with Hierarchical Discrete-Event Control Thomas Huining Feng Center for Hybrid and Embedded Software Systems EECS, UC Berkeley Advisor: Prof. Edward A. Lee

Upload: others

Post on 26-Jul-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

May 6, 2009Dissertation Talk

Model Transformation with Hierarchical Discrete-Event Control

Thomas Huining Feng

Center for Hybrid and Embedded Software Systems

EECS, UC Berkeley

Advisor: Prof. Edward A. Lee

Page 2: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 2 / 30

Outline

• Motivation and Contribution

• Transformation Rules: Syntax and Semantics

• Ptera (Ptolemy Event Relationship Actor)

• Model-Based Transformation

• Conclusion and Future Directions

Page 3: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 3 / 30

Motivation

• Models can get large

A simplified 4-way Intersection(230 actors, 2000 attributes)

How about Street?

How about City?

Other types? (n-way,irregular, European)

• Need automaticmodel constructionand maintenance

Page 4: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 4 / 30

Sinewave Example

• An SDF (synchronous dataflow) model to generate a sine wave with:

• Static partial evaluation improves run-time performance(similar to program optimization in compilers)

sin(2πFn

)Fs

Page 5: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 5 / 30

Contribution

• A model transformation tool

Convenient − an intuitive visual syntax

Flexible − compositional workflow

Efficient − by using an appropriate model of computation

• The Ptera model of computation

Syntax and semantics based on event graphs

Hierarchical composition

Composition with DE, FSM and more

• Applications

Transformation for actor models

Simulation of discrete-event processes

Page 6: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 6 / 30

Outline

• Motivation and Contribution

• Transformation Rules: Syntax and Semantics

• Ptera (Ptolemy Event Relationship Actor)

• Model-Based Transformation

• Conclusion and Future Directions

Page 7: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 7 / 30

Intuition of Model Transformation

• Pattern matching (locate a part of the model)

Page 8: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 8 / 30

Intuition of Model Transformation

• Pattern matching (locate a part of the model)

• Replace the part with a more compact design

Page 9: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 9 / 30

Intuition of Model Transformation

• Pattern matching (locate a part of the model)

• Replace the part with a more compact design

• Repeat transformations until fixpoint

Page 10: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 10 / 30

Control

• A control mechanism is needed

Transform until fixpoint

Try multiple alternative transformation rules

Pause and ask user a question

Branch with user input or current state

Perform IO before/after transformation

• Examples of existing approaches

Priority (AToM3, AGG)

Control flow + Statecharts (FUJABA)

Abstract state machines (VIATRA2)

Dataflow + Implicit shared variables (GReAT)

Imperative programs (PROGRES)

• The Ptolemy II approach

Hierarchical heterogeneous models of computation

Ptera (Ptolemy event relationship actor)

Page 11: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 11 / 30

A Ptera Transformation Workflow

SimplifyMultiply

SimplifyDivide RemoveMultiply

Page 12: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 12 / 30

Outline

• Motivation and Contribution

• Transformation Rules: Syntax and Semantics

• Ptera (Ptolemy Event Relationship Actor)

• Model-Based Transformation

• Conclusion and Future Directions

Page 13: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 13 / 30

Syntax

• Based on event graphs [Schruben 1983]

• Visual representation

Nodes are events

Edges are scheduling relations

• Compare to FSM

Actions on events

Can schedule multiple events

Timed

Initial Event

Final Event

Delay (δ)

Action

Guard

Variable

CarWash: single queue multiple servers

The CarWash model

Page 14: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 14 / 30

Execution

• During execution, the event queue stores instances of events

• Start by scheduling an instance of each initial events at time 0

• Remove and process the first instance in each firing

• Terminate when the event queue becomes empty

0.0 2.0 2.0 4.0 4.0

Start

time

End

Enter

End

Enter

Wash

S = 3Q = 0

S = 2Q = 0

S = 3Q = 1

End

Leave

Enter

S = 2Q = 1

0 50

2

50

4

2

50

8

4

End

Leave

Enter

50

8

6

Wash 4

S = 1Q = 0

End

Leave

Leave

50

10

8

Enter 6

6.0

S = 1Q = 1

Page 15: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 15 / 30

Simultaneous Events

Events with instances that

1. coexist in the event queue, and

2. are scheduled to occur at the same time

E.g., Enter and Leave.

time

End

Leave

Leave

50

10

8

Enter 6

6.0

S = 1Q = 1

End

Leave

Leave

50

10

8

Enter 8

6.0

S = 0Q = 0

...

4.0

End

Leave

Enter

50

8

6

Wash 4

S = 1Q = 0

Wash 6

End

Leave

Leave

50

12

10

Leave 8

8.0

S = 0Q = 1

Enter 8

End

Leave

Leave

50

12

10

Enter 10

8.0

Leave 8

Page 16: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 16 / 30

Simultaneous Events

time

End

Leave

Leave

50

10

8

Enter 6

6.0

S = 1Q = 1

End

Leave

Enter

50

10

8

Leave 8

6.0

S = 0Q = 0

...

4.0

End

Leave

Enter

50

8

6

Wash 4

S = 1Q = 0

Wash 6

End

Leave

Leave

50

12

10

Enter 8

8.0

S = 1Q = 0

Leave 8

Events with instances that

1. coexist in the event queue, and

2. are scheduled to occur at the same time

E.g., Enter and Leave.

End

Leave

Leave

50

12

10

Enter 8

8.0

Page 17: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 17 / 30

FIFO and LIFO Policies

• With FIFO (First In First Out) policy

• With LIFO (Last In First Out) policy

time

End

Leave

Leave

50

10

8

Enter 6

6.0

End

Leave

Enter

50

10

8

Leave 8

6.0

...

Wash 6

time

End

Leave

Leave

50

10

8

Enter 6

6.0

End

Leave

Leave

50

10

8

Enter 8

6.0

...

Wash 6

Page 18: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 18 / 30

Rationale for FIFO and LIFO

1. With FIFO, when x*t1 = y*t2 Λ t1 > t2ReadOpen → WriteOpen → Read → Write → ReadClose → WriteClose

2. With LIFO, always(ReadOpen → Read → ReadClose), (WriteOpen → Write → WriteClose)

Page 19: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 19 / 30

Execution Algorithm

1. Initialize E to contain all initial events

2. While E is not empty

a. Remove the top instance t from E

b. Execute t’s actions

c. Terminate if t is a final event

d. Schedule events in E in the order of

1. Time stamp

2. FIFO or LIFO policy

3. Event name

4. Scheduling relation name

0.0 2.0 2.0

Start

time

End

Enter

End

Enter

Wash

0 50

2

50

4

2

Page 20: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 20 / 30

• Submodel associated with scheduling relation [Schruben 1995]

• Submodel associated with event [Schruben 1995]

• LEGOs (Listener Event Graph Objects) [Buss & Sánchez 2002]

Model Hierarchy: Previous Attempts

ConsumerProducer

Page 21: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 21 / 30

Model Hierarchy: The Ptera Approach

• A submodel is itself a model

No difference in syntax

Conceptually equipped with an isolated event queue

A global notion of model time

• Implication: events (or tasks) are no longer instantaneous

Start of an event causes start of its submodel

End of the submodel causes end of the event

Page 22: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 22 / 30

Hierarchical CarWash

• Hierarchical workflow:

Global time, separate event queues

A composite task (CT) is composed of smaller tasks

Execution of CTs interleave

The whole workflow is a top-level CT

2.0

End

Enter

Wash

50

4

2

2.0

HighPr 2

...

3.0

FoamP 3

3.0

End

Enter

Wash

50

4

3

4.0

Wheel 4

4.0

End

Enter

Wash

50

4

4

Rinse 5

4.0

End

Wash

Enter

50

5

4

4.0

End

Enter

Wash

50

6

5

Wash 4

4.0

Rinse 5

HighPr 4

(LIFO)

Page 23: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 23 / 30

Outline

• Motivation and Contribution

• Transformation Rules: Syntax and Semantics

• Ptera (Ptolemy Event Relationship Actor)

• Model-Based Transformation

• Conclusion and Future Directions

Page 24: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 24 / 30

Transformation Workflow

A simple workflow for repeated transformation

Page 25: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 25 / 30

Hierarchical Workflow

• A hierarchical workflow to break down complexity

• Schedule multiple events (compare to FSM and control flow)

• Model time is useful for

animation

specifying time or cost

simulation

Page 26: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 26 / 30

Comparison

• Priority: not expressive enough

• Control flow, state machine: bounded state, not hierarchical, not timed

• Imperative program: lack of abstraction

• Dataflow: overhead of message passing

Shared variables are introduced in GReAT to improve performance, but they cause new problems.

Const ActorsRun Time (sec)

Ptera DDF C (from DDF)

8 0.016 0.113 0.015

16 0.032 0.250 0.031

32 0.063 0.875 0.078

64 0.188 4.088 0.218

128 0.750 17.254 0.717

256 3.261 74.850 3.276

512 14.431 366.679 12.386

1024 72.736 2054.172 59.764

Page 27: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 27 / 30

Applications

• Model optimizationE.g., partial evaluation, removal of nonfunctional parts

• Model constructionE.g., generating a family of products

• Model refactoringE.g., flattening hierarchy, introducing hierarchy

• SimulationE.g., Conway’s game of life

Page 28: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 28 / 30

Outline

• Motivation and Contribution

• Transformation Rules: Syntax and Semantics

• Ptera (Ptolemy Event Relationship Actor)

• Model-Based Transformation

• Conclusion and Future Directions

Page 29: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 29 / 30

Conclusion and Future Directions

Conclusion:

• Transformation rule in the same modeling language

• Model-based transformation is essentially a model

• Ptera

Convenient and expressive

Compositional

Timed

Avoids message passing

Future Directions:

• Analyze properties of transformations

• Compose Ptera with other MoCs (DE and FSM studied)

• Model checking (bound of event queue, simultaneous events, termination condition, …)

• Behavior-preserving concurrent and distributed execution

Page 30: Model Transformation with Hierarchical Discrete-Event Control · Feng, Dissertation Talk, 05/06/2009 14 / 30 Execution • During execution, the event queue stores instances of events

Feng, Dissertation Talk, 05/06/2009 30 / 30

Acknowledgments

• Dissertation committee

Prof. Edward A. Lee (chair, advisor)

Prof. Rastislav Bodik

Prof. Lee W. Schruben

• Students, researchers and staff in Cory (545.*)

• Christopher Brooks and Mary Steward

• Industrial collaborators

Naomi team at Lockheed Martin ATL

Thomas Mandl at Bosch research

• Prof. Hans Vangheluwe (former advisor at McGill)

• Friends in EECS

• Family