TLDR: This paper introduces a novel approach for generating quantum and hybrid quantum-classical software code. It leverages Large Language Models (LLMs) to transform UML design models into Python code using the Qiskit library. The method is enhanced by Retrieval-Augmented Generation (RAG) and demonstrates that well-engineered prompts can significantly improve code accuracy and consistency, outperforming the current RAG setup with general code repositories. The research aims to reduce development costs and risks in the complex quantum software landscape.
The world of software development is constantly evolving, and with the emergence of quantum computing, new challenges and opportunities arise. Developing software for quantum and hybrid quantum-classical systems is complex, often requiring specialized skills and navigating diverse technological platforms. This complexity can lead to higher costs and increased risks in development.
A recent research paper introduces a promising new direction to tackle these challenges: using Large Language Models (LLMs) to generate quantum code directly from software design models. This approach, enhanced by a technique called Retrieval-Augmented Generation (RAG), aims to make quantum software development more accessible and efficient.
Bridging Design Models and Code with AI
The core idea is to leverage Model-Driven Software Engineering (MDSE), a paradigm where software is developed using abstract models, and combine it with the power of LLMs. Traditionally, code generation from models relied on predefined rules and templates. However, LLMs, like OpenAI’s GPT-4o, can generate code more flexibly and intelligently, learning patterns from vast amounts of programming data.
The researchers focused on generating Python code that works with Qiskit, a popular open-source quantum computing framework. The input to the LLM is a textual representation of a software system’s design model, often based on Unified Modeling Language (UML) instances. The LLM then translates this design into executable quantum code.
Enhancing LLMs with Retrieval-Augmented Generation (RAG)
One of the known limitations of LLMs is their tendency to sometimes “hallucinate” or generate plausible but incorrect information. To mitigate this, the paper proposes integrating a RAG pipeline. This system allows the LLM to dynamically access external knowledge during code generation. In this setup, a retriever identifies relevant code snippets from a knowledge base (in this case, sample Qiskit code from public GitHub repositories), and the generator uses this retrieved information to produce more accurate and consistent quantum code.
The Power of Prompt Engineering
A significant finding from the experimental results highlights the critical role of “prompt engineering.” This involves carefully crafting the instructions given to the LLM. The study compared two types of prompts: a generic one that simply asked for quantum code based on the model, and a more specific one that included detailed implementation requirements, such as quantum gate mapping strategies and syntax rules.
The results were striking. For one model instance, using a specific prompt dramatically improved the CodeBLEU score (a metric for evaluating code generation quality) from 0.16 to 0.57. This indicates that well-engineered prompts can lead to significantly more accurate and consistent quantum code, improving quality by up to a factor of four.
Also Read:
- Quantum Machine Learning Enhances Entanglement in Quantum Sensors
- Knowledge Graphs Enhance Large Language Models for Alzheimer’s Disease Studies
Experimental Insights and Future Directions
While prompt engineering showed substantial improvements, the initial RAG pipeline, which incorporated general Qiskit GitHub repositories, did not significantly enhance performance. This suggests that the external context provided was not sufficiently relevant or structured for the specific task of generating quantum code from UML models. This insight opens avenues for future work, including incorporating more domain-specific and structured external sources into the RAG pipeline.
The research also outlines several future directions, such as deploying software system model instances as the source of information in RAG pipelines, using LLMs for code-to-code transformations (like transpilation), and exploring other LLMs like Claude. The ultimate goal is to further reduce the costs and risks associated with developing complex quantum and hybrid quantum-classical software systems.
For those interested in the technical details, the full research paper can be accessed here. The source code for this project is also publicly available on GitHub.


