The Operational Semantics of Hybrid Systems

54
The Operational Semantics of Hybrid Systems Edward A. Lee Professor, Chair of EE, and Associate Chair of EECS, UC Berkeley With contributions from: Adam Cataldo, Jie Liu, Xiaojun Liu, Eleftherios Matsikoudis, and Haiyang Zheng Invited Plenary Talk Hybrid Systems: Computation and Control (HSCC) Zurich, Switzerland, March 9, 2005 Center for Hybrid and Embedded Software Systems

description

The Operational Semantics of Hybrid Systems. Edward A. Lee Professor, Chair of EE, and Associate Chair of EECS, UC Berkeley With contributions from: Adam Cataldo, Jie Liu, Xiaojun Liu, Eleftherios Matsikoudis, and Haiyang Zheng Invited Plenary Talk - PowerPoint PPT Presentation

Transcript of The Operational Semantics of Hybrid Systems

Page 1: The Operational Semantics of Hybrid Systems

The Operational Semantics of Hybrid SystemsEdward A. LeeProfessor, Chair of EE, andAssociate Chair of EECS,UC Berkeley

With contributions from:Adam Cataldo, Jie Liu, Xiaojun Liu, Eleftherios Matsikoudis, and Haiyang Zheng

Invited Plenary TalkHybrid Systems: Computation and Control (HSCC)Zurich, Switzerland, March 9, 2005

Center for Hybrid and Embedded Software Systems

Page 2: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 2

The Premise

Hybrid Systems can be thought of as executable programs. In this case, they need to be given an

executable semantics.

Page 3: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 3

Outline

Signals with discontinuities Ideal solver semantics Choosing step sizes Discrete phase of execution Miscellanenous issues

Enabling vs. triggering guardsOrder of reactions to simultaneous eventsNondeterministic state machinesSampling discontinuous signalsZeno behaviors

Page 4: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 4

A Hybrid Systems Example

Consider two masses on springs which, when they collide, will stick together with a decaying stickiness until the force of the springs pulls them apart again.

Page 5: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 5

Modal Models

The Masses actor refines to a state machine with two states, Separate and Together. The transitions have guards and reset maps.

Page 6: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 6

Mode Refinements

Each state has a refinement that gives the behavior of the modal model while in that state.

Page 7: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 7

Modeling Dynamics within theSeparate ModeDynamics while separate:

Equivalently:

Page 8: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 8

Mode Refinements (2)

In the Together mode, the dynamics is that of a single mass and two springs.

Page 9: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 9

Modeling Dynamics within theTogether ModeDynamics while together:

Page 10: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 10

Implied in the Mathematical Formulation:Continuous-Time SignalsThe usual formulation of the signals of interest is a function from the time line T (a connected subset of the reals) to the reals:

Such signals are continuous at t T if (e.g.):

Page 11: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 11

Piecewise Continuous Signals

In hybrid systems of interest, signals have discontinuities.

Piecewise continuous signals are continuous at all t T \ D where D T is a discrete set.1

1A set D with an order relation is a discrete set if there exists an order embedding to the integers).

Page 12: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 12

Operational Semantics of Hybrid Systems

A computer execution of a hybrid system is constrained to provide values on a discrete set:

Given this constraint, choosing T as the domain of these functions is an unfortunate choice. It makes it impossible to unambiguously represent discontinuities.

Page 13: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 13

Definition: Continuously Evolving Signal

Change the domain of the function:

Where T is a connected subset of the reals and is the set of natural numbers.

At each time t T , the signal x has a sequence of values. Where the signal is continuous, all the values are the same. Where is discontinuous, it has multiple values.

Page 14: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 14

Simpler Example: Hysteresis

This model shows the use of a two-state FSM to model hysteresis.

Semantically, the output of the ModalModel block is discontinuous. If transitions take zero time, this is modeled as a signal that has two values at the same time, and in a particular order.

Page 15: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 15

Signals Must Have Multiple Values at theTime of a Discontinuity

Discontinuities need to be semantically distinguishable from rapid continuous changes.

Page 16: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 16

Initial and Final Value Signals

A signal has no chattering Zeno condition if there is an integer m > 0 such that

A non-chattering signal has a corresponding final value signal, where

It also has an initial value signal where

Page 17: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 17

Piecewise Continuous Signals

A piecewise continuous signal is a non-chattering signal

where The initial signal xi is continuous on the left, The final signal xf is continuous on the right, and The signal x has only one value at all t T \ D where D T is a discrete set.

Page 18: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 18

Outline

Signals with discontinuities Ideal solver semantics Choosing step sizes Discrete phase of execution Miscellanenous issues

Enabling vs. triggering guardsOrder of reactions to simultaneous eventsNondeterministic state machinesSampling discontinuous signalsZeno behaviors

Page 19: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 19

Discrete Trace:What it Means to Execute a Hybrid SystemLet D' T be a discrete set that includes at least the initial time and the times of all discontinuities.A discrete trace of the signal x is a set:

An execution of a hybrid system is the construction of a discrete trace:

tt0 t1 t2t3 ts...

Page 20: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 20

Ideal Solver Semantics[Liu and Lee, HSCC 2003]

In the ideal solver semantics, the ODE governing the hybrid system has a unique solution for all intervals [ti , ti+1) for each neighboring ti < ti+1 D' . The discrete trace loses nothing by not representing values within these intervals.

Although an idealization, this is not far fetched. The spring masses example, for instance, conforms with the assumptions and can be executed by an ideal solver.

tt0 t1 t2t3 ts...

Page 21: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 21

Modeling Continuous Dynamics withDiscrete Traces

A basic continuous-time model describes an ordinary differential equation (ODE).

Page 22: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 22

Structure of the Model ofContinuous Dynamics

A basic continuous-time model describes an ordinary differential equation (ODE).

)),(()( ttxftx

)),(( ttxf

x

t

t

dxtxtx0

)()()( 0

Page 23: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 23

Abstracted Structure of the Model ofContinuous DynamicsBetween discontinuities, the state trajectory is modeled as a vector function of time,

)),(()( ttxftx

)),(( ttxf t

t

dxtxtx0

)()()( 0 xx

nRTx :

mm RTRf :

RtT ),[ 0

The key to the ideal solver semantics is that continuity and local Lipschitz conditions on f are sufficient to ensure uniqueness of the solution over a sufficiently small interval of time.

Page 24: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 24

Outline

Signals with discontinuities Ideal solver semantics Choosing step sizes Discrete phase of execution Miscellanenous issues

Enabling vs. triggering guardsOrder of reactions to simultaneous eventsNondeterministic state machinesSampling discontinuous signalsZeno behaviors

Page 25: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 25Require backtracking

Points on the Time Line that Must BeIncluded in a Discrete Trace Predictable breakpoints

Can be registered in advance with the solver

Unpredictable breakpointsKnown after they have been missed

Points that make the step size “sufficiently small”Dependent on error estimation in the solver

Page 26: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 26

E.g. Runge-Kutta 2-3 Solver (RK2-3)

Given x(tn) and a time increment h, calculate

then let

Note that this requires three evaluations of f at three different times with three different inputs.

)75.0,75.0)(()5.0,5.0)((

)),((

12

01

0

hthKtxfKhthKtxfK

ttxfK

nn

nn

nn

)( ntx

)5.0( htx n

)75.0( htx n

estimate of

estimate of

2101

1

)9/4()9/3()9/2()()( hKhKhKtxtxhtt

nn

nn

Page 27: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 27

Operational Requirements

In a software system, the blue box below can be specified by a program that, given x(t) and t calculates f (x(t), t ) . But this requires that the program be functional (have no side effects).

)),(()( ttxftx

)),(( ttxf t

t

dxtxtx0

)()()( 0 xx

mm RTRf :

Page 28: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 28

Adjusting the Time Steps

For time step given by , let

If is less than the “error tolerance” e, then the step is deemed “successful” and the next time step is estimated at:

If is greater than the “error tolerance,” then the time step h is reduced and the whole thing is tried again.

htt nn 1

))8/1()9/1()12/1()72/5(()),((

3210

113

KKKKhttxfK nn

3 /8.0 eh

Page 29: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 29

Examining This Computationally

At each discrete time tn, given a time increment tn+1 = tn+ h, we can estimate x(tn+1) by repeatedly evaluating f with different values for the arguments. We may then decide that h is too large and reduce it and redo the process.

)),(( ttxf t

t

dxtxtx0

)()()( 0 xx

Page 30: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 30

How General Is This Model?

Does it handle:Systems without feedback? yesExternal inputs? yesState machines? noThe model itself as a function? no

)),(()( ttxftx

x

)),(( ttxf t

t

dxtxtx0

)()()( 0 xx

Page 31: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 31

How General Is This Model?

Does it handle:Systems without feedback? yesExternal inputs? yesState machines? noThe model itself as a function? no

)),(()( ttxftx

ft

dxxtx0

)()0()( x

x

Page 32: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 32

How General Is This Model?

Does it handle:Systems without feedback? yesExternal inputs? yesState machines? noThe model itself as a function? no

)),(),(()),(()( ttxtugttxftx

ft

dxxtx0

)()0()( x

x

gu

Page 33: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 33

How General Is This Model?

Does it handle:Systems without feedback? yesExternal inputs? yesState machines? no, not immediatelyThe model itself as a function? no

t

dxxtx0

)()0()( x

x

)),(()( ttxftx

Page 34: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 34

Actors with State Must Expose that State

Basic actor with firing:

Ss 1 Ss 2

][ RNTS

The new function f gives outputs in terms of inputs and the current state. The function g updates the state at the specified time.

state space

Stateful actor:

mm RTRf :][ RTS

TRg m:

mm RTRf :

Ss 1 Ss 2

)),(()(, 12 ttsftsTt

?),(,),( 2 ntsNTnt

Page 35: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 35

Stateful Actors Support Unpredictable Breakpoints and Step Size Adaptation

Ss 1 Ss 2

][ RNTS mm RTRf :

TRg m:

At each t T the calculation of the output given the input is separated from the calculation of the new state. Thus, the state does not need to updated until after the step size has been decided upon.

In fact, a variable step size solver relies on this, since any of several integration calculations may result in refinement of the step size because the error is too large.

Page 36: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 36

How General Is This Model?

Does it handle:Systems without feedback? yesExternal inputs? yesState machines? yes, with stateful actorsThe model itself as a function? yes, but be

careful!

t

t

dxtxtx0

)()()( 0 xx

)),(( ttxf t

t

dxtxtx0

)()()( 0 xx

Page 37: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 37

Why do we Care? Compositionality

A correct result

An incorrect result

A designer expects certain invariants: transformations of a model that do not change behavior.

Results are calculated with the RK 2-3 solver.

Haiyang Zheng noticed that earlier versions of HyVisual did not exhibit compositional behavior.

Page 38: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 38

Why is Compositionality Difficult to Achieve?In general, the behavior of the inside system must be given by functions of form:

t

t

dxtxtx0

)()()( 0 xx

)),(( ttxf t

t

dxtxtx0

)()()( 0 xx

mm RTRf : TRg m:

To make this work, the state of the solver must be part of the state space of the composite actor!

Page 39: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 39

Compositional Execution Requires thatSolvers Expose DetailsAn RK 2-3 solver evaluates signal values at intermediate points in time that do not truly qualify as a step. Given two RK 2-3 solvers in a hierarchy, if they do not cooperate on this, then the behavior is altered by the hierarchy.

The HyVisual Solution: Solvers that are separated in the hierarchy by at most a Modal Model cooperate if they are the same type of solver. This is compositional, but This also allows heterogeneous mixtures of solvers.

Page 40: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 40

Outline

Signals with discontinuities Ideal solver semantics Choosing step sizes Discrete phase of execution Miscellanenous issues

Enabling vs. triggering guardsOrder of reactions to simultaneous eventsNondeterministic state machinesSampling discontinuous signalsZeno behaviors

Page 41: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 41

Transient StatesA Useful Model for Software

If an outgoing guard is true upon entering a state, then the time spent in that state is identically zero. This is called a “transient state.”

Page 42: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 42

Transient Values Integrate to Zero

Transient values do not affect the integral of the signal, as expected.

Page 43: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 43

Contrast with Simulink/Stateflow

Transient States

The simulator engine of Simulink introduces a non-zero delay to consecutive transitions.

In Simulink semantics, a signal can only have one value at a given time. Consequently, Simulink introduces solver-dependent behavior.

Page 44: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 44

Discrete Phase of Execution

Ss 1 Ss 2

][ RNTS mm RTRf :

TRg m:

...)),(),(()()),(),(()1,(

)),(),(()()),(),(()0,(

112

112

11

12

ttstgtttstfts

ttstgtttstfts

until the state no longer changes. We use the final state on any evaluation at later times.

At each t T the output is a sequence of one or more values where given the current state (t) and the input s1(t) we evaluate the procedure

Commit to step here

Page 45: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 45

Outline

Signals with discontinuities Ideal solver semantics Choosing step sizes Discrete phase of execution Miscellanenous issues

Enabling vs. triggering guardsOrder of reactions to simultaneous eventsNondeterministic state machinesSampling discontinuous signalsZeno behaviors

Page 46: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 46

Issue 1: Enabling vs. Triggering Guards

In Modal Models, guards on could have either of two semantic interpretations: enabling or triggering.

If only enabling semantics are provided, then it becomes nearly impossible to give models whose behavior does not depend on the step-size choices of the solver.

HyVisual uses triggering semantics. Enabling semantics can be realized with an explicit Monte Carlo model.

Page 47: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 47

Issue 2: Order of Reaction to Simultaneous Events

Given an event from the event source, which of these should react first? Nondeterministic? Data precedences?

Simulink/Stateflow and HyVisual declare this to be deterministic, based on data precedences. Actor1 executes before Actor2.

Some formal hybrid systems languages declare this to be nondeterministic. We believe this is the wrong choice.

RNTs :Semantics of a signal:

In HyVisual, every continuous-time signal has a value at (t, 0) for any t T . This yields deterministic execution of the above model.

Page 48: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 48

Issue 3: Nondeterministic State Machines

At a time when the event source yields a positive number, both transitions are enabled.

Although this can be done in principle, HyVisual does not support this sort of nondeterminism. What execution trace should it give?

HyVisual supports explicit Monte Carlo models of nondeterminism.

Page 49: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 49

Issue 4: Sampling Discontinuous Signals

Samples must be deterministically taken at t- or t+. Our choice is t-, inspired by hardware setup times. Note that in HyVisual, unlike Simulink,

discrete signals have no value except at discrete points.

Continuous signal with sample times chosen by the solver:

Discrete result of sampling:

Page 50: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 50

Issue 5: Zeno Conditions

Zeno behavior is a property of the discrete events in a system, not a property of its continuous dynamics. The continuous dynamics merely determine the time between events.

Page 51: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 51

Zeno Behavior Can Be Dealt With (almost) Entirely in Discrete Events.Let the set of all signals be S = [T N V ] where V is a set of values. Let an actor

be a function F : S n S m . What are the constraints on such functions such that:

1. Compositions of actors are determinate.2. Feedback compositions have a meaning. 3. We can rule out Zeno behavior.

A sufficient condition is that every feedback loop have a lower bound on its time delay. See [Lee 1999] for a review of this result, based on the Cantor Metric.

Page 52: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 52

Observations

If there is a lower bound on the step size: All signals are discrete

there is an order embedding to the natural numbers Integrators with the RK2-3 solver are delta causal,

sosolution with feedback is uniqueno Zeno in discretized stepsbut lower bound on the step size implies inaccuracies

Integrators with some methods (e.g. trapeziodal rule) are not delta causal, nor even strictly causal, so we have no assurance of a unique solution in feedback systems.

Page 53: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 53

Summary

Signals must be able to have multiple values at a time.

Actors must separate reactions to inputs from state updates Supports event detection Allows iterative step-size adjustment

Compositionality Need to be able to mix solvers Need to be able to add hierarchy without changing behavior

Many detail issues in designing executable hybrid systems: Guards should trigger rather than enable transitions. Precedence analysis is essential. Nondeterminism is easily added with Monte Carlo methods Sampling at discontinuitites needs to be well-defined. Zeno conditions are a discrete event phenomenon

Page 54: The Operational Semantics of Hybrid Systems

Lee, Berkeley: 54

Open Source Software: HyVisual – Executable Hybrid System Modeling Built on Ptolemy II

HyVisual 5.0-alpha was released in March, 2005.