A Framework for Automated Simulink Model Generation from Natural Language Specifications.
一个用于从自然语言规格说明自动生成Simulink模型的框架。
NL2Sim is a groundbreaking framework that bridges the gap between high-level system requirements described in natural language and their formal implementation in MATLAB/Simulink. Powered by a Large Language Model (LLM) engine constrained within a robust engineering system, NL2Sim dramatically accelerates the Model-Based Design (MBD) workflow, reduces manual errors, and lowers the technical barrier for domain experts.
NL2Sim 是一个开创性的框架,它弥合了用自然语言描述的高层系统需求与在MATLAB/Simulink中进行形式化实现之间的鸿沟。在一个稳健的工程系统内,由一个受约束的大型语言模型(LLM)引擎驱动,NL2Sim 极大地加速了基于模型的设计(MBD)工作流,减少了人为错误,并为领域专家降低了技术门槛。
This entire project, from concept to a robust prototype, was developed in just 3 days by a programming novice in collaboration with Gemini.
整个项目,从概念到一个健壮的原型,是由一位编程新手与Gemini合作,在短短3天内完成的。
- Natural Language Interface: Describe your system in plain English or Chinese.
- 自然语言接口:用简单的英文或中文描述您的系统。
- Complex Model Generation: Capable of generating models with linear/non-linear dynamics, logic gates, feedback loops, and multi-level integrations.
- 复杂模型生成:能够生成包含线性/非线性动态、逻辑门、反馈回路和多级积分的模型。
- Extensible Knowledge Base: Easily extendable to support new Simulink blocks by simply updating an external JSON knowledge base, without touching the core code.
- 可扩展的知识库:通过简单地更新一个外部JSON知识库,即可轻松扩展以支持新的Simulink模块,而无需触及核心代码。
- Robust & Decoupled Architecture: A three-tier architecture ensures maintainability and reliability.
- 稳健的解耦架构:三层架构确保了可维护性和可靠性。
The system employs a three-tier decoupled architecture: NL2Sim 采用三层解耦架构:
- Frontend & Controller (
main_controller_web.py): A Flask-based web server that accepts user requests and manages asynchronous tasks.- 前端与控制器:一个基于Flask的Web服务器,用于接收用户请求和管理异步任务。
- Instruction Generation Engine (
prompts.py): The "brain" of the system. It uses a sophisticated prompt engineering framework and a dynamic knowledge base (simulink_blocks_kb.json) to guide an LLM (Gemini) in translating natural language into a structured JSON instruction sequence.- 指令生成引擎:系统的“大脑”。它使用一个复杂的提示工程框架和一个动态知识库,来引导LLM(Gemini)将自然语言翻译成结构化的JSON指令序列。
- Model Synthesis Service (
simulink_service.py): The "hands" of the system. A standalone Python service that communicates with a local MATLAB/Simulink instance via the MATLAB Engine API to execute the JSON instructions atomically.- 模型合成服务:系统的“双手”。一个独立的Python服务,通过MATLAB引擎API与本地的MATLAB/Simulink实例通信,以原子方式执行JSON指令。
- Python 3.8+
- MATLAB & Simulink (e.g., R2024b or newer)
- MATLAB Engine API for Python
- A Google AI API Key
- Clone the repository:
git clone [https://github.com/CraftNobody0505/NL2Sim.git](https://github.com/CraftNobody0505/NL2Sim.git) cd NL2Sim - Install Python dependencies:
(You will need to create a
pip install -r requirements.txt
requirements.txtfile) - Set up your API Key:
export GOOGLE_API_KEY="YOUR_API_KEY"
- Run the services:
- In one terminal, start the Simulink service:
python simulink_service.py
- In another terminal, start the main controller:
python main_controller_web.py
- In one terminal, start the Simulink service:
- Open your browser and go to
http://127.0.0.1:8080.
We have successfully validated the framework with three increasingly complex models: 我们已通过三个复杂度递增的模型成功验证了该框架:
- PID Controller: A standard linear control system.
- Thermostat: A non-linear system with logic gates and feedback loops.
- Projectile Motion: A dynamic system involving trigonometric functions and second-order integration.
This project is licensed under the [MIT]. See the LICENSE file for details.
本项目采用 [MIT] 授权。详情请见 LICENSE 文件。