betaFeedback

WorksComputer Science

Large Language Models for Quantum Code Translation: An Exploratory Study

Abstract

Quantum software development is challenged by quantum-mechanical semantics and fragmented software development kits (SDKs), which complicate cross-SDK code translation and execution. In this paper, we propose an LLM-based approach for translating executable programs between high-level quantum SDKs. We develop a quantum-aware translation workflow whose prompt design and validation reflect quantum semantics and accommodate the version evolution of quantum ecosystems. We conduct a preliminary evaluation of 4 LLM configurations on 43 tasks, translating Qiskit programs to PennyLane and Q#. LLMs achieve a zero-shot Pass@1 of up to 72.33%, while one-shot prompting further improves the translation effectiveness. These results suggest potential for quantum code translation by LLMs.

Introduction

Quantum computing has attracted growing interest, leading to a diverse ecosystem of software development kits (SDKs) and programming languages, including Qiskit [10], PennyLane [25], and Q# [16]. However, quantum software development remains challenging because quantum-mechanical abstractions, such as superposition, entanglement, and probabilistic measurement, are unfamiliar to many software engineers. Meanwhile, heterogeneous SDK interfaces and backend-specific execution models require developers to reconcile different application programming interfaces (APIs) and runtime constraints, complicating quantum software development and maintenance.

Code translation [2, 12] is a natural software-engineering response to this interoperability problem. For example, a controlled-X gate can be expressed in Qiskit as qc.cx(a, b) and in Q# as Controlled X([q[a]], q[b]);, where aa and bb index the control and target qubits, respectively. A practical translator should perform this API mapping while preserving the source program’s intended behavior or code structure. Large language models (LLMs) are promising candidates for this task because they can interpret code and natural-language specifications, generate code in different programming languages, and have supported activities in quantum software engineering, such as code generation [9], comment generation [27], and static analysis [19]. Such intuition and observations motivate us to investigate whether LLMs can translate quantum programs across heterogeneous SDKs while preserving their required behavior and structure.

To the best of our knowledge, this paper presents the first proposal of LLM-based quantum code translation between high-level SDKs or programming languages to deal with developer-facing quantum programming. We propose a quantum-aware LLM translation workflow from input tasks to translated programs along with the aggregate analysis. In particular, we contribute a prompt-construction method tailored to quantum code translation: it captures quantum-mechanical semantics, such as qubit ordering and the roles of control and target qubits, together with SDK-specific syntax, version constraints, runtime requirements, and task specifications, thereby accommodating the rapid evolution of quantum programming frameworks. We preliminarily evaluate four LLM configurations on 43 benchmark tasks, translating Qiskit programs to PennyLane and Q# and comparing zero-shot with one-shot prompting for two models. The best zero-shot Pass@1 reaches 72.33% on PennyLane and 71.63% on Q#, while one-shot prompting can substantially improve Pass@1. Furthermore, we find that missing source artifacts and SDK compilation errors dominate zero-shot failures, accounting for 39.2% and 34.9%, respectively. These findings suggest the potential of LLM-based quantum code translation while identifying key barriers for future research.

Background and Related Work

LLM-based translation of classical code. LLMs have been applied to translate classical code across programming languages [18]. UniTrans uses execution feedback [26], InterTrans explores intermediate translation paths [15], and AlphaTrans decomposes repositories and combines translation with multiple validation levels [11]. These advances motivate applying LLMs to quantum code translation, where preserving behavior also requires accounting for relative phase, bit ordering, control and target roles, and probabilistic measurement outcomes.

Quantum code migration across versions. Prior work investigates how quantum code can be migrated across SDK versions [22], which involves refactoring the original code to accommodate changes in APIs. By contrast, quantum code translation transfers programs across heterogeneous SDKs or programming languages, which requires reconciling different programming abstractions and execution conventions, rather than handling incremental updates within the same SDK.

Quantum code transpilation. Transpilation in quantum computing refers to the process of transforming a quantum circuit into an equivalent one that is compatible with the target quantum hardware or simulator. Several works also perform cross-SDK transpilation, such as Siavash et al. suggesting the use of LLMs [20] and LinguaQuanta leveraging the gate decomposition [24]. However, quantum code transpilation is rooted in the hardware-oriented conversion in terms of compilers and backends, while our quantum code translation targets the high-level SDKs that could be used by developers to design quantum code.

Quantum code generation. Quantum code generation studies use model-driven engineering or LLMs, including (1) model-based generation, like QuanUML [8] and M2QCode [7]; (2) LLM benchmarking studies like Qiskit Code Assistant [5], PennyCoder [1], QuanBench [9], and QuanBench+ [21]; and (3) LLM agents such as QPipe [23] and QAgent [6]. Compared to code generation, including multi-platform generation for one task [7], our translation task converts a given source program into a target program in another SDK or language while preserving functionality and general structure.

Translation Workflow

Workflow Overview

Figure 1 summarizes the translation workflow. Candidate generation uses the source program and task specification to produce a target program. In parallel, evaluation preparation comprises two blocks. Reference validation checks reference implementations against the tests in versioned native SDK environments. The Evaluation bundle block packages the validated tests and a runtime manifest for subsequent evaluation. The generated program is then executed and checked against this evaluation bundle. Execution results feed into correctness analysis, which distinguishes failures to deliver or execute a candidate from assertion rejections and relates the latter to the properties tested. Aggregate analysis and reporting summarizes these outcomes across tasks, models, and target SDKs (although Q# is a programming language, we use “SDKs” as shorthand for PennyLane and the Q# development environment to improve readability in both the paper and the experimental code).

Figure 1. Workflow for LLM-based quantum code translation.

Within the workflow, prompt construction is central to quantum code translation because it defines the task information and translation constraints provided to the model. The next subsection describes how these prompts are built.

Prompt Construction

Figure 2 illustrates the prompt construction process and prompt content used in our translation experiments. Black text denotes literal prompt fields; blue text denotes general placeholders; italic text provides brief comments for the prompt; and orange text highlights two core prompt components to specify the translation task. Specifically, each prompt comprises <Model_Instructions> for general translation rules and <Task_Input> for the task to be translated. The following four stages describe prompt construction; the example stage applies only to one-shot prompting.

Figure 2. Prompt construction process and content used in the translation experiments.

Settings At the beginning of each translation task, the program reads the following inputs: (1) {task}, containing the task identifier, source entry point, natural-language description, canonical reference implementation, and test assertions; (2) {source}, offering the source code; and (3) {target_name}, identifying the target SDK or language. These inputs are used to construct the <Task_Input> component shown in Figure 2.

Then, the configuration identifies the source SDK or language using {source_name} and assigns the sample identifier {SDKsample_index}. The instruction-prefix provider is specified by {prefix_provider}, while SDK version information is supplied through {sdk_versions = {}}. Because the target environments use different file formats and execution interfaces, the configuration branches on the target: for Q#, it supplies the Q# file extension {extension} and target-specific {runtime_guidance}; for PennyLane, it supplies the corresponding Python file extension and runtime guidance. These branches account for their distinct loading and execution interfaces. The configuration also records the validated source and target implementations in {source_program} and {target_program}, respectively. These SDK identifiers, version constraints, file settings, and runtime instructions are then written as text into the <Model_Instructions> component.

One-shot Example. The one-shot condition includes one verified source–target translation example; the zero-shot condition omits this component. The example shows how common quantum operations are represented in the target SDK or language. It is intentionally simple and does not reproduce the full functionality of an evaluated task; its purpose is to illustrate the translation conventions while limiting overlap with the task being generated.

The example is supplied through {example_block}. It contains a short gate-implementation example, a source program in {source_program}, and its semantically equivalent target implementation in {target_program}. The paired programs could demonstrate how operations, parameters, bit ordering, control and target roles, and register ownership are expressed across SDKs.

Model Instructions. This stage assembles the general translation instructions as text. The {prefix} introduces the task, and the text part describes the translation constraints, including the SDKs, versions, runtime guidance, and output format. The model must return a valid JSON object containing "target_code" for the translated program. We also include six rules for two purposes: Rules 1–5 constrain faithful native execution and assertion-preserving translation, while Rule 6 adds an independent statevector check for eligible circuits.

Task Input. Task input combines the task-specific information initialized during the Settings stage into the <Task_Input> component. It identifies the task and source entry point, specifies the target SDK, and provides the task description, source Qiskit program, and original assertions. Together, these inputs define the concrete translation and its behavioral constraints.

Empirical Study

Research Questions

We propose three research questions (RQs) to investigate zero-shot translation quality across LLMs and target SDKs, the impact of one-shot prompting, and the failure patterns of the translated programs.

RQ1: How does zero-shot quantum code translation performance vary across model configurations and target SDKs?

RQ2: How do correctness and failure profiles differ between zero-shot and one-shot prompts?

RQ3: What are the main failure categories in LLM-based quantum code translation?

Experimental Design

Benchmark. In the absence of a benchmark specifically designed for quantum code translation, we adopt an open-source benchmark from prior work on evaluating LLM-based quantum code generation, whose overall evaluation framework closely aligns with ours. We select QuanBench [9], a recent benchmark of moderate size, for our experiments. Since one canonical reference implementation in QuanBench cannot be reliably reproduced to pass the given assertions, we exclude that task and only use 43 of its 44 original tasks, together with companion tests.

LLMs. We group the evaluated LLM configurations into closed-source and open-weight models. The former group includes GPT-5.6-sol (GPT) [17] configured with medium reasoning effort, while the latter incorporates DeepSeek-V4-Pro (Pro) [3], DeepSeek-V4.1-Flash (Flash) [4], and GLM-5.2 (GLM) [28]. All three open-weight models use a temperature of 0.8 and sample-specific random seeds 42–51. GLM uses high reasoning effort. Pro and Flash use high reasoning effort during planning and disable additional reasoning during final code generation. All other model parameters retain their default configurations.

Prompt construction. We translate Qiskit 1.4.6 programs to PennyLane 0.45.1 and to Q# using Microsoft’s Quantum Development Kit (QDK) 1.32.0. The zero-shot prompt omits One-shot example in Figure 2. For one-shot prompting, we select Pro and GLM, the two configurations with the lowest overall zero-shot performance across the target SDKs (§ 4.3). Their one-shot prompts include one verified source–target translation example for the target SDK. In detail, we select a basic task from Qolumbina [13], a recent benchmark infrastructure of scalable quantum programs, and manually implement semantically equivalent three-qubit programs for this task in Qiskit, PennyLane, and Q#; this choice is intended to reduce the risk of data leakage. We choose simple examples that do not duplicate the full functionality of any evaluated task, and these examples cover reversible comparisons, conditional bit flips, and phase marking.

Evaluation metrics. (1) Effectiveness: Following QuanBench [9], we use Pass@k to measure the task-macro correctness of the translated programs, where a single task succeeds if it passes all assertions provided by QuanBench. For each task, we have ntn_t sample slots (planned translation attempts), among which ctc_t are successful. Let T\mathcal{T} be the set of retained tasks. The metric is defined as Pass@k =1∣T∣∑t∈T[1−(nt−ctk)(ntk)]= \frac{1}{\lvert\mathcal{T}\rvert}\sum_{t\in\mathcal{T}}\left[1-\frac{\binom{n_t-c_t}{k}}{\binom{n_t}{k}}\right]. In our experiments, we evaluate k∈{1,3}k\in\{1,3\} using nt=10n_t=10 sample slots for each model–task–target combination. (2) Cost: We also record the average runtime and output token count per API response to measure the cost of translation.

Empirical Results

RQ1 Across the evaluated zero-shot model–target pairs in Table 1, Pass@1 ranges from 16.28% to 72.33%, indicating substantial variation in translation success: Flash achieves the highest score on PennyLane, while Pro has the lowest on Q#. The ranking also depends on the target SDK: Flash leads on PennyLane, whereas GPT leads on Q#. Target effects vary by model as well: GPT performs better on Q# than on PennyLane, while GLM, Pro, and Flash perform better on PennyLane. In addition, Pass@3 exceeds Pass@1 for every model–target pair, showing that multi-sample evaluation can find passing candidates missed by a single sample. These results suggest that translation performance should be compared for each model and target SDK rather than summarized by a single overall model ranking. Means pool responses with complete telemetry across both targets, including unsuccessful attempts; output tokens cover planning and final generation. Flash has the shortest mean runtime (92.00 s), while GPT uses the fewest output tokens (2,758). These models also lead in correctness on PennyLane and Q#, respectively, suggesting that longer generation or greater token use does not necessarily imply higher correctness.

ModelQiskit → PennyLaneQiskit → Q#Mean per API response
Pass@1Pass@3Pass@1Pass@3Runtime (s)Output tokens
GPT51.6361.3671.6382.11149.842,758
GLM49.3065.4322.5648.97148.309,527
Pro55.8173.2616.2837.71108.177,426
Flash72.3386.5344.8865.1992.008,541

Table 1. Zero-shot task-macro Pass@1/Pass@3 (%) over 43 tasks, with mean generation runtime and output-token use.

RQ2 We compare Pro and GLM under the zero-shot and one-shot prompt conditions defined in § 4.2, using the same task scope and native evaluation bundle. Figure 3 shows that one-shot prompts improve Pass@1 and Pass@3 for both models and target SDKs. GLM gains 10.93–18.37 percentage points in Pass@1, compared with 7.67–8.14 for Pro. The gains are more pronounced for GLM, particularly on PennyLane, while Pro improves to a similar extent on PennyLane and Q#. On PennyLane, GLM overtakes Pro under both metrics, showing that model rankings can change with prompt conditions. Paired examples may help convey SDK-specific mappings and conventions, although this mechanism remains unverified.

Bar chart comparing zero-shot and one-shot Pass@1 and Pass@3 for Pro-PL, Pro-QS, GLM-PL, and GLM-QS

Figure 3. Zero-shot versus one-shot prompts over the same 43 tasks. PL: PennyLane; QS: Q#.

RQ3 We evaluate 4 LLM configurations on 2 target SDKs and 43 tasks, with 10 sample slots per combination, yielding 4×2×43×10=3,4404 \times2 \times43 \times10 = 3{,}440 zero-shot sample slots. Among these, 1,653 pass and 1,787 fail (Table 2). Table 2 reports mutually exclusive failure categories, their criteria, counts, and within-column failure percentages for all zero-shot models and the Pro + GLM prompt comparison. Scripts automatically classify failed samples using generation and evaluation statuses and tracebacks. Missing source (700) and SDK compilation (624) dominate, identifying artifact delivery and compilation as the main observed barriers. Other categories indicate execution or interface problems without establishing algorithmic incorrectness.

Failure categoryCriterionZero-shotPro + GLM One-shotPro + GLM Zero-shot
Missing sourceNo source artifact700 (39.2%)333 (36.7%)492 (44.7%)
SDK compilationTarget code not compilable624 (34.9%)349 (38.5%)407 (37.0%)
Assertion rejectionTest assertion violated160 (9.0%)81 (8.9%)53 (4.8%)
Candidate executionLoad, API, or runtime failure143 (8.0%)98 (10.8%)79 (7.2%)
SDK incompatibilityInterface/dependency-related traceback160 (9.0%)46 (5.1%)70 (6.4%)
TotalAll failed samples1,787 (100.0%)907 (100.0%)1,101 (100.0%)

Table 2. Failure categories under zero-shot and one-shot prompting

For Pro and GLM across both targets, failed samples decrease from 1,101 under zero-shot prompting to 907 with one-shot prompting. Missing source, SDK compilation, and SDK incompatibility decrease, while assertion rejection and candidate execution increase. SDK compilation becomes the largest one-shot category (38.5%), while missing source dominates under zero-shot prompting (44.7%).

Conclusion and Future Work

Our study presents an initial proposal and a pilot evaluation of LLM-based quantum code translation, with four LLM configurations, two translation targets (PennyLane and Q#), 43 benchmark tasks, and a comparison between zero-shot and one-shot prompts. The results show substantial variation in translation quality across the evaluated LLM configurations and target SDKs, with zero-shot Pass@1 ranging from 16.28% to 72.33%. The most common failure category is missing source, followed by SDK compilation.

In future work, we plan to build a dedicated cross-SDK translation benchmark by integrating existing quantum programs, including scalable programs such as Qolumbina [13], with paired source–target implementations and executable tests across SDKs and program sizes. We will also develop translation-specific metrics and assertions for semantic preservation and required structural consistency, drawing on quantum software testing [14]. These checks will cover relative phase, bit ordering, and probabilistic outputs to complement output-based evaluation. Finally, we will conduct broader empirical studies of prompting strategies and explore execution-guided repair while assessing translation quality and cost.

Data Availability

The source code, experimental artifacts, and reproduction instructions are available in an anonymized repository.2

References

  1. [1]Basit, A., Shao, M., Asif, M.H., Innan, N., Kashif, M., Marchisio, A., Shafique, M.: PennyCoder: Efficient domain-specific LLMs for PennyLane-based quantum code generation. In: Proc. IEEE Int. Conf. Quantum Computing and Engineering (QCE), vol. 2, pp. 229–234 (2025). https://doi.org/10.1109/QCE65121.2025.10324
  2. [2]Chen, X., Xue, J., Xie, X., Liang, C., Ju, X.: A systematic literature review on neural code translation. arXiv preprint arXiv:2505.07425 (2025)arxiv.org/abs/2505.07425
  3. [3]DeepSeek: DeepSeek-V4-Pro GA Release notes, Aug. 13 (2026), https://api-docs.deepseek.com/news/news260813/, accessed: Oct. 22, 2026
  4. [4]DeepSeek: DeepSeek-V4.1-Flash: Smarter, faster, more efficient. Official release notes, Sept. 10 (2026), https://api-docs.deepseek.com/news/news260910/, accessed: Oct. 22, 2026
  5. [5]Dupuis, N., Buratti, L., Vishwakarma, S., Forrat, A.V., Kremer, D., Faro, I., Puri, R., Cruz-Benito, J.: Qiskit Code Assistant: Training LLMs for generating quantum computing code. arXiv:2405.19495 (2024)arxiv.org/abs/2405.19495
  6. [6]Fu, Z., Jiang, L., Xu, Y., Huang, G., Chen, F.: QAgent: An LLM-based multi-agent system for autonomous OpenQASM programming. arXiv preprint arXiv:2508.20134 (2025)arxiv.org/abs/2508.20134
  7. [7]Guo, X., Saito, S., Zhao, J.: M2QCode: A model-driven framework for generating multi-platform quantum programs. In: Proc. IEEE/ACM Int. Conf. Automated Software Engineering (ASE), pp. 3639–3649 (2025)arxiv.org/abs/2510.17110
  8. [8]Guo, X., Saito, S., Zhao, J.: QuanUML: Towards a modeling language for model-driven quantum software development. In: Proc. IEEE Annu. Computers, Software, and Applications Conf. (COMPSAC). pp. 1344–1349 (2025)arxiv.org/abs/2506.04639
  9. [9]Guo, X., Wang, M., Zhao, J.: QuanBench: Benchmarking quantum code generation with large language models. In: Proc. IEEE/ACM Int. Conf. Automated Software Engineering (ASE). pp. 2657–2669 (2025). https://doi.org/10.1109/ASE63991.2025.00218
  10. [10]IBM Quantum: Qiskit SDK API Documentation. Official documentation, https://quantum.cloud.ibm.com/docs/en/api/qiskit/index, accessed: Oct. 23, 2026
  11. [11]Ibrahimzada, A.R., Ke, K., Pawagi, M., Abid, M.S., Pan, R., Sinha, S., Jabbarvand, R.: AlphaTrans: A neuro-symbolic compositional approach for repository-level code translation and validation. Proc. ACM Softw. Eng. 2(FSE) (2025). https://doi.org/10.1145/3729379, art. FSE109
  12. [12]Jiang, C., Liu, D., Wen, C., Xu, Z., Zheng, H., Sadiq, M., Shamsi, J.A., Qin, S., Ming, Z.: Large language models for multilingual code intelligence: A survey. arXiv preprint arXiv:2604.25960 (2026)arxiv.org/abs/2604.25960
  13. [13]Li, Y., Shao, M., Li, X., Zhao, J., Cai, K.Y.: Benchmarking quantum software testing with scalable quantum programs. arXiv:2607.02029 (2026). https://doi.org/10.48550/arXiv.2607.02029
  14. [14]Li, Y., Shao, M., Zhao, J., Wang, Q.: A methodological analysis of empirical studies in quantum software testing. ACM Transactions on Software Engineering and Methodology (2026). https://doi.org/10.1145/3819590, doi: 10.1145/3819590
  15. [15]Macedo, M., Tian, Y., Nie, P., Cogo, F.R., Adams, B.: InterTrans: Leveraging transitive intermediate translations to enhance LLM-based code translation. In: Proc. IEEE/ACM Int. Conf. Software Engineering (ICSE) (2025). https://doi.org/10.1109/ICSE55347.2025.00236
  16. [16]Microsoft: Introduction to the quantum programming language Q#. Official documentation (2026), https://learn.microsoft.com/en-us/azure/quantum/qsharp-overview, accessed: Oct. 23, 2026
  17. [17]OpenAI: GPT-5.6 Sol Model. Official model documentation (2026), https://developers.openai.com/api/docs/models/gpt-5.6-sol, accessed: Oct. 22, 2026
  18. [18]Pan, R., Ibrahimzada, A.R., Krishna, R., Sankar, D., Wassi, L.P., Merler, M., Sobolev, B., Pavuluri, R., Sinha, S., Jabbarvand, R.: Lost in translation: A study of bugs introduced by large language models while translating code. In: Proc. IEEE/ACM Int. Conf. Software Engineering (ICSE) (2024). https://doi.org/10.1145/3597503.3639226
  19. [19]Shin, S.Y., Pastore, F., Bianciulli, D.: Quantum program linting with LLMs: Emerging results from a comparative study. In: Proc. IEEE Int. Conf. Quantum Computing and Engineering (QCE). vol. 2, pp. 181–186 (2025)arxiv.org/abs/2504.05204
  20. [20]Siavash, N., Moin, A.: LLM-powered quantum code transpilation. In: Proc. IEEE Int. Conf. Quantum Computing and Engineering (QCE). vol. 2, pp. 410–411 (2025)
  21. [21]Slim, A., Hamieh, H., Kotaich, J., Ghosn, Y., Chehimi, M., Mohanna, A., Hammoud, H.A.A.K., Ghanem, B.: QuanBench+: A unified multi-framework benchmark for LLM-based quantum code generation. arXiv:2604.08570 (2026), ICLR Workshop on I Can’t Believe It’s Not Betterarxiv.org/abs/2604.08570
  22. [22]Suárez, J.M., Bibbó, L.M., Bogado, J., Fernandez, A.: Automatic Qiskit code refactoring using large language models. In: Proc. IEEE CHILEAN Conf. Electrical, Electronics Engineering, Information and Communication Technologies (CHILE-CON). pp. 1–8 (2025)arxiv.org/abs/2506.14535
  23. [23]Tao, M., Li, Y., Yue, T., Zhang, M., Arrieta Marcos, A.: Leveraging LLM-based agentic systems to generate quantum applications for test optimization. arXiv preprint arXiv:2607.00939 (2026)arxiv.org/abs/2607.00939
  24. [24]Wesley, S.: LinguaQuanta: Towards a quantum transpiler between OpenQASM and Quipper. In: Reversible Computation. pp. 142–160 (2024). https://doi.org/10.1007/978-3-031-62076-8_10
  25. [25]Xanadu: PennyLane Documentation. Official documentation, https://docs.pennylane.ai/en/stable/, accessed: Oct. 23, 2026
  26. [26]Yang, Z., Liu, F., Yu, Z., Keung, J.W., Li, J., Liu, S., Hong, Y., Ma, X., Jin, Z., Li, G.: Exploring and unleashing the power of large language models in automated code translation. Proc. ACM Softw. Eng. 1(FSE), 1585–1608 (2024). https://doi.org/10.1145/3660778
  27. [27]Yu, X., Li, Y., Wen, J., Cai, K.Y., Yin, B.: QuAInth: A code comment approach for application-oriented quantum programs via N-version LLMs. In: Proc. IEEE Int. Conf. Software Quality, Reliability and Security (QRS). pp. 13–24 (2025)DOI
  28. [28]Z.ai: GLM-5.2. Official model documentation (2026), https://docs.z.ai/guides/llm/glm-5.2, accessed: Oct. 22, 2026

Paper details

vlnc:W_q8uxw4ye
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

Not recorded for this paper

View statement
Looking for related papers…
Contents