如何在pymoo问题中使用外部应用程序实例而无需序列化以启用保存历史记录?

发布于 2025-01-29 15:57:12 字数 1792 浏览 3 评论 0原文

我正在尝试在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, in minimize, 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文