Enabling Large Language Models to Perform Power System Simulations with Previously Unseen Tools: A Case of Daline

Mengshuo Jia, Zeyu Cui, Gabriela HugarXiv 2024 · DOI

Introduction

While Large Language Models (LLMs) like GPT-4o have demonstrated remarkable general-purpose reasoning, they frequently struggle with highly specialized engineering tasks. In power systems engineering, researchers rely on sophisticated simulation tools (e.g., OpenDSS, MATPOWER) to model grid behavior. However, LLMs face two primary obstacles in this domain: knowledge cutoffs and technical complexity. If a tool is released after the model's training data was collected, the LLM has no inherent understanding of its syntax. Furthermore, the multi-step logic and intricate parameterization required for power systems often lead to "hallucinations" or non-functional code.

This research introduces a modular framework designed to bridge this gap, transforming an LLM into a reliable research assistant for specialized tools it has never encountered, using the DALINE simulation toolbox as a primary case study.

The Proposed Framework

The researchers developed a four-module architecture to systematically equip LLMs with specialized technical expertise. This framework moves beyond simple prompting to create a deeply integrated retrieval and correction system.

Overview of the proposed modular framework for integrating LLMs with power system simulation tools.

1. Advanced Prompt Engineering

The system utilizes Chain-of-Thought (CoT) and Few-Shot prompting to define specific "actions" for the LLM. Rather than generic instructions, the model is guided to identify functions, learn specific syntax patterns, and extract parameters systematically.

2. Enhanced Retrieval-Augmented Generation (RAG)

Standard RAG often fails when user requests are complex. The authors implemented a query planning strategy where the LLM decomposes a long, natural language request into sub-requests. These are mapped to specific keywords for parallel information retrieval, ensuring the most relevant technical documentation is surfaced.

3. Toolbox Refinement

In a "human-in-the-loop" approach, the simulation tool itself is optimized for AI interaction. This involves creating "AI-friendly" documentation—structured lists of parameters and code examples designed for machine parsing rather than human reading—and implementing automated syntax checking within the tool.

4. Iterative Feedback Loop

When generated code fails, the system provides the LLM with a detailed error report, troubleshooting hints, and the relevant chat history. This allows the model to iteratively correct its logic and syntax until a successful execution is achieved.

Experimental Setup and Datasets

The framework was validated using DALINE, a MATLAB-based toolbox for power flow simulation and linearization. Crucially, DALINE was released after the training cutoffs for the LLMs tested, ensuring the models had zero prior exposure to its codebase. The evaluation comprised 34 simulation tasks, ranging from 27 "Normal Tasks" (standard data generation) to 7 "Complex Tasks" (multi-step requests involving hyperparameter tuning and custom plotting).

Results and Discussion

The impact of the framework was most pronounced in the performance of GPT-4o. Without the framework, the model achieved 0% accuracy due to its lack of knowledge regarding DALINE. However, with the full proposed framework, GPT-4o reached 96.07% accuracy.

Accuracy rating improvements as more components of the proposed framework are utilized, demonstrating a "staircase" effect of cumulative gains.

As shown in the results, high accuracy is not the result of a single technique but a cumulative "staircase" effect. While adding RAG provides an initial baseline, the combination of few-shot prompting and the iterative feedback loop provides the final boost necessary for engineering-grade reliability. Notably, while GPT-3.5 also saw significant improvements, it remained less reliable than GPT-4o, suggesting that the underlying reasoning capability of the base model remains a critical factor in handling complex engineering logic.

Conclusion

This research demonstrates that LLMs can be successfully adapted to specialized engineering domains through structured framework design. By prioritizing "RAG-friendly" documentation and iterative error correction, the system overcomes the limitations of training data cutoffs. Future work will focus on generalizing this framework to accommodate multiple power system simulation tools simultaneously, moving toward a universal AI assistant for grid engineers.

Summary updated

BibTeX
@misc{jia2024enabling,
  author = {Mengshuo Jia and Zeyu Cui and Gabriela Hug},
  title = {{Enabling Large Language Models to Perform Power System Simulations with Previously Unseen Tools: A Case of Daline}},
  year = {2024},
  eprint = {2406.17215},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2406.17215},
}
Figure