Abstract: Code Large Language Models (Code LLMs) have emerged as powerful tools, revolutionizing the software development landscape by automating the coding process and reducing time and effort required to build applications. This paper focuses on training Code LLMs to specialize in the field of quantum computing. We begin by discussing the unique needs of quantum computing programming, which differ significantly from classical programming approaches or languages. A Code LLM specializing in quantum computing requires a foundational understanding of quantum computing and quantum information theory. However, the scarcity of available quantum code examples and the rapidly evolving field, which necessitates continuous dataset updates, present significant challenges. Moreover, we discuss our work on training Code LLMs to produce high-quality quantum code using the Qiskit library. This work includes an examination of the various aspects of the LLMs used for training and the specific training conditions, as well as the results obtained with our current models. To evaluate our models, we have developed a custom benchmark, similar to HumanEval, which includes a set of tests specifically designed for the field of quantum computing programming using Qiskit. Our findings indicate that our model outperforms existing state-of-the-art models in quantum computing tasks. We also provide examples of code suggestions, comparing our model to other relevant code LLMs. Finally, we introduce a discussion on the potential benefits of Code LLMs for quantum computing computational scientists, researchers, and practitioners. We also explore various features and future work that could be relevant in this context.
Introduction
Quantum computing (QC) presents a unique challenge for software development. Unlike classical programming, writing quantum code requires a foundational grasp of quantum mechanics and information theory. Furthermore, the field moves incredibly fast; the Qiskit SDK—the most popular open-source framework for QC—frequently updates its syntax and deprecates old features.
General-purpose code LLMs (like GPT-4 or CodeLlama) often struggle with QC due to data scarcity, hallucinations involving outdated library functions, and a lack of specialized domain logic. To address these issues, researchers at IBM developed a specialized LLM tailored specifically for quantum computing using the Qiskit SDK.
Methodology
The development of Granite-20B-Code-QK involved a multi-stage training pipeline starting from the Granite-20b-code base model, which was originally trained on 1.6 trillion tokens of general code.
Training Data and Weighting
The model underwent extended pre-training on 88 million tokens of Qiskit-specific data crawled from GitHub. To ensure the model learned modern, non-deprecated syntax, the team filtered out any code updated before 2022. Data was categorized into "Official" (high quality) and "Community" sources. As shown in the training configuration, official documentation was significantly oversampled to prioritize accuracy.
Instruct-Tuning
To improve natural language instruction following, the researchers added 2.7k synthetic Q&A pairs generated via Mixtral and 1k prompt/code pairs. A critical step in this process was the use of automated unit tests to validate synthetic code before training, ensuring the model did not learn incorrect patterns.
Evaluation and Results
To evaluate performance, the authors introduced Qiskit HumanEval (QHE), an execution-based benchmark consisting of 101 original quantum programming problems. Each problem includes a function signature, a docstring, and a suite of unit tests.
Performance Metrics
The specialized Granite-20B-Code-QK model demonstrated a significant performance leap in quantum-specific tasks. On the QHE benchmark, it achieved a 46.53% pass@1 score, notably outperforming its base model and larger competitors like DeepSeek-Coder-33B.
Domain Understanding
Qualitative tests revealed that the model successfully maps high-level quantum physics terminology to specific code properties. For instance, it correctly identifies the relationship between "thermal relaxation time" and the T1 property in Qiskit, a nuance often missed by general-purpose models. It also shows superior accuracy in identifying specific hardware backends compared to general models that often default to simulators or legacy imports.
Discussion and Future Work
The success of Granite-20B-Code-QK highlights that in rapidly evolving technical fields, data recency and quality weighting are more critical than sheer data volume. By discarding "zombie" syntax from before 2022, the model remains relevant to current development environments.
Future work will focus on expanding the model's breadth to include other quantum libraries (such as Cirq or PennyLane) and developing features for automatic code repair and automated test generation. IBM intends to release the Qiskit HumanEval benchmark to the community in late 2024 to foster further research in quantum-specific LLM applications.
Summary updated