Table of Contents
Fetching ...

PennyCoder: Efficient Domain-Specific LLMs for PennyLane-Based Quantum Code Generation

Abdul Basit, Minghao Shao, Muhammad Haider Asif, Nouhaila Innan, Muhammad Kashif, Alberto Marchisio, Muhammad Shafique

TL;DR

The paper addresses the privacy, latency, and cost challenges of cloud-based quantum code assistants by introducing PennyCoder, a lightweight on-device framework for PennyLane-based quantum code generation. It combines domain-specific instruction tuning on the PennyLang dataset with parameter-efficient LoRA fine-tuning of a LLaMA 3.1-8B foundation model, augmented by an optional RAG module for long-tail tasks. Empirical results show PennyCoder achieving 44.32% accuracy on PennyLane tasks, outperforming both the base model and a RAG-augmented baseline, while maintaining local deployability. This work demonstrates a practical path toward private, on-device quantum programming assistants that can support QML and QRL workflows, and outlines future directions for data augmentation and hardware-aware enhancements.

Abstract

The growing demand for robust quantum programming frameworks has unveiled a critical limitation: current large language model (LLM) based quantum code assistants heavily rely on remote APIs, introducing challenges related to privacy, latency, and excessive usage costs. Addressing this gap, we propose PennyCoder, a novel lightweight framework for quantum code generation, explicitly designed for local and embedded deployment to enable on-device quantum programming assistance without external API dependence. PennyCoder leverages a fine-tuned version of the LLaMA 3.1-8B model, adapted through parameter-efficient Low-Rank Adaptation (LoRA) techniques combined with domain-specific instruction tuning optimized for the specialized syntax and computational logic of quantum programming in PennyLane, including tasks in quantum machine learning and quantum reinforcement learning. Unlike prior work focused on cloud-based quantum code generation, our approach emphasizes device-native operability while maintaining high model efficacy. We rigorously evaluated PennyCoder over a comprehensive quantum programming dataset, achieving 44.3% accuracy with our fine-tuned model (compared to 33.7% for the base LLaMA 3.1-8B and 40.1% for the RAG-augmented baseline), demonstrating a significant improvement in functional correctness.

PennyCoder: Efficient Domain-Specific LLMs for PennyLane-Based Quantum Code Generation

TL;DR

The paper addresses the privacy, latency, and cost challenges of cloud-based quantum code assistants by introducing PennyCoder, a lightweight on-device framework for PennyLane-based quantum code generation. It combines domain-specific instruction tuning on the PennyLang dataset with parameter-efficient LoRA fine-tuning of a LLaMA 3.1-8B foundation model, augmented by an optional RAG module for long-tail tasks. Empirical results show PennyCoder achieving 44.32% accuracy on PennyLane tasks, outperforming both the base model and a RAG-augmented baseline, while maintaining local deployability. This work demonstrates a practical path toward private, on-device quantum programming assistants that can support QML and QRL workflows, and outlines future directions for data augmentation and hardware-aware enhancements.

Abstract

The growing demand for robust quantum programming frameworks has unveiled a critical limitation: current large language model (LLM) based quantum code assistants heavily rely on remote APIs, introducing challenges related to privacy, latency, and excessive usage costs. Addressing this gap, we propose PennyCoder, a novel lightweight framework for quantum code generation, explicitly designed for local and embedded deployment to enable on-device quantum programming assistance without external API dependence. PennyCoder leverages a fine-tuned version of the LLaMA 3.1-8B model, adapted through parameter-efficient Low-Rank Adaptation (LoRA) techniques combined with domain-specific instruction tuning optimized for the specialized syntax and computational logic of quantum programming in PennyLane, including tasks in quantum machine learning and quantum reinforcement learning. Unlike prior work focused on cloud-based quantum code generation, our approach emphasizes device-native operability while maintaining high model efficacy. We rigorously evaluated PennyCoder over a comprehensive quantum programming dataset, achieving 44.3% accuracy with our fine-tuned model (compared to 33.7% for the base LLaMA 3.1-8B and 40.1% for the RAG-augmented baseline), demonstrating a significant improvement in functional correctness.

Paper Structure

This paper contains 24 sections, 1 equation, 5 figures, 3 tables.

Figures (5)

  • Figure 1: PennyCoder system, a lightweight on-device quantum code generation assistant. User queries are processed locally by a LoRA-tuned LLaMA 3.1-8B model, enhanced through domain-specific instruction tuning on the PennyLang dataset. The system outputs valid PennyLane-compatible quantum code and eliminates the need for external APIs by supporting embedded, privacy-conscious deployment.
  • Figure 2: Composition of the PennyLang dataset (3,347 samples).
  • Figure 3: Overview of the PennyCoder framework. The PennyLang dataset, structured in an instruction-code format, is used both for direct domain-specific fine-tuning of a foundation model (using Low-Rank Adaptation) and for building a retrieval corpus in the RAG pipeline. During training, fine-tuning adapts a LLaMA 3.1-8B model to PennyLane quantum programming tasks. During evaluation, the system supports both direct generation and RAG to enhance few-shot generalization. Generated outputs are evaluated for functional correctness against the PennyLang test set, using controlled decoding settings such as temperature scaling and nucleus (top-$p$) sampling.
  • Figure 4: Distribution of benchmark tasks across quantum programming categories. Basic circuits represent the largest share (41%). Each task is assigned to its most relevant category.
  • Figure 5: Category-wised accuracy analysis. Explanation of task category abbreviation: Circuits=Basic quantum circuits; Comp+HW=Compilation, noise simulation & hardware mapping; Algorithms=Quantum algorithms, QML&QRL; Chem+Sim=Quantum chemistry & simulation; Protocols=Quantum protocols.