7th biennial ptolemy miniconference berkeley, ca february 13, 2007 leveraging synchronous language...

24
7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and Edward A. Lee UC Berkeley

Post on 19-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

7th Biennial Ptolemy Miniconference

Berkeley, CAFebruary 13, 2007

Leveraging Synchronous Language Principles for Hybrid System Models

Haiyang Zheng and Edward A. Lee

UC Berkeley

Page 2: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 2Ptolemy Miniconference, February 13, 2007

Introduction

A lot of tools have been developed for supporting model-based designs of hybrid systems. Charon Dymola/Modelica® Simulink®

HyVisual/Ptolemy …

All these tools use a block-diagram syntax to represent models.

Page 3: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 3Ptolemy Miniconference, February 13, 2007

Main-Stream Operational Semantics

The main-stream operational semantics for simulating DE, CT, and hybrid systems models heavily rely on the execution order of blocks.

The execution order is usually determined by topological sorting based on data dependencies. It is not unique. The execution order affects simulation results. Topological sorting is not always possible.

Page 4: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 4Ptolemy Miniconference, February 13, 2007

Operational Semantics: Discrete Event Example

DE operational semantics A block executes whenever receiving a trigger event in

any input port. When executing, if an input port has no present event,

the block uses an “absence” event for computation.

We get either 1 followed by 2, or 3 depending on the execution order of

Scale and AddSubtract blocks.

Page 5: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 5Ptolemy Miniconference, February 13, 2007

Operational Semantics: Discrete Event Example (continued)

The execution order may cause unexpected delay among “simultaneous” events.

When this delay interferes with user specified time delay and feedback loops, the simulation results are more complicated.

I leave this an exercise for

readers to figure out how many

possible outputs there are.

Page 6: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 6Ptolemy Miniconference, February 13, 2007

Operational Semantics: Continuous Time Example

CT operational semantics Determined by the actual ODE solvers used for solving

dynamic equations

Example: Runge-Kutta 2-3 Solver• Given x(tn) and a step size h to solve x(tn+1), calculate

• then let

)75.0()75.0,75.0)((

)5.0()5.0,5.0)((

)()),((

12

01

0

htxhthKtxfK

htxhthKtxfK

txttxfK

nnn

nnn

nnn

2101

1

)9/4()9/3()9/2()()( hKhKhKtxtx

htt

nn

nn

Page 7: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 7Ptolemy Miniconference, February 13, 2007

Continuous Time Example:How does Integration work?

It takes three micro steps for the RK 2-3 solver to finish a complete integration.

The outputs generated at a micro step by one integrator affect the inputs of other integrators.

x

y dy/dt

dx/dt

t t + t + /2 t + 3/4

Update dx/dt

Update dy/dt

Update x

Update y

x

y

dy/dt

dx/dt

At each micro step, perform the followings in order:

Page 8: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 8Ptolemy Miniconference, February 13, 2007

So,

Topological sorting is important for correctness of simulation.

But getting topological sorting correct is hard.

Page 9: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 9Ptolemy Miniconference, February 13, 2007

Results are calculated with the

RK 2-3 solver.

Hierarchical Execution: Continuous Time Example

A designer expects certain invariants: transformations of a model by adding hierarchies do not change behavior.

A correct result

An incorrect result in HyVisual

releases earlier than version 5.0.

Page 10: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 10Ptolemy Miniconference, February 13, 2007

Topological Sorting of Composites

Introducing hierarchies makes topological sorting hard.

How to sort the composite actor without flattening the hierarchy?

Page 11: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 11Ptolemy Miniconference, February 13, 2007

Causality Interface: A Helper for Topological Sorting

Causality interfaces expose dependency information.

Only port4 depends on port1.More information can be found in [FIT2005, Lee, Zheng, Zhou]

Page 12: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 12Ptolemy Miniconference, February 13, 2007

Synchronous Languages

The model of computation is called synchronous reactive (SR). Esterel Lustre SCADE (visual editor for Lustre) Signal Statecharts (some variants) Ptolemy II SR domain

A strong formal property: Execution results do NOT depend on schedule or topological sorting!

Page 13: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 13Ptolemy Miniconference, February 13, 2007

SR Operational Semantics:Mathematics Foundation

Requirements: All possible signal values form a flat CPO with , called unknown, as

the bottom element. All blocks are monotonic functions (and therefore continuous

functions and composable).

Fixed Point Theorem [Introduction to lattices and order, Davey and Priestley, 2002] Let f: A A be a continuous function defined on a CPO A, then f

has a least fixed point given by n0 f n ().

The number n is finite.

Page 14: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 14Ptolemy Miniconference, February 13, 2007

SR Operational Semantics:Execution Algorithm

1. At a tick t, reset all signal values to unknown, .

2. Pick up a block (no preference needed) and evaluate its output signal values based on its current input signal values and states.

3. Repeat step 2 until either all signal values have been resolved or no more signal values can be resolved.

4. The set of all resolved signal values is called the least fixed point of the model at tick t.

5. Advance to another tick t’ = t+1, repeat step 1.

Page 15: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 15Ptolemy Miniconference, February 13, 2007

SR Operational Semantics: A Simple Example

1. Invoke AddSubtract2. Invoke Ramp 3. Invoke NonStrictDelay 4. Invoke AddSubtract5. Invoke NonStrictDisplay6. Invoke NonStrictDisplay2

Fixed point is reached with all signal values resolved.

0

absent

0

One possible execution schedule

Page 16: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 16Ptolemy Miniconference, February 13, 2007

So,

Topological sorting is not that important for correctness of simulation but a very useful optimization.

Page 17: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 17Ptolemy Miniconference, February 13, 2007

An Operational Semantics For Hybrid Systems

Leverage the SR Operational Semantics to develop a general operational semantics for DE, CT, FSM, SR, and Hybrid System models

Separate the concern of simulation correctness from the other considerations for implementations details, in particular, the topological sorting.

Benefits: The correctness of individual implementations can be verified. Treat topological sorting as an optimization, which helps to improve

the execution performance.

Page 18: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 18Ptolemy Miniconference, February 13, 2007

What We Do

Augment the value set with unknown, .

Ensure an actor implements a monotonic function: Explicitly specify strictness and non-strictness property Write actors according to the abstract actor semantics

Associate time semantics to intervals between ticks.

Page 19: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 19Ptolemy Miniconference, February 13, 2007

Abstract Actor Semantics

Flow of control Initialization Execution Finalization

Specifications: prefire(): synchronizes to the environment and checks firing

conditions (such as strictness) fire(): generates outputs based on current inputs and states postfire(): updates the states for next iteration

iterate()

prefire() fire() postfire()

Page 20: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 20Ptolemy Miniconference, February 13, 2007

Time Semantics Between Ticks

We use super-dense time, for hybrid systems.

The interval between two ticks represents an increment of index or real-time.

,NR

Page 21: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 21Ptolemy Miniconference, February 13, 2007

Operational Semantics:Execution Algorithm

1. At a time t, reset all signal values to unknown, .

2. Pick up a block (no preference needed) and evaluate its output signal values based on its current input signal values and states.

3. Repeat step 2 until either all signal values have been resolved or no more signal values can be resolved.

4. The set of all resolved signal values is called the least fixed point of the model at time t.

5. Advance to another time t’, repeat step 1.

Page 22: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 22Ptolemy Miniconference, February 13, 2007

How to Advance Time?

At any time, ask all blocks to post the next super-dense time they are expecting to produce outputs.

Advance time to the earliest posted time, discard all remaining times.

A block is responsible for posting the right time and keeping a record of when it will produce outputs.

Optimization for DE and hybrid system models Global event queue may be used to keep a record of all previously

posted times when are confirmed to have outputs generated, so that to avoid duplicate postings of the same future time.

Page 23: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 23Ptolemy Miniconference, February 13, 2007

Proof of Concept

A distributed version of Newton’s Cradle model

Page 24: 7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and

Zheng, Berkeley 24Ptolemy Miniconference, February 13, 2007

Summary

Developed a rigorous operational semantics that leverages principles from synchronous/reactive (SR) languages.

Applied this operational semantics to discrete-event (DE), continuous-time (CT), SR, finite-state machine (FSM), and hybrid system (CT + DE + FSM) models.