Automating Modelica Module Generation Using Large Language Models: A Case Study on Building Control Description Language
作者: Hanlong Wan, Xing Lu, Yan Chen, Karthik Devaprasad, Laura Hinkle
分类: cs.SE, cs.AI, cs.PL, eess.SY
发布日期: 2025-09-18
备注: This is the pre-peer-review version of a journal paper; the repo is available at: https://github.com/pnnl/prompt2control
💡 一句话要点
利用大语言模型自动化生成Modelica模块,以建筑控制描述语言为例
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 大型语言模型 Modelica 代码生成 自动化 建筑控制 提示工程 人机协同 能源系统
📋 核心要点
- Modelica控制模块开发耗时且依赖专家知识,现有方法难以满足快速开发需求。
- 利用大语言模型,结合提示工程、知识库检索和人机协同,自动化生成Modelica控制模块。
- 实验表明,该方法能显著缩短开发时间(40%-60%),但仍需人工干预以保证代码质量。
📝 摘要(中文)
动态能源系统和控制需要先进的建模框架来设计和测试监管和容错策略。Modelica是一种广泛使用的基于方程的语言,但开发控制模块需要大量的人工和专业的知识。本文研究了使用大型语言模型(LLM)来自动化生成建筑Modelica库中的控制描述语言模块。我们开发了一个结构化的工作流程,该流程结合了标准化的提示支架、库感知的 grounding、使用OpenModelica的自动编译以及人机协同评估。实验在四个基本逻辑任务(与、或、非和开关)和五个控制模块(冷却器启用/禁用、旁通阀控制、冷却塔风扇速度、工厂请求和泄压阻尼器控制)上进行。结果表明,GPT 4o在零样本模式下未能生成可执行的Modelica代码,而Claude Sonnet 4通过精心设计的提示,在基本逻辑块上实现了高达完全成功的水平。对于控制模块,成功率达到83%,失败的输出需要中等程度的人工修复(估计1到8小时)。检索增强生成通常会在模块选择中产生不匹配(例如,将与检索为或),而确定性的硬规则搜索策略避免了这些错误。人工评估也优于AI评估,因为当前的LLM无法评估仿真结果或验证行为正确性。尽管存在这些限制,但LLM辅助的工作流程将每个模块的平均开发时间从10到20小时减少到4到6小时,相当于节省了40%到60%的时间。这些结果突出了LLM辅助Modelica生成的潜力和当前局限性,并指出了未来在预仿真验证、更强的 grounding 和闭环评估方面的研究方向。
🔬 方法详解
问题定义:论文旨在解决Modelica控制模块开发效率低下的问题。传统方法依赖人工编写,耗时且需要专业知识,难以快速适应动态能源系统和控制的需求。现有方法缺乏自动化工具,无法有效利用大型语言模型的能力。
核心思路:论文的核心思路是利用大型语言模型(LLM)的自然语言理解和代码生成能力,结合结构化的提示工程和知识库检索,自动化生成Modelica控制模块。通过人机协同的方式,弥补LLM在代码正确性和行为验证方面的不足。
技术框架:该方法包含以下主要阶段:1) 标准化提示支架:设计结构化的提示模板,引导LLM生成特定类型的Modelica代码。2) 库感知 grounding:利用知识库检索相关模块信息,为LLM提供上下文知识。3) 自动编译:使用OpenModelica自动编译生成的代码,检测语法错误。4) 人机协同评估:人工评估代码的正确性和行为,并进行必要的修复。
关键创新:该方法的主要创新在于将大型语言模型应用于Modelica代码生成,并结合了结构化的提示工程、知识库检索和人机协同。与传统的纯人工编写方法相比,该方法能够显著提高开发效率。与直接使用LLM生成代码相比,该方法通过提示工程和知识库检索,提高了代码的质量和正确性。
关键设计:论文中,提示工程的设计至关重要,需要根据不同的控制模块类型设计不同的提示模板。知识库检索策略的选择也影响着代码生成的质量,论文比较了检索增强生成和确定性的硬规则搜索策略。此外,人机协同评估环节也需要设计合理的评估指标和流程,以确保代码的正确性和行为符合预期。
📊 实验亮点
实验结果表明,使用LLM辅助的工作流程将每个模块的平均开发时间从10到20小时减少到4到6小时,节省了40%到60%的时间。Claude Sonnet 4通过精心设计的提示,在基本逻辑块上实现了高达完全成功的水平。对于控制模块,成功率达到83%。
🎯 应用场景
该研究成果可应用于动态能源系统和控制领域,加速Modelica控制模块的开发,降低开发成本,提高开发效率。该方法还可推广到其他领域,例如机器人控制、自动化生产等,实现控制系统的快速设计和部署。未来,随着LLM能力的提升,有望实现完全自动化的Modelica代码生成。
📄 摘要(原文)
Dynamic energy systems and controls require advanced modeling frameworks to design and test supervisory and fault tolerant strategies. Modelica is a widely used equation based language, but developing control modules is labor intensive and requires specialized expertise. This paper examines the use of large language models (LLMs) to automate the generation of Control Description Language modules in the Building Modelica Library as a case study. We developed a structured workflow that combines standardized prompt scaffolds, library aware grounding, automated compilation with OpenModelica, and human in the loop evaluation. Experiments were carried out on four basic logic tasks (And, Or, Not, and Switch) and five control modules (chiller enable/disable, bypass valve control, cooling tower fan speed, plant requests, and relief damper control). The results showed that GPT 4o failed to produce executable Modelica code in zero shot mode, while Claude Sonnet 4 achieved up to full success for basic logic blocks with carefully engineered prompts. For control modules, success rates reached 83 percent, and failed outputs required medium level human repair (estimated one to eight hours). Retrieval augmented generation often produced mismatches in module selection (for example, And retrieved as Or), while a deterministic hard rule search strategy avoided these errors. Human evaluation also outperformed AI evaluation, since current LLMs cannot assess simulation results or validate behavioral correctness. Despite these limitations, the LLM assisted workflow reduced the average development time from 10 to 20 hours down to 4 to 6 hours per module, corresponding to 40 to 60 percent time savings. These results highlight both the potential and current limitations of LLM assisted Modelica generation, and point to future research in pre simulation validation, stronger grounding, and closed loop evaluation.