如何在pymoo问题中使用外部应用程序实例而无需序列化以启用保存历史记录?
我正在尝试在PYMOO问题的评估中加入外部应用程序。我已经有效了,但是在Pymoo问题中使用外部
>> RuntimeError: Pickling of "arcog.Application" instances is not enabled (http://www.boost.org/libs/python/doc/v2/pickle.html)
应用save_history
方法没有保存外部应用程序实例
我需要的评估功能需要此外部应用程序实例工作 - 因此, 寻找一种解决方案,该解决方案将允许我使用save_history
方法,而无需保存外部应用程序实例(甚至问题本身)
我正在
- 。
QuescookWrapper
类(可能错误地实现了此) - 这仍然意味着需要序列化的外部应用程序,并且我获得了RuntimeReror。 - 我已经尝试使用
save_algorithm = false
,在最小化
中,但是问题本身仍然可以保存,我得到了RuntimeError。
相关代码段如下:
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)
提前感谢您的建议:) 我感觉到这里有机会在这里学习一些新的基础知识,但是我还不够了解要寻找什么。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论