I'm trying to include an external application instance in the evaluation of a pymoo problem. I've got this working, but having the external application in the pymoo problem means that I can't use the save_history
method, and I get the following error:
>> RuntimeError: Pickling of "arcog.Application" instances is not enabled (http://www.boost.org/libs/python/doc/v2/pickle.html)
I'm aiming to be able to use the save_history
method without saving the external application instance
The evaluate function I need requires this external application instance to work - as such,
I'm looking for a solution that will allow me to use the save_history
method without saving the external application instance (or even the Problem itself..)
I've tried:
- Using a wrapper function outside of the
ProblemWrapper
class (could have implemented this incorrectly) - this still meant that the external application needed to be serialised, and I get the RuntimeError. - I've tried using
save_algorithm=False
, inminimize
, but the Problem itself still gets saved, and I get the RuntimeError.
The associated code snippet is below:
from pymoo.core.problem import Problem
from pymoo.optimize import minimize
from pymoo.algorithms.moo.nsga2 import NSGA2
class ProblemWrapper(Problem):
def __init__(self, app, xconfig, limits, *args, **kwargs):
Problem.__init__(self, *args, **kwargs)
self.app = app
self.xconfig = xconfig
self.limits = limits
def _evaluate(self, designs, out, *args, **kwargs):
res = []
for design in designs:
print("Evaluating an individual.")
evald = eval_func(design, self.app,
self.xconfig, self.limits)
res.append(evald)
out["F"] = np.array(res)
problem = ProblemWrapper(n_var=N_VAR, n_obj=N_OBJ, xl=xl,
xu=xu, app=app,
xconfig=xconfig, limits=limits)
algorithm = NSGA2(pop_size=POPSIZE)
stop_criteria = ('n_gen', N_GEN)
results = minimize(
problem=problem,
algorithm=algorithm,
termination=stop_criteria,
save_history=True)
Thanks in advance for your advice :) I'm sensing there's an opportunity to learn some new fundamentals here, but I'm not quite onto it enough to know what to look for.