Constraint Based Synthesis FROM SKETCHES TO STORYBOARDS Rishabh

  • Slides: 44
Download presentation
Constraint Based Synthesis FROM SKETCHES TO STORYBOARDS Rishabh Singh and Armando Solar-Lezama

Constraint Based Synthesis FROM SKETCHES TO STORYBOARDS Rishabh Singh and Armando Solar-Lezama

Framing the synthesis problem Mundane Science Fiction Visual. Basic Python Fortran? ( ) Automate

Framing the synthesis problem Mundane Science Fiction Visual. Basic Python Fortran? ( ) Automate challenging programming steps Leverage programmer knowledge

Fundamental question • How to combine human insight and machine power • Synergy between

Fundamental question • How to combine human insight and machine power • Synergy between human and machine is key

Lessons from verification • Embrace partial specifications § Because there will never be a

Lessons from verification • Embrace partial specifications § Because there will never be a spec for Power. Point • Speak to programmers in their own language § Test harnesses good, high order logic bad • Don’t be afraid of exhaustive exploration § But do it intelligently • You don’t have to do everything statically § For many problems it is too hard

MULTIMODAL SYNTHESIS

MULTIMODAL SYNTHESIS

Programming with Code { n = v. next; p = v. prev; p. next

Programming with Code { n = v. next; p = v. prev; p. next = n; n. prev = p; }

Programming with Pictures v next prev a prev x prev next a prev b

Programming with Pictures v next prev a prev x prev next a prev b b next prev next n prev x

Bridging the semantic gap n a next prev a x next prev b b

Bridging the semantic gap n a next prev a x next prev b b { s = n. succ; p = n. pred; p. succ = s; s. pred = p; } • Problem: the picture is not a program § you can not “compile” the picture into a program • More like programming by example § except the picture is not an example either

Scenarios vs. Examples n next prev a x next prev b • A scenario

Scenarios vs. Examples n next prev a x next prev b • A scenario is more powerful than an example § each scenario represents an infinite set of examples • It is also less powerful § The picture is ambiguous regarding the fate of …

Multimodal Synthesis • Each scenario is a partial specification § that’s why they can

Multimodal Synthesis • Each scenario is a partial specification § that’s why they can be simple • Completeness vs. complexity tradeoff § irrespective of format complete specs are more complex • Trick: combine many simple specs in different formalisms to fully constrain the behavior

Multimodal Synthesis • Trick: combine many simple specs in different formalisms to fully constrain

Multimodal Synthesis • Trick: combine many simple specs in different formalisms to fully constrain the behavior Concrete Scenarios Abstract Scenarios Inductive Insights Invariants Structural Info Storyboard Synthesizer Correct Code

ANATOMY OF A STORYBOARD

ANATOMY OF A STORYBOARD

Linked List Reversal head mid a next f e next b head mid’ a

Linked List Reversal head mid a next f e next b head mid’ a next e’ f’ next b

Scenarios for LL-reversal head a next mid f e next b head a head

Scenarios for LL-reversal head a next mid f e next b head a head next mid’ e’ f’ next head a next b b head a head a next b a

Text representation of Scenario head a next mid f e next b head a

Text representation of Scenario head a next mid f e next b head a next mid’ e’ f’ next b

Inductive insights with fold/unfold Unfold: x’ = f x’ x’= e mid f e

Inductive insights with fold/unfold Unfold: x’ = f x’ x’= e mid f e x’ = f x’ e = e’ next mid f’ e’

Inductive insights with fold/unfold Unfold: x’ = f x’ x’= e mid f e

Inductive insights with fold/unfold Unfold: x’ = f x’ x’= e mid f e x’ = f x’ e = e’ Fold: next mid f’ x’ = f x’ x’= e x’ = f x’ e = e’ next f’ mid f mid e’ e’ e

Text Representation of Unfold: x’ = f x’ x’= e mid f e x’

Text Representation of Unfold: x’ = f x’ x’= e mid f e x’ = f x’ e = e’ next mid f’ e’

Fold/Unfold • These rules are part of the specification § without them the scenarios

Fold/Unfold • These rules are part of the specification § without them the scenarios are too imprecise • They can also serve to communicate insights val > y. val f=y b=b’ f’ y f stuff val ==y. val f=b=y y stree’ b’ stree b stuff’ y f’ stree’ b’ val < y. val f=y b=b’ stuff’ Underspecified summary node

Fold/Unfold • These rules are part of the specification § without them the scenarios

Fold/Unfold • These rules are part of the specification § without them the scenarios are too imprecise • They can also serve to communicate insights v lleft prev next a lleft prev next x prev next a prev next b lright

Look Sketch void ll. Reverse(Node head) { ? ? /*1*/ while (? ? /*p*/)

Look Sketch void ll. Reverse(Node head) { ? ? /*1*/ while (? ? /*p*/) { ? ? /*2*/ } ? ? /*3*/ }

Look Sketch void ll. Reverse(Node head) { cstmt* /*1*/ while (cond /*p*/) { cstmt*

Look Sketch void ll. Reverse(Node head) { cstmt* /*1*/ while (cond /*p*/) { cstmt* /*2*/ } cstmt* /*3*/ }

Conditional Statements var(. ptr? ) op var(. ptr? ) | null cstmt : if(COND)

Conditional Statements var(. ptr? ) op var(. ptr? ) | null cstmt : if(COND) then STMT var(. ptr? ) = var(. ptr? ) unfold/fold var

CONSTRAINT BASED SYNTHESIS PRIMER

CONSTRAINT BASED SYNTHESIS PRIMER

Synthesis as curve fitting •

Synthesis as curve fitting •

Ex: Sketch • Synthesize Check Insert your favorite checker here

Ex: Sketch • Synthesize Check Insert your favorite checker here

Plan of attack • Define constraints from Storyboards • Use CEGIS to generate incrementally

Plan of attack • Define constraints from Storyboards • Use CEGIS to generate incrementally

CONSTRAINTS FROM STORYBOARDS

CONSTRAINTS FROM STORYBOARDS

Control flow sketch defines a CFG sin void ll. Reverse(Node head) { cstmt* /*1*/

Control flow sketch defines a CFG sin void ll. Reverse(Node head) { cstmt* /*1*/ while (cond /*p*/) { cstmt* /*2*/ } cstmt* /*3*/ } f 1 f 2 s 1 s 3 false fp true f 3 sout • Almost, we have no conditional branches s 2

Equations sin f 1 f 2 s 1 s 3 f 3 sout false

Equations sin f 1 f 2 s 1 s 3 f 3 sout false fp true s 2

Synthesis vs. Verification • Verification known : f, sin unknown : sout , si

Synthesis vs. Verification • Verification known : f, sin unknown : sout , si • Synthesis known : sin, sout unknown : fi

Synthesis challenges • Find values for ci § they don’t form a lattice •

Synthesis challenges • Find values for ci § they don’t form a lattice • Can’t give to solver § We are interested in LFP § si are sets of shapes • Key: § avoid set reasoning

Eliminating sets • Use non-determinism to model sets § works because of associativity of

Eliminating sets • Use non-determinism to model sets § works because of associativity of transfer functions funfold j • Avoid sets that arise from loops points

Loop unrolling f 1 f 1 fp true fp f 3 true . .

Loop unrolling f 1 f 1 fp true fp f 3 true . . . f 3 fp false f 3 p 0 p 1 fp false f 3 p

Not your grandmother’s unrolling • We are evaluating in the abstract domain You expect

Not your grandmother’s unrolling • We are evaluating in the abstract domain You expect to reach fixed point in k steps. § You prefer solutions that reach fixed point faster §

2: Unfold functions funfold j Parameterize the unfold choice j

2: Unfold functions funfold j Parameterize the unfold choice j

Solving the constraint Rewrite the formula as:

Solving the constraint Rewrite the formula as:

Quantifier alternation constraint

Quantifier alternation constraint

Experiments

Experiments

Case studies - I Manipulation #Clauses Memory #Scen Time ll-insertion 1. 99 M 0.

Case studies - I Manipulation #Clauses Memory #Scen Time ll-insertion 1. 99 M 0. 75 G 4 2 m 9 s ll-deletion 1. 88 M 0. 54 G 4 1 m 48 s ll-reverse 1. 30 M 0. 35 G 4 1 m 49 s ll-find-last 1. 02 M 0. 29 G 4 0 m 56 s ll-swap-first-last 1. 08 M 0. 31 G 4 4 m 18 s dll-traversal 1. 72 M 0. 88 G 4 1 m 58 s dll-reversal 2. 04 M 0. 49 G 4 3 m 47 s

Case studies - II Manipulation #Clauses Memory #Scen Time bst-search(contains) 0. 62 M 0.

Case studies - II Manipulation #Clauses Memory #Scen Time bst-search(contains) 0. 62 M 0. 37 G 1 1 m 02 s bst-search 0. 77 M 0. 45 G 1 6 m 07 s bst-find-min 0. 63 M 0. 45 G 1 0 m 58 s bst-find-max 0. 57 M 0. 18 G 1 0 m 23 s bst-left-rotate 1. 41 M 0. 50 G 3 3 m 18 s bst-right-rotate 1. 47 M 0. 43 G 3 3 m 15 s bst-insertion 1. 04 M 0. 46 G 3 1 m 52 s bst-deletion 0. 63 M 0. 62 G 6 3 m 13 s Manipulation #Clauses Memory #Scen Time aig-insertion 0. 17 M 0. 31 G 4 1 m 04 s

BST Deletion • Simple storyboard was under-constrained § Two additional concrete instances were required

BST Deletion • Simple storyboard was under-constrained § Two additional concrete instances were required • Still better than using only concrete examples § constraints grow too big before there are enough examples to constrain the algorithm

Research Questions • Interactivity § Debugging storyboards • Corner cases § Automated fuzzing of

Research Questions • Interactivity § Debugging storyboards • Corner cases § Automated fuzzing of scenarios • Symmetry reduction • Concurrent data structures

Conclusion • Constraints are a powerful basis for synthesis • Multimodal interaction makes specs

Conclusion • Constraints are a powerful basis for synthesis • Multimodal interaction makes specs simpler • Interactivity is key