Python Z3和current.futures

时间:2018-09-19 13:20:52

标签: z3py concurrent.futures

我想并行解决一组包含的问题,然后添加其他信息来解决新问题。

以下是用于解决该问题的程序结构示例:

from z3 import *
import concurrent.futures


# solver test function
def add(a, b, solver, index):
    solver.append(a > b)
    assert solver.check()
    model = solver.model()
    return {
        'solver': solver,
        'av': model[a],
        'a': a,
        'b': b,
        'bv': model[b],
        'index': index
    }


with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
    # start solving the problems
    to_compute = []
    for i in range(3):
        sol = z3.Solver()
        to_compute.append(executor.submit(
            add,
            Int('a{}'.format(i)),
            Int('b{}'.format(i)),
            sol,
            i
        ))
    # wait for the solution to the computations
    next_to_solve = []
    for result_futures in concurrent.futures.as_completed(to_compute):
        results = result_futures.result()
        print(results)
        sol = results['solver']
        sol.append(results['a'] > results['av'])
        next_to_solve.append(
            executor.submit(
                add,
                results['a'],
                results['b'],
                sol,
                results['index']
            )
        )

每次运行程序时结果都不同,结果包括:

  • Z3Exception'无效的dec_ref命令'
  • 崩溃的蟒蛇
  • 没有错误

为了使程序更可靠,我需要做什么?

1 个答案:

答案 0 :(得分:1)

您是否看到以下示例:http://github.com/Z3Prover/z3/blob/master/examples/python/parallel.py

我不是z3py并发功能的专家,但是似乎您需要非常小心地在与运行求解器相同的上下文中创建变量。非常文件。