Multithreading Pyomo:sending options=";“线程”;到cbc解算器会导致错误

Multithreading Pyomo:sending options=";“线程”;到cbc解算器会导致错误,multithreading,pyomo,coin-or-cbc,Multithreading,Pyomo,Coin Or Cbc,可以在命令行中激活多线程: $cbc -threads=6 Welcome to the CBC MILP Solver Version: 2.9.9 Build Date: Aug 21 2017 但是当我尝试在pyomo代码中激活这个选项时 opt = SolverFactory('cbc') result = opt.solve(instance, options="threads=4") 我得到一个错误: File "/usr/local/lib/pyt

可以在命令行中激活多线程:

$cbc -threads=6
Welcome to the CBC MILP Solver
Version: 2.9.9
Build Date: Aug 21 2017
但是当我尝试在pyomo代码中激活这个选项时

opt = SolverFactory('cbc')
result = opt.solve(instance, options="threads=4")
我得到一个错误:

File "/usr/local/lib/python3.9/dist-packages/pyomo/opt/base/solvers.py", line 561, in solve
    self.options.update(kwds.pop('options', {}))
  File "/usr/local/lib/python3.9/dist-packages/pyutilib/misc/misc.py", line 360, in update
    if type(d[k]) is dict:
TypeError: string indices must be integers

有什么想法吗?

关键字参数需要一本字典。如果要使用与命令行相同的语法,则需要使用
options\u string

opt.solve(实例,options\u string=“threads=4”)
solve(实例,选项={“线程”:4})

谢谢!根据misc.py,我猜这个论点需要一本字典。没有更多的错误,但只使用了一个线程,而不是4个。我使用抽象模型。我应该只使用ConcreteModel来激活多线程吗?@ElizavetaGolubeva确保CBC可执行文件是多线程兼容的。如果您是从源代码处编译的,您应该将其指定为一个选项。而且,据我所知,多线程只在解算的分支和绑定阶段有用。PS:我还为Pyomo编写了一个解算器包装器,如果您想查看它,可以轻松地选择解算器和获取变量的最终结果:
File "/usr/local/lib/python3.9/dist-packages/pyomo/opt/base/solvers.py", line 561, in solve
    self.options.update(kwds.pop('options', {}))
  File "/usr/local/lib/python3.9/dist-packages/pyutilib/misc/misc.py", line 360, in update
    if type(d[k]) is dict:
TypeError: string indices must be integers