optilog: a framework for sat-based systems3 from optilog . loaders import load_cnf 4 from optilog ....

20
OptiLog: A Framework for SAT-based Systems The 24th International Conference on Theory and Applications of Satisfiability Testing Carlos Ansótegui Jesús Ojeda Antonio Pacheco Josep Pon Josep M. Salvia Eduard Torres Logic & Optimization Group (LOG), University of Lleida, Spain Barcelona - July 7, 2021

Upload: others

Post on 01-Sep-2021

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: OptiLog: A Framework for SAT-based Systems3 from optilog . loaders import load_cnf 4 from optilog . sat . pbencoder import Encoder 5 6 from optilog . autocfg import ac, Categorical

OptiLog: A Framework for SAT-based SystemsThe 24th International Conference on Theory and Applications

of Satisfiability Testing

Carlos Ansótegui Jesús Ojeda Antonio PachecoJosep Pon Josep M. Salvia Eduard Torres

Logic & Optimization Group (LOG), University of Lleida, Spain

Barcelona - July 7, 2021

Page 2: OptiLog: A Framework for SAT-based Systems3 from optilog . loaders import load_cnf 4 from optilog . sat . pbencoder import Encoder 5 6 from optilog . autocfg import ac, Categorical

1 Motivation

2 Related Work

3 OptiLog Overview

4 Solving a formula using OptiLog

5 Integrating a solver into OptiLog

6 The Pseudo-Boolean (PB) Encoder Module

7 The Automatic Configuration (AC) Module

8 Conclusions & Future Work

9 References

OptiLog: A Framework for SAT-based Systems 2 / 18

Page 3: OptiLog: A Framework for SAT-based Systems3 from optilog . loaders import load_cnf 4 from optilog . sat . pbencoder import Encoder 5 6 from optilog . autocfg import ac, Categorical

Motivation

Rapid prototyping of SAT-based systems using Python asprogramming language.

Uniform interface for SAT solvers and Pseudo-Boolean (PB)encoders.

Simple methodology to integrate any C/C++ SAT solver.

Framework to simplify the Automatic Configuration (AC)process of SAT-based systems.

OptiLog: A Framework for SAT-based Systems Motivation 3 / 18

Page 4: OptiLog: A Framework for SAT-based Systems3 from optilog . loaders import load_cnf 4 from optilog . sat . pbencoder import Encoder 5 6 from optilog . autocfg import ac, Categorical

Related Work

PySAT [IMM18] is a Python toolkit that integrates a numberof widely used state-of-the-art SAT solvers, as well as avariety of cardinality and Pseudo-Boolean encodings.

IPASIR [Bc14] is a simple C interface to incremental SATsolvers. This interface is used in the SAT competition’sincremental track.

The PBLib [PS15] is a C++ project that collects andimplements many different encodings for Pseudo-Booleanconstraints into conjunctive normal form (CNF).

OptiLog: A Framework for SAT-based Systems Related Work 4 / 18

Page 5: OptiLog: A Framework for SAT-based Systems3 from optilog . loaders import load_cnf 4 from optilog . sat . pbencoder import Encoder 5 6 from optilog . autocfg import ac, Categorical

OptiLog Overview

OptiLog1 is a unified framework for developing SAT-based systems.It provides a new way of integrating SAT solvers into Pythonwithout implementing Python code or Python/C API bindings, aunified interface for encoding PB constraints and a framework thatsimplifies the automatic configuration of any Python function.

Figure: OptiLog Architecture

1Docs: http://ulog.udl.cat/static/doc/optilog/html/index.htmlOptiLog: A Framework for SAT-based Systems OptiLog Overview 5 / 18

Page 6: OptiLog: A Framework for SAT-based Systems3 from optilog . loaders import load_cnf 4 from optilog . sat . pbencoder import Encoder 5 6 from optilog . autocfg import ac, Categorical

Solving a formula using OptiLog

>>> from o p t i l o g . l oade r s import load_cnf>>> from o p t i l o g . sat import Glucose41>>> s o l v e r = Glucose41 ()>>> load_cnf ( ’ path/to/ formula . cnf ’ , s o l v e r )>>> s o l v e r . s o l v e ()True>>> s o l v e r . model ( )[1 , −2, 3 , 4 , . . . ]

OptiLog: A Framework for SAT-based Systems Solving a formula using OptiLog 6 / 18

Page 7: OptiLog: A Framework for SAT-based Systems3 from optilog . loaders import load_cnf 4 from optilog . sat . pbencoder import Encoder 5 6 from optilog . autocfg import ac, Categorical

Integrating a solver into OptiLog

OptiLog allows the integration of SAT solvers written in C/C++to Python through the implementation of the iSAT interface.

c l a s s Glucose41Wrapper : iSAT{

i n t newVar ( ) ;void addClause ( vector<int> &l i t e r a l s ) ;E_STATE s o l v e ( vector<int> &assumptions ) ;void getModel ( vector<int> &model ) ;( . . . )

}

OptiLog: A Framework for SAT-based Systems Integrating a solver into OptiLog 7 / 18

Page 8: OptiLog: A Framework for SAT-based Systems3 from optilog . loaders import load_cnf 4 from optilog . sat . pbencoder import Encoder 5 6 from optilog . autocfg import ac, Categorical

Integrating a solver into OptiLog

The iSAT interface provides these new additional methods:set_decision_varset_static_heuristicsolve_hard_limitedlearnt_clausesget and set methods for solver configuration

OptiLog: A Framework for SAT-based Systems Integrating a solver into OptiLog 8 / 18

Page 9: OptiLog: A Framework for SAT-based Systems3 from optilog . loaders import load_cnf 4 from optilog . sat . pbencoder import Encoder 5 6 from optilog . autocfg import ac, Categorical

The Pseudo-Boolean (PB) Encoder Module

Integration of PBLib encodings and the Totalizer encoding fromPySAT using the same interface.

Pseudo-Boolean encodings:Adder networksBinary mergeBDDSequential weigh countersSorting networks

Cardinality encodings:BitwiseCardinality networkLadder / RegularPairwiseSequential countersTotalizer

OptiLog: A Framework for SAT-based Systems The Pseudo-Boolean (PB) Encoder Module 9 / 18

Page 10: OptiLog: A Framework for SAT-based Systems3 from optilog . loaders import load_cnf 4 from optilog . sat . pbencoder import Encoder 5 6 from optilog . autocfg import ac, Categorical

The Pseudo-Boolean (PB) Encoder Module

Non-incremental encoders

Example: 2x + y + z ≥ 2

>>> from o p t i l o g . sat . pbencoder import Encoder>>> Encoder . at_least_k ( [ 1 , 2 , 3 ] , 2 , [ 2 , 1 , 1 ] , ”bdd” )(9 , [ [ 4 ] , [−4, 5 ] , [ 3 , 5 ] , [−4, 3 , 6 ] , . . . ] )

Incremental encoders

Example: From x + y + z ≤ 3 to x + y + z ≤ 2

>>> from o p t i l o g . sat . pbencoder import IncrementalEncoder>>> enc , max_var , C = IncrementalEncoder . i n i t ( [ 1 , 2 , 3 ] , 3)(<IncrementalEncoder object >, 6 , [[ −3 , 4 ] , . . . ] )>>> max_var , C_ext = enc . extend (2)(6 , [ [ −6 ] ] )

OptiLog: A Framework for SAT-based Systems The Pseudo-Boolean (PB) Encoder Module 10 / 18

Page 11: OptiLog: A Framework for SAT-based Systems3 from optilog . loaders import load_cnf 4 from optilog . sat . pbencoder import Encoder 5 6 from optilog . autocfg import ac, Categorical

The Automatic Configuration (AC) Module

The Automatic Configuration (AC) module provides an API toautomatically generate the configuration files that automaticconfigurators need as input to configure any Python function.

OptiLog currently provides support for SMAC [HHL11] andGGA [AST09, AMS+15].

OptiLog: A Framework for SAT-based Systems The Automatic Configuration (AC) Module 11 / 18

Page 12: OptiLog: A Framework for SAT-based Systems3 from optilog . loaders import load_cnf 4 from optilog . sat . pbencoder import Encoder 5 6 from optilog . autocfg import ac, Categorical

Example: Automatically configuring a SAT-based algorithm (I)

1 # example . py23 def a lgor i thm ( instance , seed ) :4 s = Glucose41 ()5 s . set ( ” seed ” , seed )6 f = load_cnf ( instance , s )7 max_var = f . max_var ()8 _, C = Encoder . at_most_k(9 range (1 , max_var + 1) ,

10 bound=max_var // 2 ,11 max_var=max_var ,12 )13 s . add_clauses (C)14 r e s = s . s o l v e ()15 p r i n t ( ” s ” , r e s )16 return r e s

1 # example_ac . py23 from o p t i l o g . l oade r s import load_cnf4 from o p t i l o g . sat . pbencoder import Encoder56 from o p t i l o g . autocfg import ac , Catego r i ca l7 from o p t i l o g . autocfg import CfgCal l8 from o p t i l o g . autocfg . sat import get_glucose419

10 ENCODERS = [ ” best ” , ” cardnetwrk ” , ” t o t a l i z e r ” ]1112 @ac13 def a lgor i thm (14 instance , seed ,15 i n i t _ s o l v e r _ f n : CfgCal l ( get_glucose41 ) ,16 encoding : Catego r i ca l (∗ENCODERS) = ” best ” ,17 ) :18 s = i n i t _ s o l v e r _ f n ( seed=seed )19 f = load_cnf ( instance , s )20 max_var = f . max_var ()21 _, C = Encoder . at_most_k(22 range (1 , max_var + 1) ,23 bound=max_var // 2 ,24 max_var=max_var ,25 encoding=encoding ,26 )27 s . add_clauses (C)28 r e s = s . s o l v e ()29 p r i n t ( ” s ” , r e s )30 return r e s

OptiLog: A Framework for SAT-based Systems The Automatic Configuration (AC) Module 12 / 18

Page 13: OptiLog: A Framework for SAT-based Systems3 from optilog . loaders import load_cnf 4 from optilog . sat . pbencoder import Encoder 5 6 from optilog . autocfg import ac, Categorical

Example: Automatically configuring a SAT-based algorithm (I)

1 # example . py23 def a lgor i thm ( instance , seed ) :4 s = Glucose41 ()5 s . set ( ” seed ” , seed )6 f = load_cnf ( instance , s )7 max_var = f . max_var ()8 _, C = Encoder . at_most_k(9 range (1 , max_var + 1) ,

10 bound=max_var // 2 ,11 max_var=max_var ,12 )13 s . add_clauses (C)14 r e s = s . s o l v e ()15 p r i n t ( ” s ” , r e s )16 return r e s

1 # example_ac . py23 from o p t i l o g . l oade r s import load_cnf4 from o p t i l o g . sat . pbencoder import Encoder56 from o p t i l o g . autocfg import ac , Catego r i ca l7 from o p t i l o g . autocfg import CfgCal l8 from o p t i l o g . autocfg . sat import get_glucose419

10 ENCODERS = [ ” best ” , ” cardnetwrk ” , ” t o t a l i z e r ” ]1112 @ac13 def a lgor i thm (14 instance , seed ,15 i n i t _ s o l v e r _ f n : CfgCal l ( get_glucose41 ) ,16 encoding : Catego r i ca l (∗ENCODERS) = ” best ” ,17 ) :18 s = i n i t _ s o l v e r _ f n ( seed=seed )19 f = load_cnf ( instance , s )20 max_var = f . max_var ()21 _, C = Encoder . at_most_k(22 range (1 , max_var + 1) ,23 bound=max_var // 2 ,24 max_var=max_var ,25 encoding=encoding ,26 )27 s . add_clauses (C)28 r e s = s . s o l v e ()29 p r i n t ( ” s ” , r e s )30 return r e s

OptiLog: A Framework for SAT-based Systems The Automatic Configuration (AC) Module 12 / 18

Page 14: OptiLog: A Framework for SAT-based Systems3 from optilog . loaders import load_cnf 4 from optilog . sat . pbencoder import Encoder 5 6 from optilog . autocfg import ac, Categorical

Example: Automatically configuring a SAT-based algorithm (II)

GGA scenario generation1 # scenar io_gga . py23 from p a t h l i b import Path4 from o p t i l o g . autocfg . c o n f i g u r a t o r s import GGAConfigurator5 from example_ac import a lgor i thm67 i f __name__ == ”__main__” :8 c o n f i g u r a t o r = GGAConfigurator (9 algor ithm , runso lver_path=” ./ r u n s o l v e r ” ,

10 g l o b a l _ c f g c a l l s =[a lgor i thm ] ,11 input_data=[” i n s t 1 . cnf ” , . . . , ” instN . cnf ” ] ,12 data_kwarg=” in s tance ” , seed_kwarg=” seed ” ,13 eva l_t ime_l imit =30, memory_limit=4 ∗ 1024 ,14 tuner_r t_ l im i t =180, run_obj=” runtime ” ,15 qua l i t y_regex=r ”^s ( ? : True | Fa l se )$” ,16 seed=1, cost_min=0, cost_max=300,17 )18 c o n f i g u r a t o r . generate_scenar io ( ” ./ scenar io−gga” )

GGA execution./pydgga gga -s scenario-gga/ --slots 1

What about configuring with SMAC?

OptiLog: A Framework for SAT-based Systems The Automatic Configuration (AC) Module 13 / 18

Page 15: OptiLog: A Framework for SAT-based Systems3 from optilog . loaders import load_cnf 4 from optilog . sat . pbencoder import Encoder 5 6 from optilog . autocfg import ac, Categorical

Example: Automatically configuring a SAT-based algorithm (II)

GGA scenario generation1 # scenar io_gga . py23 from p a t h l i b import Path4 from o p t i l o g . autocfg . c o n f i g u r a t o r s import GGAConfigurator5 from example_ac import a lgor i thm67 i f __name__ == ”__main__” :8 c o n f i g u r a t o r = GGAConfigurator (9 algor ithm , runso lver_path=” ./ r u n s o l v e r ” ,

10 g l o b a l _ c f g c a l l s =[a lgor i thm ] ,11 input_data=[” i n s t 1 . cnf ” , . . . , ” instN . cnf ” ] ,12 data_kwarg=” in s tance ” , seed_kwarg=” seed ” ,13 eva l_t ime_l imit =30, memory_limit=4 ∗ 1024 ,14 tuner_r t_ l im i t =180, run_obj=” runtime ” ,15 qua l i t y_regex=r ”^s ( ? : True | Fa l se )$” ,16 seed=1, cost_min=0, cost_max=300,17 )18 c o n f i g u r a t o r . generate_scenar io ( ” ./ scenar io−gga” )

GGA execution./pydgga gga -s scenario-gga/ --slots 1

What about configuring with SMAC?

OptiLog: A Framework for SAT-based Systems The Automatic Configuration (AC) Module 13 / 18

Page 16: OptiLog: A Framework for SAT-based Systems3 from optilog . loaders import load_cnf 4 from optilog . sat . pbencoder import Encoder 5 6 from optilog . autocfg import ac, Categorical

Example: Automatically configuring a SAT-based algorithm (III)

SMAC scenario generation1 # scenario_smac . py23 from o p t i l o g . autocfg import SMACConfigurator4 from example_ac import a lgor i thm56 i f __name__ == ”__main__” :7 c o n f i g u r a t o r = SMACConfigurator (8 algor ithm , runso lver_path=” ./ r u n s o l v e r ” ,9 g l o b a l _ c f g c a l l s =[a lgor i thm ] ,

10 input_data=[” i n s t 1 . cnf ” , . . . , ” instN . cnf ” ] ,11 data_kwarg=” in s tance ” , seed_kwarg=” seed ” ,12 c u t o f f =30, memory_limit=4 ∗ 1024 ,13 w a l l c l o c k _ l i m i t =180, run_obj=” runtime ” ,14 qua l i t y_regex=r ”^s ( ? : True | Fa l se )$” ,15 )16 c o n f i g u r a t o r . generate_scenar io ( ” ./ s cena r i o ” )

SMAC executionsmac --scenario ./scenario/scenario.txt

OptiLog: A Framework for SAT-based Systems The Automatic Configuration (AC) Module 14 / 18

Page 17: OptiLog: A Framework for SAT-based Systems3 from optilog . loaders import load_cnf 4 from optilog . sat . pbencoder import Encoder 5 6 from optilog . autocfg import ac, Categorical

Conclusions & Future Work

ConclusionsOptiLog eases the access to solvers and encoders to our andother communities.The iSAT interface could become the basis for an standardSAT API.The AC module can potentially be applied to tune any Pythonfunction.

Future WorkWe will add other solvers, like MaxSAT or PB solvers.Support for more complex compilation pipelines.Support for callback functions on critical points as in Gurobi[Gur21] (restarts, pick literal decision, conflict analysis, etc.).Integrate crafted and random instance generators and allowdynamic instance downloading from repositories.

OptiLog: A Framework for SAT-based Systems Conclusions & Future Work 15 / 18

Page 18: OptiLog: A Framework for SAT-based Systems3 from optilog . loaders import load_cnf 4 from optilog . sat . pbencoder import Encoder 5 6 from optilog . autocfg import ac, Categorical

[AMS+15] Carlos Ansótegui, Yuri Malitsky, Horst Samulowitz,Meinolf Sellmann, and Kevin Tierney.Model-based genetic algorithms for algorithmconfiguration.In IJCAI, pages 733–739, 2015.

[AST09] C. Ansotegui, M. Sellmann, and K. Tierney.A gender-based genetic algorithm for the automaticconfiguration of algorithms.In Proceedings of the 15th International Conference onPrinciples and Practice of Constraint Programming,pages 142–157, 2009.

[Bc14] Tomas Balyo and contributors.The standard interface for incremental satisfiabilitysolving.https://github.com/biotomas/ipasir, 2014.

OptiLog: A Framework for SAT-based Systems References 16 / 18

Page 19: OptiLog: A Framework for SAT-based Systems3 from optilog . loaders import load_cnf 4 from optilog . sat . pbencoder import Encoder 5 6 from optilog . autocfg import ac, Categorical

[Gur21] Gurobi Optimization.Gurobi.https://www.gurobi.com/, 2021.

[HHL11] F. Hutter, H.H. Hoos, and K. Leyton-Brown.Sequential model-based optimization for generalalgorithm configuration.In Learning and Intelligent Optimization - 5thInternational Conference, LION 5, Rome, Italy, January17-21, 2011. Selected Papers, pages 507–523, 2011.

[IMM18] Alexey Ignatiev, Antonio Morgado, and JoaoMarques-Silva.PySAT: A Python toolkit for prototyping with SAToracles.In SAT, pages 428–437, 2018.

OptiLog: A Framework for SAT-based Systems References 17 / 18

Page 20: OptiLog: A Framework for SAT-based Systems3 from optilog . loaders import load_cnf 4 from optilog . sat . pbencoder import Encoder 5 6 from optilog . autocfg import ac, Categorical

[PS15] Tobias Philipp and Peter Steinke.PBLib – a library for encoding pseudo-booleanconstraints into CNF.In Marijn Heule and Sean Weaver, editors, Theory andApplications of Satisfiability Testing – SAT 2015, pages9–16, Cham, 2015. Springer International Publishing.

OptiLog: A Framework for SAT-based Systems References 18 / 18