Abstraction Refinement for Probabilistic Software Sascha Kurowski - - PowerPoint PPT Presentation

abstraction refinement for probabilistic software
SMART_READER_LITE
LIVE PREVIEW

Abstraction Refinement for Probabilistic Software Sascha Kurowski - - PowerPoint PPT Presentation

Abstraction Refinement for Probabilistic Software Abstraction Refinement for Probabilistic Software Sascha Kurowski 6. Juli 2016 0/25 1/25 Sascha Kurowski | 6. Juli 2016 Sascha Kurowski | 6. Juli 2016 Probabilistic programs Outline ANSI-C


slide-1
SLIDE 1

Abstraction Refinement for Probabilistic Software

Sascha Kurowski

  • 6. Juli 2016

0/25 Sascha Kurowski | 6. Juli 2016 Abstraction Refinement for Probabilistic Software 1/25 Sascha Kurowski | 6. Juli 2016

slide-2
SLIDE 2

ANSI-C program

Probabilistic programs

Outline

2/25 Sascha Kurowski | 6. Juli 2016

slide-3
SLIDE 3

int main ( ) { 1: int c = ndet (2) + 1; 2: while (0 < c && c < 3) { 3: c += coin ( 0 . 5 ) ? 1:−1; } 4: assert ( c > 0 ) ; }

Probabilistic programs

Gambler’s ruin

3/25 Sascha Kurowski | 6. Juli 2016

slide-4
SLIDE 4

int main ( ) { 1: int c = ndet (2) + 1; 2: while (0 < c && c < 3) { 3: c += coin ( 0 . 5 ) ? 1:−1; } 4: assert ( c > 0 ) ; }

Non-deterministic choice: int ndet(int n)

◮ No information about outcome ◮ Returns any value between 0 and n ◮ E.g. user input or underspecified function

Probabilistic programs

Gambler’s ruin

3/25 Sascha Kurowski | 6. Juli 2016

slide-5
SLIDE 5

int main ( ) { 1: int c = ndet (2) + 1; 2: while (0 < c && c < 3) { 3: c += coin ( 0 . 5 ) ? 1:−1; } 4: assert ( c > 0 ) ; }

Probabilistic choices: int coin(float p)

◮ Likelyhood of each possible outcome known ◮ Returns 1 with probability p and 0 with probability 1 − p ◮ E.g. randomization or network communication

Probabilistic programs

Gambler’s ruin

3/25 Sascha Kurowski | 6. Juli 2016

slide-6
SLIDE 6

int main ( ) { 1: int c = ndet (2) + 1; 2: while (0 < c && c < 3) { 3: c += coin ( 0 . 5 ) ? 1:−1; } 4: assert ( c > 0 ) ; }

Probabilistic programs

Gambler’s ruin

3/25 Sascha Kurowski | 6. Juli 2016

slide-7
SLIDE 7

ANSI-C program Probabilistic program Model extraction

Probabilistic programs

Outline

4/25 Sascha Kurowski | 6. Juli 2016

slide-8
SLIDE 8

int main ( ) { 1: int c = ndet (2) + 1; 2: while (0 < c && c < 3) { 3: c += coin ( 0 . 5 ) ? 1:−1; } 4: assert ( c > 0 ) ; }

1 2 4 3

c=ndet(2)+1 if (0 < c && c < 3) c += coin(0.5) ? 1:−1 if (c <= 0 || c >= 3)

Probabilistic programs

Gambler’s ruin

5/25 Sascha Kurowski | 6. Juli 2016

slide-9
SLIDE 9

1 2 4 3

c=ndet(2)+1 if(0 < c && c < 3) c += coin(0.5) ? 1:−1 if (c <= 0 || c >= 3)

Probabilistic programs

Semantics of probabilistic programs

6/25 Sascha Kurowski | 6. Juli 2016

slide-10
SLIDE 10

1 : c = 0 2 : c = 2 2 : c = 1 2 : c = 0 2 : c = 3 3 : c = 2 3 : c = 1 4 : c = 0 4 : c = 3 1 1 1 1 1 1 0.5 0.5 0.5 0.5

Probabilistic programs

Semantics of probabilistic programs

7/25 Sascha Kurowski | 6. Juli 2016

slide-11
SLIDE 11

◮ Schedulers resolve non-determinism by mapping each state to a

non-deterministic choice

1 : c = 0 2 : c = 2 2 : c = 1 2 : c = 0 2 : c = 3 3 : c = 2 3 : c = 1 4 : c = 0 4 : c = 3 1 1 1 1 1 1 0.5 0.5 0.5 0.5

Model checking

Schedulers

8/25 Sascha Kurowski | 6. Juli 2016

slide-12
SLIDE 12

◮ Schedulers resolve non-determinism by mapping each state to a

non-deterministic choice

1 : c = 0 2 : c = 2 2 : c = 1 2 : c = 0 2 : c = 3 3 : c = 2 3 : c = 1 4 : c = 0 4 : c = 3 1 1 1 1 1 1 0.5 0.5 0.5 0.5

Model checking

Schedulers

8/25 Sascha Kurowski | 6. Juli 2016

slide-13
SLIDE 13

◮ Schedulers resolve non-determinism by mapping each state to a

non-deterministic choice

1 : c = 0 2 : c = 2 2 : c = 1 2 : c = 0 2 : c = 3 3 : c = 2 3 : c = 1 4 : c = 0 4 : c = 3 1 1 1 1 1 1 0.5 0.5 0.5 0.5

Model checking

Schedulers

8/25 Sascha Kurowski | 6. Juli 2016

slide-14
SLIDE 14

Problem

◮ Calculating the probability of a state is impossible ◮ Instead, there is a separate probability for each scheduler

Idea

◮ Define properties over minimal and maximal probabilities ◮ I.e. consider the best-case and the worst-case scheduler

Model checking

Probabilities

9/25 Sascha Kurowski | 6. Juli 2016

slide-15
SLIDE 15

Probability of ♦red

◮ Scheduler c = 1: 1 2 1 + 1 2 3 + 1 2 5 + · · · = 2 3

Model checking

Probabilities

10/25 Sascha Kurowski | 6. Juli 2016

slide-16
SLIDE 16

Probability of ♦red

◮ Scheduler c = 1: 1 2 1 + 1 2 3 + 1 2 5 + · · · = 2 3 ◮ Scheduler c = 2: 1 2 × ( 1 2 1 + 1 2 3 + 1 2 5 + . . . ) = 1 3

Model checking

Probabilities

10/25 Sascha Kurowski | 6. Juli 2016

slide-17
SLIDE 17

Probability of ♦red

◮ Scheduler c = 1: 1 2 1 + 1 2 3 + 1 2 5 + · · · = 2 3

Maximal probability

◮ Scheduler c = 2: 1 2 × ( 1 2 1 + 1 2 3 + 1 2 5 + . . . ) = 1 3

Minimal probability

Model checking

Probabilities

10/25 Sascha Kurowski | 6. Juli 2016

slide-18
SLIDE 18

Probability of ♦red

◮ Scheduler c = 1: 1 2 1 + 1 2 3 + 1 2 5 + · · · = 2 3 ◮ Scheduler c = 2: 1 2 × ( 1 2 1 + 1 2 3 + 1 2 5 + . . . ) = 1 3 ◮ Probabilities can be calculated using a linear optimisation problem

Model checking

Probabilities

10/25 Sascha Kurowski | 6. Juli 2016

slide-19
SLIDE 19

◮ MDP semantics often have too many (or even infinitely many) states

int main ( ) { 1: int c = 0; 2: bool f a i l = false ; 3: while ( ! f a i l ) { 4: f a i l = coin ( 0 . 5 ) ; 5: c++; 6: } } 1 2 3 6 4 5 c=0 fail =false if (! fail ) if ( fail ) fail =coin(0.5) c++

Model checking

State space explosion

11/25 Sascha Kurowski | 6. Juli 2016

slide-20
SLIDE 20

Problem |M| ≈ 232 + · · · + 232

  • Number of 32-bit integer variables

×Number of statements Idea

Reduce the value ranges of variables

Model checking

State space explosion

12/25 Sascha Kurowski | 6. Juli 2016

slide-21
SLIDE 21

ANSI-C program Probabilistic program Boolean probabilistic program Stochastic game Model extraction Model construction

Abstraction of Probabilistic Programs

Outline

13/25 Sascha Kurowski | 6. Juli 2016

slide-22
SLIDE 22

Solution

Replace original variables with predicates (boolean expressions)

Abstraction of Probabilistic Programs

Predicate abstraction

14/25 Sascha Kurowski | 6. Juli 2016

slide-23
SLIDE 23

Solution

Replace original variables with predicates (boolean expressions) int main ( ) { int i = 0; while ( true ) { assert ( i != 443); i f ( i < 10) { i = i + 1; } else i = i + 2; } }

Abstraction of Probabilistic Programs

Predicate abstraction

14/25 Sascha Kurowski | 6. Juli 2016

slide-24
SLIDE 24

Solution

Replace original variables with predicates (boolean expressions) int main ( ) { int i = 0; while ( true ) { assert ( i != 443); i f ( i < 10) { i = i + 1; } else i = i + 2; } } Predicates: i < 10, i mod 2 = 0

✓✓ 0, 2, . . . , 8 ✓✗ 1, 3, . . . , 9 ✗✗ . . . , 443, . . . ✗✓ 10, 12, . . .

  • Min. and max. Prob(♦✗✗) = 0

Abstraction of Probabilistic Programs

Predicate abstraction

14/25 Sascha Kurowski | 6. Juli 2016

slide-25
SLIDE 25

Solution

Replace original variables with predicates (boolean expressions) int main ( ) { int i = 0; while ( true ) { assert ( i != 443); i f ( i < 10) { i = i + 1; } else i = i + 2; } } Predicates: i < 10, i mod 2 = 0

✓✓ 0, 2, . . . , 8 ✓✗ 1, 3, . . . , 9 ✗✗ . . . , 443, . . . ✗✓ 10, 12, . . .

  • Min. and max. Prob(♦✗✗) = 0

Abstraction of Probabilistic Programs

Predicate abstraction

14/25 Sascha Kurowski | 6. Juli 2016

slide-26
SLIDE 26

Definition

A two-player stochastic game is a tuple ˆ

M = ( ˆ S, ˆ sinit, ˆ P) with

◮ countable, non-empty set of

states ˆ

S

◮ initial state ˆ

sinit ∈ ˆ S

◮ transition function

ˆ P : ˆ S → P(P(Dist ˆ

S))

A B C 0.5 0.5 1 0.4 0.6 1 1 1

Abstraction of Probabilistic Programs

Two-player stochastic game

15/25 Sascha Kurowski | 6. Juli 2016

slide-27
SLIDE 27

Definition

A two-player stochastic game is a tuple ˆ

M = ( ˆ S, ˆ sinit, ˆ P) with

◮ countable, non-empty set of

states ˆ

S

◮ initial state ˆ

sinit ∈ ˆ S

◮ transition function

ˆ P : ˆ S → P(P(Dist ˆ

S))

A B C 0.5 0.5 1 0.4 0.6 1 1 1

Abstraction of Probabilistic Programs

Two-player stochastic game

15/25 Sascha Kurowski | 6. Juli 2016

slide-28
SLIDE 28

Definition

A two-player stochastic game is a tuple ˆ

M = ( ˆ S, ˆ sinit, ˆ P) with

◮ countable, non-empty set of

states ˆ

S

◮ initial state ˆ

sinit ∈ ˆ S

◮ transition function

ˆ P : ˆ S → P(P(Dist ˆ

S))

A B C 0.5 0.5 1 0.4 0.6 1 1 1

Abstraction of Probabilistic Programs

Two-player stochastic game

15/25 Sascha Kurowski | 6. Juli 2016

slide-29
SLIDE 29

Definition

A two-player stochastic game is a tuple ˆ

M = ( ˆ S, ˆ sinit, ˆ P) with

◮ countable, non-empty set of

states ˆ

S

◮ initial state ˆ

sinit ∈ ˆ S

◮ transition function

ˆ P : ˆ S → P(P(Dist ˆ

S))

A B C 0.5 0.5 1 0.4 0.6 1 1 1

Abstraction of Probabilistic Programs

Two-player stochastic game

15/25 Sascha Kurowski | 6. Juli 2016

slide-30
SLIDE 30

Definition

A two-player stochastic game is a tuple ˆ

M = ( ˆ S, ˆ sinit, ˆ P) with

◮ countable, non-empty set of

states ˆ

S

◮ initial state ˆ

sinit ∈ ˆ S

◮ transition function

ˆ P : ˆ S → P(P(Dist ˆ

S))

A B C 0.5 0.5 1 0.4 0.6 1 1 1

Abstraction of Probabilistic Programs

Two-player stochastic game

15/25 Sascha Kurowski | 6. Juli 2016

slide-31
SLIDE 31

Definition

A two-player stochastic game is a tuple ˆ

M = ( ˆ S, ˆ sinit, ˆ P) with

◮ countable, non-empty set of

states ˆ

S

◮ initial state ˆ

sinit ∈ ˆ S

◮ transition function

ˆ P : ˆ S → P(P(Dist ˆ

S))

A B C 0.5 0.5 1 0.4 0.6 1 1 1

Abstraction of Probabilistic Programs

Two-player stochastic game

15/25 Sascha Kurowski | 6. Juli 2016

slide-32
SLIDE 32

ANSI-C program Probabilistic program Boolean probabilistic program Stochastic game error ≤ ǫ? Results Model extraction Model construction Model checking Yes

Abstraction of Probabilistic Programs

Outline

16/25 Sascha Kurowski | 6. Juli 2016

slide-33
SLIDE 33

Predicates: c = 0, c = 2

1 : c = 0 2 : c = 3 2 : c = 1 2 : c = 0 2 : c = 2 3 : c = 2 3 : c = 1 4 : c = 0 4 : c = 3 1 1 1 1 1 1 0.5 0.5 0.5 0.5

Abstraction of Probabilistic Programs

Abstraction of Gambler’s ruin

17/25 Sascha Kurowski | 6. Juli 2016

slide-34
SLIDE 34

1 : c = 0, c = 2 2 : c = 0, c = 2 3 : c = 0, c = 2 2 : c = 0, c = 2 3 : c = 0, c = 2 4 : c = 0, c = 2 2 : c = 0, c = 2 4 : c = 0, c = 2 1 1 1 1 1 1 0.5 0.5 1

Abstraction of Probabilistic Programs

Abstraction of Gambler’s ruin

18/25 Sascha Kurowski | 6. Juli 2016

slide-35
SLIDE 35

1 : c = 0, c = 2 2 : c = 0, c = 2 3 : c = 0, c = 2 2 : c = 0, c = 2 3 : c = 0, c = 2 4 : c = 0, c = 2 2 : c = 0, c = 2 4 : c = 0, c = 2 1 1 1 1 1 1 0.5 0.5 1 Player 2 decision: Represents non-determinism of original

Abstraction of Probabilistic Programs

Abstraction of Gambler’s ruin

18/25 Sascha Kurowski | 6. Juli 2016

slide-36
SLIDE 36

1 : c = 0, c = 2 2 : c = 0, c = 2 3 : c = 0, c = 2 2 : c = 0, c = 2 3 : c = 0, c = 2 4 : c = 0, c = 2 2 : c = 0, c = 2 4 : c = 0, c = 2 1 1 1 1 1 1 0.5 0.5 1 Player 1 decision: Represents non-determinism introduced by abstraction

Abstraction of Probabilistic Programs

Abstraction of Gambler’s ruin

18/25 Sascha Kurowski | 6. Juli 2016

slide-37
SLIDE 37

1 : c = 0, c = 2 2 : c = 0, c = 2 3 : c = 0, c = 2 2 : c = 0, c = 2 3 : c = 0, c = 2 4 : c = 0, c = 2 2 : c = 0, c = 2 4 : c = 0, c = 2 1 1 1 1 1 1 0.5 0.5 1 Playing the Min-Max game: Player 1 goal: Get away from red Player 2 goal: Get to red

Abstraction of Probabilistic Programs

Abstraction of Gambler’s ruin

18/25 Sascha Kurowski | 6. Juli 2016

slide-38
SLIDE 38

1 : c = 0, c = 2 2 : c = 0, c = 2 3 : c = 0, c = 2 2 : c = 0, c = 2 3 : c = 0, c = 2 4 : c = 0, c = 2 2 : c = 0, c = 2 4 : c = 0, c = 2 1 1 1 1 1 1 0.5 0.5 1 Playing the Max-Max game: Player 1 and player 2 goal: Get to red

Abstraction of Probabilistic Programs

Abstraction of Gambler’s ruin

18/25 Sascha Kurowski | 6. Juli 2016

slide-39
SLIDE 39

Theorem

Probabilities in abstraction give bounds on original probabilities

pMin−Min( ˆ F) ≤ pMin(F) ≤ pMax−Min( ˆ F) pMin−Max( ˆ F) ≤ pMax(F) ≤ pMax−Max( ˆ F) pMin−Max(♦red) = 0 ≤ pMax(♦red) ≤ 1 = pMax−Max(♦red) Problem

No meaningful information: error ǫ = 1 =

⇒ Imprecise abstraction

Abstraction of Probabilistic Programs

Model checking

19/25 Sascha Kurowski | 6. Juli 2016

slide-40
SLIDE 40

ANSI-C program Probabilistic program Boolean probabilistic program Stochastic game error ≤ ǫ? Predicates Results Model extraction Model construction Model checking No Refinement Yes

Abstraction refinement

Outline

20/25 Sascha Kurowski | 6. Juli 2016

slide-41
SLIDE 41

Solution: Abstraction refinement

◮ Identify refinable state with distinct choices in min and max case, e.g.

◮ state with highest error

(difference between minimal and maximal probability)

◮ state nearest to initial state

◮ Case distinction on the label of the outgoing edges

Abstraction refinement

Abstraction refinement

21/25 Sascha Kurowski | 6. Juli 2016

slide-42
SLIDE 42

1 : c = 0, c = 2 2 : c = 0, c = 2 3 : c = 0, c = 2 2 : c = 0, c = 2 3 : c = 0, c = 2 4 : c = 0, c = 2 2 : c = 0, c = 2 4 : c = 0, c = 2 1 1 1 1 1 1 0.5 0.5 1 Blue is a refinable state: Decision made there leads to the high error

Abstraction refinement

Abstraction of Gambler’s ruin

22/25 Sascha Kurowski | 6. Juli 2016

slide-43
SLIDE 43

1 : c = 0, c = 2 2 : c = 0, c = 2 3 : c = 0, c = 2 2 : c = 0, c = 2 3 : c = 0, c = 2 4 : c = 0, c = 2 2 : c = 0, c = 2 4 : c = 0, c = 2 1 1 1 1 1 1 0.5 0.5 1 Outgoing edges in CFG are conditionals if (c <= 0 || c >= 3) and if (0 < c && c < 3)

Abstraction refinement

Abstraction of Gambler’s ruin

22/25 Sascha Kurowski | 6. Juli 2016

slide-44
SLIDE 44

1 : c = 0, c = 2 2 : c = 0, c = 2 3 : c = 0, c = 2 2 : c = 0, c = 2 3 : c = 0, c = 2 4 : c = 0, c = 2 2 : c = 0, c = 2 4 : c = 0, c = 2 1 1 1 1 1 1 0.5 0.5 1 We can add the new predicate c ≤ 0 ∨ c ≥ 3

Abstraction refinement

Abstraction of Gambler’s ruin

22/25 Sascha Kurowski | 6. Juli 2016

slide-45
SLIDE 45

◮ Model checking the abstraction gives exact results (error ǫ = 0) ◮ Refined abstraction is isomorphic to the original program

Using the predicates we can separate all possible values of c

◮ So here we haven’t gained much ◮ But the method is very efficient for real-world examples

Abstraction refinement

Abstraction of Gambler’s ruin

23/25 Sascha Kurowski | 6. Juli 2016

slide-46
SLIDE 46

ANSI-C program Probabilistic program Boolean probabilistic program Abstract MDP error ≤ ǫ? Predicates Results Model extraction Model construction Model checking No Refinement Yes

Conclusion

Abstraction-refinement loop

24/25 Sascha Kurowski | 6. Juli 2016

slide-47
SLIDE 47

Thank you for your attention

Questions?

25/25 Sascha Kurowski | 6. Juli 2016