Q-Bridge: Code Translation for Quantum Machine Learning via LLMs

Runjia Zeng, Priyabrata Senapati, Ruixiang Tang, Dongfang Liu, Qiang GuanarXiv 2026

TL;DR

Q-Bridge is the first reproducible framework designed to automatically translate classical machine learning (CML) code into executable quantum machine learning (QML) variants. By leveraging a self-evolving pipeline to generate a large-scale paired dataset (CML-2-QML) and fine-tuning an LLM using low-rank adaptation (LoRA), Q-Bridge bridges the steep programming gap between classical and quantum AI paradigms.

What Problem Does This Paper Address?

Quantum Machine Learning (QML) holds immense theoretical promise, but classical machine learning practitioners face a massive barrier to entry. Programming quantum hardware requires specialized knowledge of reversible logic, complex measurement semantics, and hardware-specific constraints.

While Large Language Models (LLMs) excel at standard code generation, they struggle with QML due to a severe lack of high-quality, standardized datasets and robust translation frameworks. Currently, there is no automated way to reliably port a classical pipeline (like a PyTorch or scikit-learn model) into an equivalent, runnable quantum circuit. Q-Bridge addresses this gap by automating the translation from CML to QML.

Fig. 1. Classical to quantum translation pipeline that includes (a) conventional ML code is provided as an input, (b) a LLM interprets the classical ML code and synthesizes an equivalent quantum ML specification, (c) the generated design is instantiated as a parameterized quantum circuit encoder plus variational blocks with single qubit rotations, ZZ entanglers, and measurements ansatz [43].

Methods

The authors introduce Q-Bridge, an LLM-guided code translation framework that operates via a three-stage pipeline:

  1. Seed Codebase Foundation: The process starts with a high-quality, human-curated seed codebase containing both verifiable Qiskit code and diverse unverified quantum code collected from open-source repositories.
  2. Dataset Scaling (Self-Involvement): To expand this small seed, the authors use a "self-involving" pipeline. An LLM (specifically gpt-oss-20b) uses targeted prompts to scale up the codebase through two paradigms: extension (deepening code capabilities) and controlled modification (introducing deliberate structural variations).
  3. Instruction Tuning: The resulting large-scale dataset, CML-2-QML, is used to fine-tune a base LLM via supervised low-rank adaptation (LoRA). This ensures memory-efficient training while aligning the syntactic and semantic structures of classical and quantum code.

The final fine-tuned Q-Bridge model takes classical code as an input, automatically determines an appropriate QML paradigm, generates candidate encodings/ansatz topologies, and outputs executable QML code (supporting Qiskit or PennyLane).

Fig. 2. The building of Q-Bridge. It begins with ❶establishing a robust seed codebase to form a reliable high-quality prototype, followed by ❷employing LLMs to expand and refine the dataset, and finally ❸training LLMs on the CML-2-QML dataset to obtain Q-Bridge model. Finally, we outline potential future directions of our work.

Datasets

The primary data contribution of this paper is the CML-2-QML Dataset, which represents the first large-scale, high-quality collection of paired CML and QML code:

  • Verified Subset: Contains 114 ansatze and 101 feature maps paired with evaluation tools to ensure functional correctness.
  • Unverified Subset: A high-diversity corpus of 6,765 pairs spanning 18 representative model architectures (e.g., Quantum Autoencoders, QLSTM, QCNN, and Quantum Transformers) across multiple frameworks like PennyLane, Qiskit, and TorchQuantum.

For downstream functional evaluation, the translated models were tested on five standard datasets: Iris-Regression-3f, Diabetes-10f, CaliforniaHousing-8f, Synthetic-4f, and Synthetic-6f.

Key Insights and Ideas

  • Structural Alignment: The paper demonstrates that direct CML-to-QML translation is fundamentally viable because the two paradigms share deep structural parallels. Deep learning abstractions (layers, losses, optimizers) map cleanly to quantum analogues (parameterized unitaries, measurement statistics, classical optimizers).
  • The Role of Temperature Control: By adjusting the LLM's generation temperature, Q-Bridge can balance deterministic correctness with creative exploration. Low temperatures (e.g., 0.1) yield highly faithful, strict translations of the classical architecture, while higher temperatures (e.g., 0.6) allow the model to experiment with novel quantum circuit configurations and alternative entangling layers.
  • Modular Reuse Over Independent Growth: Statistical analysis of the generated dataset revealed that the combination paradigm heavily dominated over simple extension. This indicates that effective quantum code variants are best built by compositionally reusing established classical foundations rather than inventing entirely new structures from scratch.

Key Results

The authors evaluated Q-Bridge against powerful baselines, including GPT-5-Thinking, GPT-OSS-20B, and Qwen3-1.7B, using four criteria: architectural fidelity, quantum-native design, executability, and alignment.

  • Superior Code Generation: Q-Bridge variants consistently outperformed general-purpose LLMs. For instance, while GPT-5-Thinking generated overly rigid observable setups and Qwen3-1.7B failed to produce runnable code entirely, the Q-Bridge-0.6 variant successfully factored pipelines into clean feature encodings, variational layers, and direct probability readouts using standard Qiskit/PennyLane tooling.
  • Functional Performance: When evaluating classification on the Iris-Regression-3f dataset, the Q-Bridge-translated QML model achieved an accuracy of 0.380, slightly outperforming the classical neural network baseline (0.340). More importantly, the QML model distributed predictions more evenly across classes, showing potential advantages in mitigating class bias.

Limitations and Future Work

Despite its success, the authors note several challenges that set the stage for future research:

  • API Instability: Unlike mature classical frameworks like PyTorch, QML libraries (like Qiskit) evolve rapidly, frequently introducing breaking changes. The authors plan to use Parameter-Efficient Fine-Tuning (PEFT) to help the model incrementally adapt to new API versions without full retraining.
  • Deployment Efficiency: The current Q-Bridge model is computationally heavy. Future work will focus on knowledge distillation to compress the model into lightweight student variants (like Llama-3.2-1B) and low-bit quantization (4-bit/8-bit) to allow deployment in resource-constrained environments or edge devices.

Summary updated

BibTeX
@misc{zeng2026q,
  author = {Runjia Zeng and Priyabrata Senapati and Ruixiang Tang and Dongfang Liu and Qiang Guan},
  title = {{Q-Bridge: Code Translation for Quantum Machine Learning via LLMs}},
  year = {2026},
  eprint = {2603.27836},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2603.27836},
}
Figure