Divide and Recycle: Types and Compilation for a Hybrid Synchronous Language Albert Benveniste 1 Benoît Caillaud 1 Timothy Bourke 1 Marc Pouzet 1 , 2 , 3 1. INRIA 2. Institut Universitaire de France 3. École normale supérieure (LIENS) LCTES 2011, CPS Week, April 11–14, Chicago, IL, USA
Motivation Simulink Ptolemy Hybrid Systems Modelers . . . ◮ Platforms for simulation and development ◮ More and more important ◮ Semantics ◮ Efficiency and predictability ◮ Fidelity / Consistency
Motivation Simulink Ptolemy Hybrid Systems Modelers . . . ◮ Platforms for simulation and development ◮ More and more important ◮ Semantics ◮ Efficiency and predictability ◮ Fidelity / Consistency Conservative extension of a synchronous data-flow language
Motivation Simulink Ptolemy Hybrid Systems Modelers . . . ◮ Platforms for simulation and development ◮ More and more important ◮ Semantics ◮ Efficiency and predictability ◮ Fidelity / Consistency Conservative extension of a synchronous data-flow language What distinguishes our approach? ◮ Compilation with existing tools (after source-to-source transformation) ◮ Static typing ◮ Semantics based on non-standard analysis
Outline Background Hybrid Synchronous Language Semantics Compilation Execution Typing Conclusion
Modeling Model discrete systems with data-flow equations Model physical systems with Ordinary Differential Equations (ODEs)
Modeling Model discrete systems with data-flow equations Model physical systems with Ordinary Differential Equations (ODEs) (Causal) First-order ODEs ˙ y ( t ) = f ( t , y ) ◮ Causal: inputs on right, outputs on left instantaneous variables derivatives ◮ First-order: one equation = one variable y ( 0 ) = y i initial values
Bouncing ball model F = m · a − g = m · d 2 h ( t ) h dt 2 d 2 h ( t ) = − g / m dt 2
Bouncing ball model F = m · a − g = m · d 2 h ( t ) h dt 2 d 2 h ( t ) = − g / m dt 2 v ( 0 ) = v 0 ˙ v = − g / m ˙ h ( 0 ) = h 0 h = v
Bouncing ball model F = m · a − g = m · d 2 h ( t ) h dt 2 d 2 h ( t ) = − g / m dt 2 � t v ( t ) = v 0 + ( − g / m ) . d τ v ( 0 ) = v 0 v = − g / m ˙ 0 � t ˙ h ( 0 ) = h 0 h = v h ( t ) = h 0 + v (τ) . d τ 0
Bouncing ball model F = m · a − g = m · d 2 h ( t ) h dt 2 d 2 h ( t ) = − g / m dt 2 Solver approximation f y i � t v ( t ) = v 0 + ( − g / m ) . d τ v ( 0 ) = v 0 v = − g / m ˙ 0 � t ˙ h ( 0 ) = h 0 h = v h ( t ) = h 0 + v (τ) . d τ 0
Bouncing ball model up(-h) F = m · a − g = m · d 2 h ( t ) h dt 2 g d 2 h ( t ) = − g / m dt 2 event! Solver approximation f y i � t v ( t ) = v 0 + ( − g / m ) . d τ v ( 0 ) = v 0 v = − g / m ˙ 0 � t ˙ h ( 0 ) = h 0 h = v h ( t ) = h 0 + v (τ) . d τ 0
Solver execution t t
Solver execution f t t
Solver execution f f t t
Solver execution f f f t t
Solver execution f f f t g t
Solver execution f f f f t g g t
Solver execution f f f f f t g g g t ◮ Bigger and bigger steps (bound by h min and h max )
Solver execution 1. approximation error too large f f f f f f t g g g g t ◮ Bigger and bigger steps (bound by h min and h max )
Solver execution 1. approximation error too large f f f f f f f t g g g g t ◮ Bigger and bigger steps (bound by h min and h max )
Solver execution 1. approximation error too large f f f f f f f f t g g g g t ◮ Bigger and bigger steps (bound by h min and h max )
Solver execution 1. approximation error too large f f f f f f f f f t g g g g g t ◮ Bigger and bigger steps (bound by h min and h max )
Solver execution 1. approximation error too large f f f f f f f f f f t g g g g g g t ◮ Bigger and bigger steps (bound by h min and h max )
Solver execution 1. approximation error too large f f f f f f f f f f f t g g g g g g g t 2. expression crosses zero ◮ Bigger and bigger steps (bound by h min and h max )
Solver execution 1. approximation error too large f f f f f f f f f f f t g g g g g g g g t 2. expression crosses zero ◮ Bigger and bigger steps (bound by h min and h max )
Solver execution 1. approximation error too large f f f f f f f f f f f t g g g g g g g g g t 2. expression crosses zero ◮ Bigger and bigger steps (bound by h min and h max )
Solver execution 1. approximation error too large f f f f f f f f f f f t g g g g g g g g g g t 2. expression crosses zero ◮ Bigger and bigger steps (bound by h min and h max )
Solver execution 1. approximation error too large f f f f f f f f f f f t g g g g g g g g g g t 2. expression crosses zero ◮ Bigger and bigger steps (bound by h min and h max ) ◮ t does not necessarily advance monotonically ◮ Ok for continuous states (managed by solver) ◮ Cannot change state within f or g
Basic Hybrid Language Start with Lucid Synchrone (subset); add first-order ODEs with reset. x ( 0 ) = x i ˙ x ( t ) = f ( t , x ) instantaneous initial values variables derivatives
Basic Hybrid Language Start with Lucid Synchrone (subset); add first-order ODEs with reset. x ( 0 ) = x i ˙ x ( t ) = f ( t , x ) instantaneous initial values variables derivatives Rather than ˙ x = e d and x ( 0 ) = x i , write der x = e d init x i
Basic Hybrid Language Start with Lucid Synchrone (subset); add first-order ODEs with reset. x ( 0 ) = x i ˙ x ( t ) = f ( t , x ) instantaneous initial values variables derivatives Rather than ˙ x = e d and x ( 0 ) = x i , write der x = e d init reset e 1 every up( e z 1 ) x i
Basic Hybrid Language Start with Lucid Synchrone (subset); add first-order ODEs with reset. x ( 0 ) = x i ˙ x ( t ) = f ( t , x ) instantaneous initial values variables derivatives Rather than ˙ x = e d and x ( 0 ) = x i , write der x = e d init reset e 1 every up( e z 1 ) x i | e n every up( e z n ) · · ·
Basic Hybrid Language Start with Lucid Synchrone (subset); add first-order ODEs with reset. x ( 0 ) = x i ˙ x ( t ) = f ( t , x ) instantaneous initial values variables derivatives without default Rather than ˙ x = e d and x ( 0 ) = x i , write der x = e d init reset e 1 every up( e z 1 ) x i | e n every up( e z n ) · · · x = (pre h + 1) every up( e ) init e i
Basic Hybrid Language Start with Lucid Synchrone (subset); add first-order ODEs with reset. x ( 0 ) = x i ˙ x ( t ) = f ( t , x ) instantaneous initial values variables derivatives without default Rather than ˙ x = e d and x ( 0 ) = x i , write der x = e d init reset e 1 every up( e z 1 ) x i | e n every up( e z n ) · · · x = (pre h + 1) every up( e ) init e i | purely sync every event
Basic Hybrid Language Start with Lucid Synchrone (subset); add first-order ODEs with reset. x ( 0 ) = x i ˙ x ( t ) = f ( t , x ) instantaneous initial values variables derivatives without default without default Rather than ˙ x = e d and x ( 0 ) = x i , write der x = e d init reset e 1 every up( e z 1 ) x i | e n every up( e z n ) · · · with default x = (pre h + 1) every up( e ) default e c init e i | purely sync every event
Basic Hybrid Language Start with Lucid Synchrone (subset); add first-order ODEs with reset. x ( 0 ) = x i ˙ x ( t ) = f ( t , x ) instantaneous initial values variables derivatives without default without default Rather than ˙ x = e d and x ( 0 ) = x i , write der x = e d init reset e 1 every up( e z 1 ) x i | e n every up( e z n ) · · · with default x = (pre h + 1) every up( e ) default e c init e i | purely sync every event Very simple: no clocks, no automata, no higher-order
Bouncing ball program v ( 0 ) = v 0 ˙ v = − g / m ˙ h ( 0 ) = h 0 h = v h reset v to − 0 . 8 · v when h becomes 0 let hybrid ball ( ) = let rec der v = ( − . g / m) init v0 reset ( − . 0.8 *. last v) every up(–. h) and der h = v init h0 ( v , h) in
Semantics reals non-standard reals ⋆ R R + infinitesimals ( ∂ )
Semantics reals non-standard reals ⋆ R R + infinitesimals ( ∂ ) · · · < t − 3 ∂ < t − 2 ∂ < t − ∂ < t < t + ∂ < t + 2 ∂ < t + 3 ∂ < · · ·
Semantics reals non-standard reals ⋆ R R + infinitesimals ( ∂ ) · · · < t − 3 ∂ < t − 2 ∂ < t − ∂ < t < t + ∂ < t + 2 ∂ < t + 3 ∂ < · · · ◮ dense and discrete ◮ base clock for both continuous and discrete behaviors • t is the previous instant, t • is the next instant ◮ ∀ t . s ′ ( t ) integr # ( T )( s )( s 0 )( hs )( t ) where = s ′ ( t ) if t = min ( T ) = s 0 ( t ) s ′ ( t ) s ′ ( • t ) + ∂ s ( • t ) if handler # ( T )( hs )( t ) = NoEvent = s ′ ( t ) if handler # ( T )( hs )( t ) = Xcrossing ( v ) v = up # ( T )( s )( t ) if t = min ( T ) = false up # ( T )( s )( t • ) if ( s ( • t ) ≤ 0 ) ∧ ( s ( t ) > 0 ) and ( t ∈ T ) = true up # ( T )( s )( t • ) otherwise = false . . . . . . . . .
Recommend
More recommend