Lewati ke konten utama

Qiskit Code Assistant

LLM Qiskit Code Assistant bertujuan membuat komputasi kuantum lebih mudah diakses oleh pengguna Qiskit baru dan meningkatkan pengalaman coding bagi pengguna saat ini. Asisten ini dilatih menggunakan jutaan token teks dari Qiskit SDK, bertahun-tahun contoh kode Qiskit, dan fitur-fitur IBM Quantum®. Qiskit Code Assistant bisa membantu alur kerja pengembangan kuantummu dengan menawarkan saran yang dihasilkan LLM berdasarkan model IBM Granite dan model open-source lainnya, yang mencakup fitur dan fungsionalitas terbaru dari IBM®.

Catatan

Large Language Model (LLM) di balik Qiskit Code Assistant

Untuk memberikan saran kode, Qiskit Code Assistant menggunakan Large Language Model (LLM). Dalam hal ini, Qiskit Code Assistant saat ini mengandalkan model mistral-small-3.2-24b-qiskit, yang dibangun di atas model Mistral-Small-3.2-24B-Qiskit. Model mistral-small-3.2-24b-qiskit meningkatkan kemampuan pembuatan kode model Mistral-Small-3.2-24B-Instruct-2506 untuk Qiskit melalui pelatihan tambahan yang diperluas dan fine-tuning pada data Qiskit berkualitas tinggi, serta commit Python dan chat. Untuk informasi lebih lanjut tentang keluarga model Mistral AI, lihat dokumentasi Mistral AI. Untuk detail lebih lanjut tentang model .*-qiskit, lihat Qiskit Code Assistant: Training LLMs for generating Quantum Computing Code.

LLM yang kami khususkan untuk Qiskit juga tersedia sebagai model open-source. Lihat semua model yang tersedia di https://huggingface.co/Qiskit.

Benchmark Qiskit HumanEval dan Qiskit HumanEval Hard

Untuk menguji mistral-small-3.2-24b-qiskit dan model lainnya, kami berkolaborasi dengan Qiskit Advocates dan para ahli untuk membuat benchmark berbasis eksekusi yang disebut Qiskit HumanEval (QHE) dan Qiskit HumanEval Hard (QHE Hard), lalu menjalankannya pada model-model tersebut. Benchmark ini mirip dengan HumanEval, mencakup berbagai masalah kode yang menantang untuk diselesaikan, semuanya berbasis library Qiskit resmi.

Benchmark ini terdiri dari sekitar 150 tes, masing-masing dibuat dari definisi fungsi, diikuti oleh docstring yang merinci tugas yang harus diselesaikan model. Setiap contoh juga mencakup solusi kanonik referensi, serta unit test, untuk mengevaluasi kebenaran solusi yang dihasilkan. Ada tiga tingkat kesulitan tes: dasar, menengah, dan sulit. Benchmark Qiskit HumanEval Hard adalah variasi dari Qiskit HumanEval, tetapi menghapus informasi terkait impor kode, sehingga LLM perlu mencari tahu impor metode atau kelas yang tepat. Perubahan ini membuat dataset jauh lebih menantang bagi LLM, menurut pengujian dan hasil awal kami.

Dataset untuk Qiskit HumanEval dan Qiskit HumanEval Hard tersedia di situs-situs ini: Qiskit HumanEval dan Qiskit HumanEval. Kamu bisa berkontribusi pada pengembangan benchmark ini di repositori GitHub.

Instal Qiskit Code Assistant

Pelajari cara menginstal, mengonfigurasi, dan menggunakan model Qiskit Code Assistant mana pun di mesin lokalmu.

Unduh dari situs web Hugging Face

Ikuti langkah-langkah ini untuk mengunduh model terkait Qiskit Code Assistant mana pun dari situs web Hugging Face:

  1. Buka halaman model Qiskit yang diinginkan di Hugging Face.
  2. Buka tab Files and Versions dan unduh file model safetensors atau GGUF.
Unduh menggunakan Hugging Face CLI

Untuk mengunduh model Qiskit Code Assistant yang tersedia menggunakan Hugging Face CLI, ikuti langkah-langkah ini:

  1. Instal Hugging Face CLI

  2. Login ke akun Hugging Face-mu

    huggingface-cli login
  3. Unduh model yang kamu suka dari daftar sebelumnya

    huggingface-cli download <HF REPO NAME> <MODEL PATH> --local-dir <LOCAL PATH>
Deploy model Qiskit Code Assistant secara lokal melalui Ollama secara manual

Ada banyak cara untuk men-deploy dan berinteraksi dengan model Qiskit Code Assistant yang sudah diunduh. Panduan ini mendemonstrasikan penggunaan Ollama sebagai berikut: baik dengan aplikasi Ollama menggunakan integrasi Hugging Face Hub atau model lokal, maupun dengan paket llama-cpp-python.

Menggunakan aplikasi Ollama

Aplikasi Ollama menyediakan solusi sederhana untuk menjalankan LLM secara lokal. Aplikasi ini mudah digunakan, dengan CLI yang membuat seluruh proses setup, manajemen model, dan interaksi cukup mudah. Ini ideal untuk eksperimen cepat dan untuk pengguna yang ingin menangani lebih sedikit detail teknis.

Instal Ollama
  1. Unduh aplikasi Ollama

  2. Instal file yang telah diunduh

  3. Luncurkan aplikasi Ollama yang sudah terinstal

    info

    Aplikasi berjalan dengan sukses ketika ikon Ollama muncul di menu bar desktop. Kamu juga bisa memverifikasi layanan berjalan dengan membuka http://localhost:11434/.

  4. Coba Ollama di terminalmu dan mulai menjalankan model. Misalnya:

    ollama run hf.co/Qiskit/Qwen2.5-Coder-14B-Qiskit
Menyiapkan Ollama menggunakan integrasi Hugging Face Hub

Integrasi Ollama/Hugging Face Hub menyediakan cara untuk berinteraksi dengan model yang di-host di Hugging Face Hub tanpa perlu membuat modelfile baru atau mengunduh file GGUF atau safetensors secara manual. File template dan params default sudah disertakan untuk model di Hugging Face Hub.

  1. Pastikan aplikasi Ollama sedang berjalan.

  2. Buka halaman model yang diinginkan, dan salin URL-nya. Misalnya, https://huggingface.co/Qiskit/Qwen2.5-Coder-14B-Qiskit-GGUF.

  3. Dari terminalmu, jalankan perintah:

    ollama run hf.co/Qiskit/Qwen2.5-Coder-14B-Qiskit

Kamu bisa menggunakan model hf.co/Qiskit/Qwen2.5-Coder-14B-Qiskit atau salah satu model GGUF resmi lainnya yang saat ini direkomendasikan hf.co/Qiskit/mistral-small-3.2-24b-qiskit-GGUF atau hf.co/Qiskit/granite-3.3-8b-qiskit-GGUF.

Menyiapkan Ollama dengan model GGUF Qiskit Code Assistant yang diunduh secara manual

Kalau kamu sudah mengunduh model GGUF secara manual seperti https://huggingface.co/Qiskit/Qwen2.5-Coder-14B-Qiskit-GGUF dan kamu ingin bereksperimen dengan template dan parameter yang berbeda, kamu bisa mengikuti langkah-langkah ini untuk memuatnya ke aplikasi Ollama lokalmu.

  1. Buat sebuah Modelfile dengan memasukkan konten berikut dan pastikan memperbarui <PATH-TO-GGUF-FILE> ke path sebenarnya dari model yang kamu unduh.

    FROM <PATH-TO-GGUF-FILE>
    TEMPLATE """{{ if .System }}
    System:
    {{ .System }}

    {{ end }}{{ if .Prompt }}Question:
    {{ .Prompt }}

    {{ end }}Answer:
    ```python{{ .Response }}
    """

    PARAMETER stop "Question:"
    PARAMETER stop "Answer:"
    PARAMETER stop "System:"
    PARAMETER stop "```"

    PARAMETER temperature 0
    PARAMETER top_k 1
  2. Run the following command to create a custom model instance based on the Modelfile.

    ollama create Qwen2.5-Coder-14B-Qiskit -f ./path-to-model-file
    catatan

    This process may take some time for Ollama to read the model file, initialize the model instance, and configure it according to the specifications provided.

Run the Qiskit Code Assistant model manually downloaded in Ollama

After the Qwen2.5-Coder-14B-Qiskit model has been set up in Ollama, run the following command to launch the model and interact with it in the terminal (in chat mode).

ollama run Qwen2.5-Coder-14B-Qiskit

Some useful commands:

  • ollama list - List models on your computer
  • ollama rm Qwen2.5-Coder-14B-Qiskit - Delete the model
  • ollama show Qwen2.5-Coder-14B-Qiskit - Show model information
  • ollama stop Qwen2.5-Coder-14B-Qiskit - Stop a model that is currently running
  • ollama ps - List which models are currently loaded
Manually deploy the Qiskit Code Assistant models in local through the llama-cpp-python package

An alternative to the Ollama application is the llama-cpp-python package, which is a Python binding for llama.cpp. It gives you more control and flexibility to run the GGUF model locally, and is ideal for users who wish to integrate the local model in their workflows and Python applications.

  1. Install llama-cpp-python
  2. Interact with the model from within your application using llama_cpp. For example:
from llama_cpp import Llama

model_path = <PATH-TO-GGUF-FILE>

model = Llama(
model_path,
seed=17,
n_ctx=10000,
n_gpu_layers=37, # to offload in gpu, but put 0 if all in cpu
)

input = 'Generate a quantum circuit with 2 qubits'
raw_pred = model(input)["choices"][0]["text"]

You can also add text generation parameters to the model to customize the inference:

generation_kwargs = {
"max_tokens": 512,
"echo": False, # Echo the prompt in the output
"top_k": 1
}

raw_pred = model(input, **generation_kwargs)["choices"][0]["text"]
Manually deploy the Qiskit Code Assistant models in local through llama.cpp

Use the llama.cpp library

Another alternative is to use llama.cpp, an open-source library for performing LLM inference on a CPU with minimal setup. It provides low-level control over the model execution and is typically run from the command line, pointing to a local GGUF model file.

There are several ways to install llama.cpp on your machine:

Once installed, you can use llama.cpp to interact with GGUF models in conversation mode as follows:

# Use a local model file
llama-cli -m my_model.gguf -cnv

# Or download and run a model directly from Hugging Face
llama-cli -hf Qiskit/Qwen2.5-Coder-14B-Qiskit-GGUF -cnv

You can also launch an OpenAI-compatible API server for the model in the following way:

llama-server -hf Qiskit/Qwen2.5-Coder-14B-Qiskit-GGUF
Advanced parameters

With the llama-cli program, you can control the model generation using command-line options. For example, you can provide an initial “system” prompt using the -p/--prompt flag. In conversation mode (-cnv), this initial prompt acts as the system message. Otherwise, you can simply prepend any desired instruction to your prompt text. You can also adjust sampling parameters - for instance: temperature (--temp), top-k (--top-k), top-p (--top-p), repetition penalty (--repeat-penalty), and the seed to use (--seed). The following is an example invocation using these options:

llama-cli -hf Qiskit/Qwen2.5-Coder-14B-Qiskit-GGUF \
-p "You are a friendly assistant." -cnv \
--temp 0.7 \
--top-k 50 \
--top-p 0.95 \
--repeat-penalty 1.1 \
--seed 42

To ensure proper functionality of our Qiskit models, we recommend using the system prompt provided in our HF GGUF repositories: system prompt for mistral-small-3.2-24b-qiskit-GGUF, Qwen2.5-Coder-14B-Qiskit-GGUF, granite-3.3-8b-qiskit-GGUF, and granite-3.2-8b-qiskit-GGUF.

Manually connect Continue (VS Code)

Continue (VS Code)

1. Install the extension

Open VS Code, go to Extensions (Cmd+Shift+X), search Continue, install it.

2. Open the config

Click the Continue icon in the sidebar, then click the gear icon, or open the command palette (Cmd+Shift+P) and run Continue: Open Config File.

This opens ~/.continue/config.yaml (or config.json in older versions).

3. Configure the model

Add the following to config.yaml:

models:
- name: Qiskit Code Assistant
provider: ollama
model: mistral-small-3.2-24b-qiskit
apiBase: http://localhost:11434

This makes the Qiskit model available in the chat panel (sidebar conversations, inline Q&A) and for inline edit commands.

4. Test it
  • Chat: Open the Continue panel in the sidebar and ask a question (e.g., "How do I create a parameterized circuit in Qiskit?")
  • Inline edit: Select a block of code, press Cmd+I (Mac) or Ctrl+I (Linux/Windows)
Manually connect Jupyter AI (JupyterLab)

Jupyter AI (JupyterLab)

Note: These instructions cover Jupyter AI v2.x.

1. Install Jupyter AI and the Ollama provider
pip install "jupyter-ai<3" langchain-ollama

The "jupyter-ai<3" pin ensures you get v2.x. The langchain-ollama package is required for Jupyter AI to detect Ollama as a provider. Without it, Ollama will not appear in the settings panel.

Then restart JupyterLab.

2. Configure the chat model

Open JupyterLab and click the chat icon in the left sidebar. In the settings panel:

  1. Under Language model, select Ollama as the provider.
  2. Enter mistral-small-3.2-24b-qiskit as the model name.
  3. No API key is needed for Ollama (leave the field empty).
  4. Click the back arrow to start chatting.
3. Use the %%ai magic command

The %%ai magic lets you query the model directly in notebook cells.

%load_ext jupyter_ai_magics

Then in a cell:

%%ai ollama:mistral-small-3.2-24b-qiskit
Write a function that implements Grover's algorithm using Qiskit
4. Custom Ollama host (optional)

By default, Jupyter AI connects to http://127.0.0.1:11434. If your Ollama server runs on a different address or port:

In the chat UI: Set the "Base API URL" field in the AI settings panel.

Manually connect OpenCode (Terminal)

OpenCode (Terminal)

1. Install OpenCode
curl -fsSL https://opencode.ai/install | bash
2. Configure the Qiskit model

Create an opencode.json file in your project root (or ~/.config/opencode/opencode.json for a global config):

{
"$schema": "https://opencode.ai/config.json",
"provider": {
"ollama": {
"npm": "@ai-sdk/openai-compatible",
"name": "Ollama (local)",
"options": {
"baseURL": "http://localhost:11434/v1"
},
"models": {
"mistral-small-3.2-24b-qiskit": {
"name": "Qiskit Code Assistant"
}
}
}
}
}
3. Select the model

Launch OpenCode in your project directory:

opencode

Inside the TUI, run the /models command and select Qiskit Code Assistant from the list.

4. Test it

Ask a question directly in the chat, for example: "Define a Bell circuit and run it using QiskitRuntimeService"

Available models

Current models

These are the latest recommended models for use with Qiskit Code Assistant:

  1. Qiskit/mistral-small-3.2-24b-qiskit - Released October 2025
  2. Qiskit/Qwen2.5-Coder-14B-Qiskit - Released June 2025
  3. qiskit/granite-3.3-8b-qiskit - Released June 2025
  4. qiskit/granite-3.2-8b-qiskit - Released June 2025

GGUF format models are optimized for local use and require fewer computational resources:

  1. mistral-small-3.2-24b-qiskit-GGUF – Released October 2025
    Trained with Qiskit data up to version 2.1

  2. Qiskit/Qwen2.5-Coder-14B-Qiskit-GGUF – Released June 2025
    Trained with Qiskit data up to version 2.0

  3. qiskit/granite-3.3-8b-qiskit-GGUF – Released June 2025
    Trained with Qiskit data up to version 2.0

  4. qiskit/granite-3.2-8b-qiskit-GGUF – Released June 2025
    Trained with Qiskit data up to version 2.0

The Open Source Qiskit Code Assistant models are available in safetensors or GGUF file format and can be downloaded from the Hugging Face as explained below.

Qiskit versions used for training

Model     Benchmark Metrics    Release dateTrained on Qiskit version
 QiskitHumanEval-HardQiskitHumanEvalHumanEvalASDivMathQASciQMBPPIFEvalCrowsPairs (English)TruthfulQA (MC1 acc)  
mistral-small-3.2-24b-qiskit32.4547.0277.493.7749.6897.5064.0048.4467.0839.41January 20262.2
Qwen2.5-Coder-14B-Qiskit25.1749.0191.464.2153.9097.0077.6049.6465.1837.82June 20252.0
granite-3.3-8b-qiskit14.5727.1562.800.4838.6693.3052.4059.7159.7539.05June 20252.0
granite-3.2-8b-qiskit9.9324.5057.320.0941.4196.3051.8060.7966.7940.51June 20252.0
granite-8b-qiskit-rc-0.1015.8938.4159.76February 20251.3
granite-8b-qiskit17.8844.3753.66November 20241.2

Note: All models listed in the benchmark table were evaluated using their respective system prompt, defined in their Hugging Face model.

Deprecated models

These models are no longer actively maintained but remain available:

  1. qiskit/granite-8b-qiskit-rc-0.10 - Released February 2025 (deprecated)
  2. qiskit/granite-8b-qiskit - Released November 2024 (deprecated)

More information and citations

To learn more about Qiskit Code Assistant, the Qiskit HumanEval, or Qiskit HumanEval Hard benchmarks, and cite them in your scientific publications, review these recommended citations:

@misc{2405.19495,
Author = {Nicolas Dupuis and Luca Buratti and Sanjay Vishwakarma and Aitana Viudes Forrat and David Kremer and Ismael Faro and Ruchir Puri and Juan Cruz-Benito},
Title = {Qiskit Code Assistant: Training LLMs for generating Quantum Computing Code},
Year = {2024},
Eprint = {arXiv:2405.19495},
}
@misc{2406.14712,
Author = {Sanjay Vishwakarma and Francis Harkins and Siddharth Golecha and Vishal Sharathchandra Bajpe and Nicolas Dupuis and Luca Buratti and David Kremer and Ismael Faro and Ruchir Puri and Juan Cruz-Benito},
Title = {Qiskit HumanEval: An Evaluation Benchmark For Quantum Code Generative Models},
Year = {2024},
Eprint = {arXiv:2406.14712},
}
@misc{2508.20907,
Author = {Nicolas Dupuis and Adarsh Tiwari and Youssef Mroueh and David Kremer and Ismael Faro and Juan Cruz-Benito},
Title = {Quantum Verifiable Rewards for Post-Training Qiskit Code Assistant},
Year = {2025},
Eprint = {arXiv:2508.20907},
}