Abstract
Programming quantum computers at the assembly level remains a significant challenge due to data scarcity and the inherent complexity of quantum logic. We present QAgent, a hierarchical multi-agent framework designed to automate the generation of OpenQASM code from natural language descriptions. QAgent employs a two-tier strategy: a Dynamic-few-shot Coder for standard tasks and a Tools-augmented Coder for complex, multi-step requirements. By incorporating an iterative reflection loop, QAgent improves functional correctness by 71.6% compared to baseline LLM prompting methods.
Introduction
While Noisy Intermediate-Scale Quantum (NISQ) devices are beginning to demonstrate advantages over classical systems, the "metal"—the low-level Open Quantum Assembly Language (OpenQASM)—is notoriously difficult to write and debug. Most developers rely on high-level Python SDKs like Qiskit, but direct assembly programming is essential for hardware-specific optimizations.
Large Language Models (LLMs) have transformed classical software engineering, yet they struggle with quantum assembly. This difficulty stems from the scarcity of OpenQASM training data, the counter-intuitive logic of quantum algorithms (where a single misplaced gate can invalidate the entire circuit), and the need to adhere to strict hardware constraints. QAgent addresses these hurdles by providing an autonomous, multi-agent bridge from natural language to executable assembly code.
The QAgent Framework
QAgent utilizes a hybrid, hierarchical architecture designed to match the complexity of the input task with the appropriate level of reasoning.
1. Dynamic-few-shot Coder
For canonical or well-structured quantum tasks, QAgent employs a Dynamic-few-shot Coder. This module uses Retrieval-Augmented Generation (RAG) to identify similar OpenQASM examples from a curated database. These examples serve as templates, allowing the model to "mimic" proven logic for standard algorithms like Bernstein-Vazirani or Grover’s search.
2. Tools-augmented Coder
When tasks involve complex, parameterized requirements where simple imitation is insufficient, the system escalates to the Tools-augmented Coder. This module functions as an automated engineer, decomposing the prompt into sub-tasks, creating a step-by-step execution plan, and utilizing a library of Python-based tools to generate precise circuit logic.
3. Iterative Reflection Loop
Central to both coders is the Reflection Agent. If the generated code fails initial simulation or syntax checks, the Reflection Agent analyzes error logs and uses Chain-of-Thought (CoT) reasoning to identify bugs and suggest revisions. This "try-again" mechanism is critical for refining complex quantum logic.
Experimental Setup and Datasets
QAgent was evaluated using two primary benchmarks:
- QCircuitNet: A dataset of fundamental "Level-1" quantum problems described in natural language and LaTeX.
- Composite Multi-algorithm Tasks: A new dataset for "Level-2" to "Level-4" problems, requiring the agent to decompose complex queries into multiple distinct quantum algorithms (e.g., combining Phase Estimation with W-state preparation).
Key Results and Analysis
The implementation of QAgent resulted in a massive 71.6% increase in functional correctness over static LLM prompting baselines.
Model Scaling and Performance
Evaluation across the Qwen model family (7B, 32B, and 235B parameters) revealed that while smaller models are competent at basic syntax, the 235B model is significantly more effective at the complex parameter extraction and tool selection required for advanced circuits. As shown in the results, syntax validity is generally high across models, but functional correctness—ensuring the code actually solves the intended physics problem—is where QAgent provides the most significant value.
The Decomposition Challenge
A key finding was the "decomposition wall." While QAgent excels at Level-1 and Level-2 tasks, performance begins to degrade as the number of required algorithms in a single prompt increases (Level-3 and Level-4). This suggests that the primary bottleneck for autonomous quantum programming is often the initial semantic understanding and segmentation of complex user instructions.
Conclusion
QAgent represents a significant step toward democratizing quantum hardware access. By combining imitation-based learning with tool-augmented planning and iterative debugging, it bridges the gap between natural language and low-level assembly. Future work will focus on more proactive "triage" systems to predict task complexity and improved strategies for decomposing highly composite quantum requirements.
Summary updated