Automatic Qiskit Code Refactoring Using Large Language Models
Preprint
Abstract
As quantum software frameworks evolve, developers face increasing challenges in maintaining compatibility with rapidly changing APIs. In this work, we present a novel methodology for refactoring Qiskit code using large language models (LLMs). We begin by extracting a taxonomy of migration scenarios from the different sources of official Qiskit documentation (such as release notes), capturing common patterns such as migration of functionality to different modules and deprecated usage. This taxonomy, along with the original Python source code, is provided as input to an LLM, which is then tasked with identifying instances of migration scenarios in the code and suggesting appropriate refactoring solutions. Our approach is designed to address the context length limitations of current LLMs by structuring the input and reasoning process in a targeted, efficient manner. The results demonstrate that LLMs, when guided by domain-specific migration knowledge, can effectively assist in automating Qiskit code migration. This work contributes both a set of proven prompts and taxonomy for Qiskit code migration from earlier versions to version 0.46 and a methodology to asses the capabilities of LLMs to assist in the migration of quantum code.Keywords
All Related Versions
This publication has 10 references indexed in Scilit:
- An Empirical Study on the Code Refactoring Capability of Large Language ModelsACM Transactions on Software Engineering and Methodology, 2026
- The Impact of Prompt Programming on Function-Level Code GenerationIEEE Transactions on Software Engineering, 2025
- Migrating Code At Scale With LLMs At Google2025
- Benchmarking the performance of quantum computing software for quantum circuit creation, manipulation and compilationNature Computational Science, 2025
- Qiskit Code Assistant: Training LLMs for generating Quantum Computing Code2024
- AI-Driven Refactoring: A Pipeline for Identifying and Correcting Data Clumps in Git RepositoriesElectronics, 2024
- InstructCoder: Instruction Tuning Large Language Models for Code Editing2024
- On Refactoring Quantum Programs in Q#2023
- MQT Bench: Benchmarking Software and Design Automation Tools for Quantum ComputingQuantum, 2023
- Quantum Computing in the NISQ era and beyondQuantum, 2018