Abstract
Designing efficient quantum circuits is a significant bottleneck in quantum software development. We present QUASAR, an agentic reinforcement learning (RL) framework that trains Large Language Models (LLMs) to generate and optimize high-quality OpenQASM code. By incorporating a Quantum Tool Server for real-time simulation and a hierarchical reward pipeline, QUASAR achieves 100% syntactical validity in Pass@10 and significantly outperforms industrial models like GPT-4o and DeepSeek-V3 in quantum algorithm design.
Introduction
As quantum hardware matures, the need for platform-agnostic assembly languages like OpenQASM increases. However, writing OpenQASM is notoriously difficult for both humans and standard LLMs. Challenges include the need for extreme numerical precision in gate parameters, a lack of fundamental quantum mechanical understanding (leading to "hallucinations"), and the nondeterministic nature of quantum evaluation.
Methodology
QUASAR addresses these challenges by treating the LLM as an agent within a reinforcement learning loop. The framework utilizes a 4B-parameter model (Qwen3) that interacts with an external environment to refine its outputs.
The Agentic Pipeline and Hierarchical Reward
The LLM proposes a circuit, which is then sent to a Quantum Tool Server. The server executes the code in a simulator and returns feedback, including execution errors and physical metrics. This feedback is used to update the model's policy via Group Relative Policy Optimization (GRPO).
The core innovation is a four-stage hierarchical reward system:
- Syntactic Reward: Ensures the code compiles.
- Distributional Alignment: Uses Jensen-Shannon distance to match the output probability distribution to a ground-truth solution.
- Expectation Value Reward: Evaluates if the circuit solves the target physics problem (e.g., Hamiltonian minimization).
- Optimization Progress: Rewards the model for providing a high-quality "warm start" that reduces the steps needed for classical optimizers.
Experimental Setup
QUASAR was evaluated on a dataset of 12 central optimization primitives, including MaxCut, the Traveling Salesman Problem (TSP), and Hamiltonian Path problems. The training focused on generating circuits for Variational Quantum Eigensolvers (VQE) and the Quantum Approximate Optimization Algorithm (QAOA).
Results
QUASAR demonstrates superior performance across several key metrics:
- Syntactical Correctness (SCR): Achieved 99.31% in Pass@1 and 100% in Pass@10, surpassing GPT-4o (87.93%) and DeepSeek-V3 (94.83%).
- Semantic Success (SREV): Showed a 12.95% improvement over RL-only baselines in solving actual physics problems.
- Efficiency: Generated circuits provided significantly better initializations for hybrid quantum-classical optimizers compared to standard methods.
Discussion and Conclusion
A key finding is that Distributional Alignment (Relative Entropy) is the primary driver of semantic performance. By enforcing a hierarchy where syntax is mastered before physics, QUASAR ensures the model learns the "rules of the road" effectively. While the model currently faces challenges with higher-order (HUBO) problems, future work will focus on integrating classical "presolvers" and expanding to more diverse hardware layouts. QUASAR represents a significant step toward automated, high-performance quantum software engineering.
Summary updated