Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn...

31
Learning to Solve SMT Formulas Mislav Balunović, Pavol Bielik, Martin Vechev Department of Computer Science

Transcript of Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn...

Page 1: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Learning to Solve SMT Formulas

Mislav Balunovic, Pavol Bielik, Martin Vechev

Department of Computer Science

Page 2: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

SAT

SMT

SMT Formula

φ = (b ∨ -x2 ≥ 2.3y ∨ sin(x)3 = cos(log(y) • x)) ∧

(¬b ∨ y < -34.4 ∨ exp(y) > y/x) where b ∊ {true, false}, x, y ∊ ℝ

Theories Booleans, Reals, Integers, Arrays, BitVectors, Strings, ...

Does there exist a valid assignment to b, x, y?

Page 3: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

b = true

x = 14.32

y = -37.2

SMT Solvers

φ = (b ∨ -x2 ≥ 2.3y ∨ sin(x)3 = cos(log(y) • x)) ∧

(¬b ∨ y < -34.4 ∨ exp(y) > y/x)

φ SMT Solver

Find an assignment to all free variables in φ such that φ evaluates to true

SAT + model

UNSAT + unsat core

First-order logic formula

where b ∊ {true, false}, x, y ∊ ℝ

Does there exist a valid assignment to b, x, y?

Page 4: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

SMT Solvers

φ SMT Solver

Find an assignment to all free variables in φ such that φ evaluates to true

Software & Hardware Verification

Neural Networks Verification

Type Inference

Symbolic Execution

Planning

Static Program Analysis

Scheduling

Graph Problems Program Synthesis

Applications

SAT + model

UNSAT + unsat core

First-order logic formula

Page 5: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Solving SMT Formulas is Hard

φ SMT Solver SAT + model

UNSAT + unsat core

Theory ComplexityQuantifier Free Booleans (SAT) NP-Complete O(nk)

Linear Real Arithmetic 2-EXPTIME O(22 )

Linear Integer Arithmetic 3-EXPTIME O(22 )

Non-linear Integer Arithmetic undecidable

nk

nk2

First-order logic formula

Page 6: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Solving SMT Formulas is Hard

φ Set of Handcrafted Strategies

SAT + model

UNSAT + unsat core

Theory ComplexityQuantifier Free Booleans (SAT) NP-Complete O(nk)

Linear Real Arithmetic 2-EXPTIME O(22 )

Linear Integer Arithmetic 3-EXPTIME O(22 )

Non-linear Integer Arithmetic undecidable

nk

nk2

First-order logic formula

Page 7: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Solving SMT Formulas is Hard

φ Set of Handcrafted Strategies

State-of-the-art SMT Solvers✘ Easily perform badly on new problems✘ Require expert knowledge to fix

SAT + model

UNSAT + unsat core

First-order logic formula

Page 8: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Learning to Solve SMT Formulas

φ Learned Strategies

Fast

✔ Learn fast strategies✔ No prior knowledge

Our Work:

SAT + model

UNSAT + unsat core

First-order logic formula

State-of-the-art SMT Solvers✘ Easily perform badly on new problems✘ Require expert knowledge to fix

Page 9: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

ActionSpace

SMT Formula Solving

apply transformation (tactic)

Constant Folding

x + 0 x

Bit Blasting

x = 5 x3 = 0 ∧ x

2 = 1 ∧

x1 = 0 ∧ x

0 = 10101

2

φ φ φ φ1

Decision Procedure

Reals, Integers, BitVectors, ...

2 3

true (SAT)

false (UNSAT)

t1

t2

t3

Normalize Bounds

k ≤ x 0 ≤ x’x’ = x - k

Page 10: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Handcrafted strategies determine which path to take

SMT Formula Solving

φ φ φ φ

532 s

φ

φ

φ

φ

TIMEOUT

12 s

TIMEOUT

TIMEOUT

1

2

2

2

3

3

3

1

2

3

2

3

1apply transformation

(tactic)

Page 11: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Learning to Solve Formula

SMTStrategy

t1; …; t

nModelφ

SAT + model

UNSAT + unsat core

Predict Strategyφ

Hard to Learn

Page 12: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Handcrafted strategies determine which path to take

Learning to Solve Formula

φ φ φ φ

532 s

φ

φ

φ

φ

TIMEOUT

12 s

TIMEOUT

TIMEOUT

1

2

2

2

3

3

3

1

2

3

2

3

1apply transformation

(tactic)

Page 13: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Learning to Solve Formula

s s s s

s

s

s

s

a1

a1

a2

a3

a2

a1

a3

532 s

TIMEOUT

12 s

TIMEOUT

TIMEOUT

1

2

2

2

3

3

3

1

2

3

2

3

1

Learn path with lowest runtime

Page 14: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

SMT Formula Solving

ModelφSMT

Strategyt1; …; t

n

SAT + model

UNSAT + unsat core

φ Policy SMTt1 φ1 Policy SMTt

2

SAT

UNSAT...

Predict Strategyφ

Predict Single Transformations

Hard to Learn

Internal SMT State Lost Model Not AvailableRuntime Overhead

Easier to Learn

Bit Blasting

x = 5 x3 = 0 ∧ x

2 = 1 ∧

x1 = 0 ∧ x

0 = 10101

2

Page 15: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Learning to Solve SMT Formulas

Learning Policy

Dataset ofFormulas

Learn a policy to select next tactic

Policy

SMT solved?

Tactic

φ

no

yes

SAT

UNSAT

Page 16: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Learning to Solve SMT Formulas

Learning Policy ExtractionPolicy

Dataset ofFormulas

Learn a policy to select next tactic

Use the learned policy to synthesize a Strategy program

Policy

SMT solved?

Tactic

φ

no

yes

SAT

UNSAT

SMT +

✔ No runtime overhead✔ Integration with existing SMT Solvers

φ SAT + model

UNSAT + unsat core

Program with Branches

Page 17: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Neural Network Policy

Prior Actions[simplify, bit_blast, …]

Formula Measures[num_consts, is_pb, …]

Formula RepresentationBOW | Skip-Gram | AST

Embedding

Embedding

[1733, 0, …]

eval on φ

eval on φ

Page 18: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Neural Network Policy

Embedding

Embedding

[1733, 0, …]

ReLUReLU

ReLU

SoftMax

Sigmoid

Tactics0.70: pb2bv

0.15: smt

...

Parameters0.20: flat

0.75: som

95: factor

...

Probability distribution over tactics

Regression to predict each parameter

eval on φ

eval on φ

Prior Actions[simplify, bit_blast, …]

Formula Measures[num_consts, is_pb, …]

Formula RepresentationBOW | Skip-Gram | AST

Page 19: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Training

Dataset of Formulas

= {φ, ψ, …, χ}

Page 20: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Training

Sample Policy

Policy

SMT solved?

Tactic

φ

no

yes

SAT

UNSAT

Dataset of Formulas

= {φ, ψ, …, χ}

Page 21: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Training

Training Dataset

Sample Policy

Policy

SMT solved?

Tactic

φ

no

yes

SAT

UNSAT

Dataset of Formulas

= {φ, ψ, …, χ}

Page 22: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Training

Training DatasetRetrain Policy

tactic weighted average of cross-entropy loss

+mean-square-error

parameters

=

Sample Policy

Policy

SMT solved?

Tactic

φ

no

yes

SAT

UNSAT

Dataset of Formulas

= {φ, ψ, …, χ}

Page 23: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Training

Training DatasetRetrain Policy

tactic weighted average of cross-entropy loss

+mean-square-error

parameters

=

Sample Policy

Policy

SMT solved?

Tactic

φ

no

yes

SAT

UNSAT

= {φ, ψ, …, χ}

Evaluate

Page 24: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Learning

Sequential Strategies

𝜋(a | s)

φa1 a

2 a3

a1

a4

a5

a1

a4

a5

ψ

χ

Page 25: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Learning Policy Extraction

φ

ψ

χ

𝜋(a | s)

a1

a4

a5

a1 a

2 a3

a1

a4

a5

Strategy with Branches

if expr then a2 else a

4

a1

a4

a5

a3

a2

{φ, ψ, …, χ}

Sequential Strategies

Page 26: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Evaluationstate-of-the-art SMT Solver

Z3 Industrial Benchmarks

AProVE Sage2Academic Benchmarks

leipzig core hycomp

Learning

Policy Extraction

+Learning

Policy Extraction

+Learning

Policy Extraction

+Learning

Policy Extraction

+Learning

Policy Extraction

+

Page 27: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Speed-up over Z3

Z3 handcrafted strategy

Speed-uplog scale

0.1

1

10

100

1000

0 20 40 60 80 100

faster

slower

Formulas

Page 28: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Speed-up over Z3

Z3 handcrafted strategy

Speed-uplog scale

0.1

1

10

100

1000

0 20 40 60 80 100

faster

slower

Synthesized Strategy10x Sage2

Formulas

Page 29: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Speed-up over Z3

Z3 handcrafted strategy

Speed-uplog scale

0.1

1

10

100

1000

0 20 40 60 80 100

faster

slower

Synthesized Strategy10x

100x

1000x

Sage2

AProVE

Formulas

Page 30: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Speed-up over Z3

Z3 handcrafted strategy

Formulas

Speed-uplog scale

0.1

1

10

100

1000

0 20 40 60 80 100

faster

slower

Synthesized Strategy10x

100x

1000x

Sage2

AProVE

leipzig

core

hycomp

Page 31: Learning to Solve SMT Formulas...Learning to Solve SMT Formulas φ Learned Strategies Fast Learn fast strategies No prior knowledge Our Work: SAT + model UNSAT + unsat core First-order

Learning to Solve SMT Formulashttp://fastsmt.ethz.ch/

Learning Policy ExtractionPolicy

Dataset ofFormulas

Learn a policy to select next tactic

Use the learned policy to synthesize a Strategy program

SMT +

✔ No runtime overhead✔ Integration with existing SMT Solvers

Policy

SMT solved?

Tactic

φ

no

yes

SAT

UNSAT

φ SAT + model

UNSAT + unsat core

Program with Branches