Table of Contents
Fetching ...

Model-Driven Quantum Code Generation Using Large Language Models and Retrieval-Augmented Generation

Nazanin Siavash, Armin Moin

TL;DR

The paper explores a model-driven approach to quantum software engineering by integrating large language models with retrieval-augmented generation to generate quantum code from UML/model instances. It demonstrates a GPT-4o–driven workflow that outputs Qiskit-compatible Python code, groundable via a RAG pipeline but showing limited gains from external repositories in its current setup. Results indicate that carefully engineered prompts substantially improve CodeBLEU and quantum-specific metrics, while RAG context provides marginal benefits without domain-relevant data. The work outlines a promising direction for reducing barriers to quantum programming and highlights avenues for richer data sources and more effective retrieval strategies in future work.

Abstract

This paper introduces a novel research direction for model-to-text/code transformations by leveraging Large Language Models (LLMs) that can be enhanced with Retrieval-Augmented Generation (RAG) pipelines. The focus is on quantum and hybrid quantum-classical software systems, where model-driven approaches can help reduce the costs and mitigate the risks associated with the heterogeneous platform landscape and lack of developers' skills. We validate one of the proposed ideas regarding generating code out of UML model instances of software systems. This Python code uses a well-established library, called Qiskit, to execute on gate-based or circuit-based quantum computers. The RAG pipeline that we deploy incorporates sample Qiskit code from public GitHub repositories. Experimental results show that well-engineered prompts can improve CodeBLEU scores by up to a factor of four, yielding more accurate and consistent quantum code. However, the proposed research direction can go beyond this through further investigation in the future by conducting experiments to address our other research questions and ideas proposed here, such as deploying software system model instances as the source of information in the RAG pipelines, or deploying LLMs for code-to-code transformations, for instance, for transpilation use cases.

Model-Driven Quantum Code Generation Using Large Language Models and Retrieval-Augmented Generation

TL;DR

The paper explores a model-driven approach to quantum software engineering by integrating large language models with retrieval-augmented generation to generate quantum code from UML/model instances. It demonstrates a GPT-4o–driven workflow that outputs Qiskit-compatible Python code, groundable via a RAG pipeline but showing limited gains from external repositories in its current setup. Results indicate that carefully engineered prompts substantially improve CodeBLEU and quantum-specific metrics, while RAG context provides marginal benefits without domain-relevant data. The work outlines a promising direction for reducing barriers to quantum programming and highlights avenues for richer data sources and more effective retrieval strategies in future work.

Abstract

This paper introduces a novel research direction for model-to-text/code transformations by leveraging Large Language Models (LLMs) that can be enhanced with Retrieval-Augmented Generation (RAG) pipelines. The focus is on quantum and hybrid quantum-classical software systems, where model-driven approaches can help reduce the costs and mitigate the risks associated with the heterogeneous platform landscape and lack of developers' skills. We validate one of the proposed ideas regarding generating code out of UML model instances of software systems. This Python code uses a well-established library, called Qiskit, to execute on gate-based or circuit-based quantum computers. The RAG pipeline that we deploy incorporates sample Qiskit code from public GitHub repositories. Experimental results show that well-engineered prompts can improve CodeBLEU scores by up to a factor of four, yielding more accurate and consistent quantum code. However, the proposed research direction can go beyond this through further investigation in the future by conducting experiments to address our other research questions and ideas proposed here, such as deploying software system model instances as the source of information in the RAG pipelines, or deploying LLMs for code-to-code transformations, for instance, for transpilation use cases.

Paper Structure

This paper contains 20 sections, 4 equations, 3 figures, 4 tables.

Figures (3)

  • Figure 1: The overall architecture of our current RAG pipeline configuration
  • Figure 2: Effect of prompt specificity and RAG on quantum code generation metrics
  • Figure 3: Evaluation results for generic and specific prompts on model instance 4 of Jiménez-Navajas et al. Jimenez+2025