arXiv:2506.14535cs.SEcs.AI2025-06被引 2

用大模型自动重构Qiskit代码,解决版本更新带来的兼容性难题。

Automatic Qiskit Code Refactoring Using Large Language Models

  • 基于官方文档构建迁移模式知识库,指导大模型识别代码问题。
  • 在真实代码上实现高准确率的自动重构建议,提升迁移效率。
  • 适合量子开发人员和工具链研究者参考,推动自动化迁移实践。

随着量子软件框架的快速演进,开发者面临日益严峻的API兼容性维护挑战。本文提出一种利用大语言模型(LLMs)重构Qiskit代码的新方法。通过整合官方文档(如发布说明)中的信息,提取出迁移场景的分类体系,涵盖功能模块迁移、废弃用法替换等常见模式。该分类体系与原始Python代码一同作为输入,由LLM识别代码中对应迁移场景并生成修复建议。为应对当前大模型上下文长度限制,设计了高效、聚焦的输入结构与推理流程。实验表明,在领域特定迁移知识引导下,大模型能有效辅助自动化完成Qiskit代码从旧版本到0.46版本的迁移。本工作不仅提供了经验证的提示词模板与迁移分类体系,还建立了一套评估大模型在量子代码迁移中能力的方法论。

原文摘要 · Abstract (English)

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.

量子计算代码重构大模型应用

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。