FMU 中的强化学习代理

Reinforcement Learning Agent in FMU

我想在我在 OpenModelica 中构建的模型上训练强化学习代理。通过使用pyFMI,导入FMU,仿真,得到一些结果是没有问题的。

我的问题是我没有可能在每个步骤后 "pause" 进行模拟,获取状态,将其输入我的 RL 代理并将其建议的操作作为输入返回。

ModelicaGym 似乎是一种通过开始模拟、停止、获取结果、定义下一个动作并以上次结束时间作为开始时间再次开始模拟来解决此问题的方法。

阅读隆德大学 (https://portal.research.lu.se/portal/files/7201641/pyfmi_tech.pdf) 的一篇论文让我想到了另一个想法:

正在用 Learner 创建一个 FMU,并通过 PyFMI.Master 连接两个 FMU。

大致如下:

from  pyfmi  import  load_fmu
from  pyfmi.master  import  Master

controller   = load_fmu("controller.fmu")
Circuit = load_fmu("circuit.fmu")

connections = [( Circuit ,"currentSensor1.i",controller ,"feedback1.u2"),
               (controller ,"PID.y",Circuit ,"signalVoltage1.v")]

models = [Circuit , controller]
master_simulator = Master(models , connections)
res = master_simulator.simulate(final_time =1)

使用内部带有 PID 控制器的其他 FMU 控制电路是可行的,但是是否可以创建带有强化学习代理的 FMU,包括所有其他需要的库、包(Keras、Tensorflow?)

根据我的观点,这样的实现可以有很好的性能,特别是对于具有更高复杂性的模型和学习器,这可能是一种有趣的方法。

或者我只是在追逐一些梦想,因为在 FMU 中实现强化学习算法是不可能的或导致其他麻烦?

实际上,我有点惊讶没有发现其他人试图实现这个。

此致

亨里克

也许你可以更新你的问题,这样学习代理是如何实现的就更清楚了,但我知道它可以用于 Python?

PyFMI 文档中的示例 fmu_with_input_function.py 说明了如何使用函数作为 FMU 的输入。我想你可以在这个函数中从 FMU 检索信息,就像这样(未经测试的伪代码):

from pyfmi import load_fmu

define input_object(model):
  response = model.get('response_variable_name')
  return ('input_var_name', learner(response))

model = load_fmu('model.fmu')

res = model.simulate(final_time=30, input=input_object(model))

您必须设置您的模型 FMU,以便您的学习者应该更改的变量 (input_var_name) 是 输入变量 可调参数。如果使用不带 variability="tunable" 的参数,则无法在模拟过程中更改它们。

我会首先尝试使用输入变量,因为可调参数处理起来有点复杂,并且在某些工具中可能无法正确实现。

这个答案可能来得太晚了,但是我在研究完全相同的问题时发现了你的问题。根据我的理解,你的问题是在论文中提出的

建筑协同仿真环境中深度强化学习控制器的集成与评估 [PDF found here]

However in our context, the co-simulation environment that is used for the study of Cyber-Physical Systems is a master of co-simulation, and need to be able to call AI based Python libraries or tools from within the co-simulation. In the co-simulation, the controller requires an interaction with the controlled component at each iteration. Therefore, it is necessary to generate the AI based control components in the form of an FMU as is the case for the other components.

他们使用了一个名为 DACCOSIM NG 的工具,但后来引入了他们自己的方法来使这种方法更加精简。

希望您早就找到了自己的解决方案。