Satex Black Box

The Satex BlackBox module provide utilities to run solvers from the SAT solver competitions with SAT Heritage and then parse the result.

class optilog.blackbox.SatexBlackBox(solver, constraints=None)
Parameters
  • solver (str) – Name of the solver to insantiate. See the method available_solvers

  • constraints (Optional[ExecutionConstraints]) – Defines the execution constraints for the Configuration Process

static available_solvers(pattern=None)

SatexBlackBox accesses the SAT solvers used by satex This method returns a list of available solvers that match the given pattern.

Parameters

pattern (Optional[str]) – Pattern for available solvers

Return type

List[str]

Returns

List of strings with the names of available solvers

>>> from optilog.blackbox import SatexBlackBox
>>> 
>>> SatexBlackBox.available_solvers('kissat*')
['kissat-sc2020-default:2020', 'kissat-sc2020-sat:2020', 'kissat-sc2020-unsat:2020',
'kissat-mab:2021', 'kissat-sat_crvr_gb:2021', 'kissat-sc2021:2021', 'kissat_bonus:2021',
'kissat_cf:2021', 'kissat_gb:2021']
property is_sat: bool

Whether the solver has determined the instance is satisfiable or not. Accessible after the execution has finished.

Return type

bool

property sat: str

Result of the status line of the solver. Accessible after the execution has finished.

Return type

str

property model: List[int]

Parsed model as list of integers of the instance Accessible after the execution has finished.

Return type

List[int]

get(key)

Returns the value assigned to a given parameter name.

Parameters

key (str) – Parameter name.

Return type

Union[int, float, bool, str]

Returns

Parameter value.

classmethod get_config()
Return type

Dict[str, Dict[str, str]]

Returns

A dictionary with all the configurable parameters of the solver. Each parameter has defined its type (int, float, bool or categorical), its domain, and its default value.

property parsed

Dictionary with all the parsed elements from the execution. Accessible after the execution has finished.

set(key, value, check_domain=True)

Sets the value for a given parameter.

Parameters
  • key (str) – Parameter name.

  • value – Parameter value.

  • value – int or float or bool or str

Raises

KeyError: if param is not found inside the solver.

run(instance, constraints=None, stdout=BlackBoxRedirection.Default, stderr=BlackBoxRedirection.Stdout)

Executes the SAT solver and stores the output out of the call

Note that this call will launch a docker container and may pull a docker image. Startup may not be instantaneous.

Parameters
  • instance (Union[str, CNF]) – Path to the CNF instance to execute. It may also be a CNF object, in which case it will be written to a memory file without going through disk. Note that this might would result in faster loading times but higher memory consumption.

  • constraints (Optional[ExecutionConstraints]) – Defines the execution constraints for the Configuration Process. If it is None, the default constraints of the constructor will be used. Otherwise, these new constraints will be used.

  • stdout (Union[str, BlackBoxRedirection]) – Where to redirect stdout. If it is a string, the output will be redirected to the specified path.

  • stderr (Union[str, BlackBoxRedirection]) – Where to redirect stderr. If it is a string, the output will be redirected to the specified path.

First of all we will check out the available kissat solvers:

>>> from optilog.blackbox import SatexBlackBox
>>>
>>> print(SatexBlackBox.available_solvers('kissat*'))
['kissat-sc2020-default:2020', 'kissat-sc2020-sat:2020', 'kissat-sc2020-unsat:2020',
 'kissat-mab:2021', 'kissat-sat_crvr_gb:2021', 'kissat-sc2021:2021', 'kissat_bonus:2021',
 'kissat_cf:2021', 'kissat_gb:2021']

Then, we can create a new SAT solver and solve a CNF instance:

>>> from optilog.blackbox import SatexBlackBox, ExecutionConstraints
>>>
>>> bb = SatexBlackBox(
>>>     'kissat-mab:2021',
>>>     constraints=ExecutionConstraints(
>>>         wall_time=13,
>>>         memory='1G'
>>>     )
>>>
>>> bb.run('/path/to/instance')
>>>
>>> print(bb.sat)
SATISFIABLE
>>> print(bb.is_sat)
True
>>> print(bb.model)
[1, 2, 3, 4, ..., 99, -100]

We can do the exact same thing with a CNF formula:

>>> from optilog.blackbox import SatexBlackBox
>>> from optilog.formulas import CNF
>>> c = CNF()
>>> c.add_clause([1, 2, 3])
>>> c.add_clause([-1])
>>> c.add_clause([-3])
>>>
>>>
>>> bb = SatexBlackBox('kissat-mab:2021')
>>>
>>> bb.run(c)
>>>
>>> print(bb.sat)
SATISFIABLE
>>> print(bb.is_sat)
True
>>> print(bb.model)
[-1, 2, -3]