AI
New LLM Workflow Significantly Improves Modelica Code Generation for Physics Simulations
Researchers developed ModiGen, an AI-powered system that combines fine-tuning and retrieval techniques to help large language models write complex simulation code with substantially higher accuracy.
Large language models show promise in generating code across many domains, but applying them to specialized languages like Modelica—used extensively for simulating intricate physical systems—has largely gone unexplored. A new research effort tackles this gap by developing a structured approach to improve how LLMs handle Modelica model creation.
The Challenge with LLMs and Specialized Languages#
Modelica demands deep domain knowledge to use effectively, and while LLMs have achieved strong results in general-purpose programming tasks, they struggle significantly when tasked with generating Modelica components. Models produced by unoptimized LLMs frequently fail to execute properly, limiting their practical value for engineers and researchers.
ModiGen's Multi-Part Approach#
The researchers developed ModiGen, a workflow designed to overcome these limitations through three key techniques:
- Supervised fine-tuning to specialize the model on Modelica syntax and patterns
- Graph retrieval-augmented generation to ground code suggestions in relevant examples and structures
- Feedback optimization to iteratively refine outputs based on simulation results
The system was evaluated using custom benchmark datasets created specifically to test how well LLMs can generate both Modelica components and associated test cases.
Substantial Performance Gains#
The results demonstrate meaningful improvements across tasks. The workflow achieved a maximum boost of 0.3349 in pass@1 performance for component generation—meaning roughly a third more models ran successfully on the first attempt. Test case generation saw similar gains, reaching a 0.2457 improvement, significantly narrowing the gap between raw LLM output and production-ready code.
Broader Implications#
These findings suggest that LLMs can become effective partners in creating intelligent modeling and simulation tools when paired with domain-aware training and retrieval strategies. The work points toward future advances in how AI assists specialized engineering tasks and system design workflows.

