I'm trying to optimise multiple linear programming problems in parallel using Pyomo
and the standard Python multiprocessing
library. When switching to using multi-processing I keep running into the error: ValueError: Cannot load a SolverResults object with bad status: error
.
A similar issue was reported in this question, where their problem seemed to be that the solver (n.b. they used cbc whereas I used cplex) was timing out and couldn't gracefully quit. This doesn't seem to be the issue with my error though. One guess is that the cplex solver is trying to write to a temporary file that is then getting overwritten by the parallel optimisations.
Any help fixing this error would be much appreciated! The following code should reproduce the error.
import time
import multiprocessing
import pyomo.environ as pyo
from pyomo.opt import SolverFactory
def run_model(n_runs=50):
for _ in range(n_runs):
opt = SolverFactory(solver_name, executable=solver_executable)
model = pyo.ConcreteModel()
model.x = pyo.Var([1,2], domain=pyo.NonNegativeReals)
model.OBJ = pyo.Objective(expr = 2*model.x[1] + 3*model.x[2])
model.Constraint1 = pyo.Constraint(expr = 3*model.x[1] + 4*model.x[2] >= 1)
opt.solve(model)
time.sleep(0.1)
return
solver_name = 'cplex'
solver_executable = 'C:/Program Files/IBM/ILOG/CPLEX_Studio201/cplex/bin/x64_win64/cplex'
if __name__ == '__main__':
process_list = []
for _ in range(10):
p = multiprocessing.Process(target=run_model)
p.start()
process_list.append(p)
for process in process_list:
process.join()
Process Process-8:
Traceback (most recent call last):
File "C:\Users\User\anaconda3\envs\env\lib\multiprocessing\process.py", line 315, in _bootstrap
self.run()
File "C:\Users\User\anaconda3\envs\env\lib\multiprocessing\process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\User\Desktop\library_dir\scripts\multiprocessing_test.py", line 15, in run_model
opt.solve(model)
File "C:\Users\User\anaconda3\envs\env\lib\site-packages\pyomo\opt\base\solvers.py", line 626, in solve
_model.solutions.load_from(
File "C:\Users\User\anaconda3\envs\env\lib\site-packages\pyomo\core\base\PyomoModel.py", line 224, in load_from
raise ValueError("Cannot load a SolverResults object "
ValueError: Cannot load a SolverResults object with bad status: error
A solution to the overall problem (but not this specific error) was to use glpk
solver from here.