Probability backdoors search example for PvS 7x4

An example of probabilistic backdoors searching to solve the equivalence checking problem of two Boolean schemes that implement different algorithms, using the example of PvS 7x4 encoding (Pancake vs Selection sort).

 1from os import cpu_count
 2from typing import List
 3
 4# algorithm module imports
 5from algorithm.impl import Elitism
 6from algorithm.module.mutation import Doer
 7from algorithm.module.crossover import TwoPoint
 8from algorithm.module.selection import Roulette
 9
10# function module imports
11from function.impl import RhoFunction
12from function.module.measure import Propagations
13
14# satprob lib imports
15from lib_satprob.encoding import CNF
16from lib_satprob.variables import Range
17from lib_satprob.solver import PySatSolver
18from lib_satprob.problem import SatProblem
19
20# space module imports
21from space import rho_subset
22from space.impl import BackdoorSet
23
24# core module imports
25from core.impl import Optimize
26from core.model.point import Point
27from core.module.sampling import Const
28from core.module.limitation import WallTime
29from core.module.comparator import MinValueMaxSize
30
31# other imports
32from util.work_path import WorkPath
33from output.impl import OptimizeLogger
34from executor.impl import ProcessExecutor
35
36
37def run_pvs_4_7_search() -> List[Point]:
38    algorithm = Elitism(
39        elites_count=2,
40        population_size=6,
41        mutation=Doer(),
42        crossover=TwoPoint(),
43        selection=Roulette(),
44        min_update_size=6
45    )
46    limitation = WallTime(
47        from_string='04:00:00'
48    )
49
50    function = RhoFunction(
51        penalty_power=2 ** 20,
52        measure=Propagations(),
53    )
54    sampling = Const(
55        size=1024, split_into=256
56    )
57
58    root_path = WorkPath('examples')
59    data_path = root_path.to_path('data')
60    cnf_file = data_path.to_file('pvs_4_7.cnf')
61
62    problem = SatProblem(
63        encoding=CNF(from_file=cnf_file),
64        solver=PySatSolver(sat_name='g3'),
65    )  # read from file './examples/data/sort/pvs_4_7.cnf
66
67    space = BackdoorSet(
68        by_vector=[],
69        variables=rho_subset(
70            problem,
71            Range(length=1213),
72            of_size=100
73        )
74    )  # reduce to subset of 100 “off” var
75
76    workers = min(cpu_count(), 16)
77    executor = ProcessExecutor(
78        max_workers=workers
79    )
80    print(f'Running on {workers} threads')
81
82    # log process to dir './examples/logs/<date_date>
83    logs_path = root_path.to_path('logs', 'pvs_4_7')
84    return Optimize(
85        space=space,
86        problem=problem,
87        executor=executor,
88        sampling=sampling,
89        function=function,
90        algorithm=algorithm,
91        limitation=limitation,
92        comparator=MinValueMaxSize(),
93        logger=OptimizeLogger(logs_path),
94    ).launch()
95
96
97__all__ = [
98    'run_pvs_4_7_search'
99]
Other examples: