メインコンテンツへスキップ

Qiskit Code Assistant

Qiskit Code Assistantは、Qiskitを初めて利用する方にとって量子コンピューティングをより身近なものにし、既存のユーザーのコーディング体験を向上させることを目指しています。watsonx を基盤とした生成AIコードアシスタントです。Qiskit SDK数百万件のテキストトークン、長年にわたるQiskitコード例、およびIBM Quantum® の機能を用いてトレーニングされています。Qiskit Code Assistantは、IBMの最新機能を組み込んだ IBM Graniteモデル に基づくLLM生成の提案を提供することで、量子開発ワークフローをサポートします。

Notes
  • これは、新しい IBM Quantum Platform に登録されたIBM Quantum Premiumプランユーザー向けに提供される実験的機能です。
  • Qiskit Code Assistantはプレビューリリースの状態であり、変更される可能性があります。
  • フィードバックや開発チームへのお問い合わせは、Qiskit Slack Workspaceチャンネル または関連する公開GitHubリポジトリを使ってください。

機能

以下の機能は、Visual Studio Code(VS Code)および互換エディター、ならびに JupyterLab 拡張機能に含まれています。

  • Qiskitコード生成に特化したモデルに基づく生成AIを活用して、Qiskitコードの生成を加速します。
  • 抽象的なプロンプトや具体的なプロンプトを使用して推奨コードを生成できます。
  • 確認、承認、または拒否できる提案を表示します。
  • PythonコードおよびJupyter notebookファイルをサポートします。
  • ヘイトスピーチなど、ユーザーにとって潜在的なリスクとなる質問への回答を避けるためのガードレールが含まれています。

Qiskit Code Assistantを開発環境に直接統合する手順については、該当するトピックの指示に従ってください。

Qiskit Code Assistantの基盤となる大規模言語モデル(LLM)

コード提案を提供するために、Qiskit Code Assistantは大規模言語モデル(LLM)を使用しています。現在、Qiskit Code Assistantは Mistral-Small-3.2-24B-Qiskitモデル をベースに構築された mistral-small-3.2-24b-qiskit モデルを使用しています。mistral-small-3.2-24b-qiskit モデルは、高品質なQiskitデータ、PythonコミットおよびチャットデータによるPretraining拡張とFine-tuningを通じて、Mistral-Small-3.2-24B-Instruct-2506 モデルのQiskitに対するコード生成能力を向上させたものです。Mistral AIモデルファミリーの詳細については、Mistral AIのドキュメント を参照してください。.*-qiskit モデルの詳細については、Qiskit Code Assistant: Training LLMs for generating Quantum Computing Code を参照してください。

Qiskit向けに特化したLLMは、オープンソースモデルとしても提供されています。利用可能なすべてのモデルは https://huggingface.co/Qiskit でご確認いただけます。

Qiskit HumanEvalおよびQiskit HumanEval Hardベンチマーク

mistral-small-3.2-24b-qiskit およびその他のモデルをテストするために、Qiskit AdvocatesおよびエキスパートとともにQiskit HumanEval(QHE)およびQiskit HumanEval Hard(QHE Hard)と呼ばれる実行ベースのベンチマークを作成し、各モデルで実行しました。これらのベンチマークは HumanEval に類似しており、すべて公式Qiskitライブラリに基づく複数の難解なコード問題が含まれています。

このベンチマークは約150のテストで構成されており、それぞれ関数定義と、モデルが解くべきタスクを詳述するdocstringで構成されています。各例にはリファレンスとなる標準解答と、生成された解の正確さを評価するためのユニットテストも含まれています。テストの難易度は、基本、中級、難易度の高いの3段階です。Qiskit HumanEval Hardベンチマークは、Qiskit HumanEvalの変形版ですが、コードのimportに関する情報を除外しているため、LLMが適切なメソッドやクラスのimportを自ら判断する必要があります。この変更により、私たちのテストと初期結果によると、データセットはLLMにとってはるかに難しくなります。

Qiskit HumanEvalおよびQiskit HumanEval Hardのデータセットは次のサイトで入手できます: Qiskit HumanEval および Qiskit HumanEval Hard。これらのベンチマークの開発には、GitHubリポジトリ からコントリビューションいただけます。

詳細情報と引用

Qiskit Code Assistant、Qiskit HumanEval、またはQiskit HumanEval Hardベンチマークの詳細を学んだり、科学的な出版物に引用したりするには、以下の推奨引用を参照してください。

@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},
}

ローカルモードでのQiskit Code Assistantの使用

Qiskit Code Assistantモデルのいずれかをローカルマシンにインストール、設定、および使用する方法を学びます。

Notes
  • Qiskit Code Assistantはプレビューリリースの状態であり、変更される可能性があります。
  • フィードバックや開発チームへのお問い合わせは、Qiskit Slack Workspaceチャンネル または関連する公開GitHubリポジトリを使ってください。

ローカルモードでQiskit Code Assistantを使い始める最も簡単な方法は、VS CodeまたはJupyterLab拡張機能用の自動セットアップスクリプトを使用することです。これらのスクリプトは、LLMを実行するための Ollama の自動インストール、推奨モデルのダウンロード、および拡張機能の設定を自動で行います。

VS Code拡張機能のセットアップ

ターミナルで以下のコマンドを実行してください:

bash <(curl -fsSL https://raw.githubusercontent.com/Qiskit/qiskit-code-assistant-vscode/main/setup_local.sh)

このスクリプトは以下のステップを実行します:

  • Ollamaのインストール(未インストールの場合)
  • 推奨Qiskit Code Assistantモデルのダウンロードと設定
  • ローカルデプロイに対応したVS Code拡張機能のセットアップ

JupyterLab拡張機能のセットアップ

ターミナルで以下のコマンドを実行してください:

bash <(curl -fsSL https://raw.githubusercontent.com/Qiskit/qiskit-code-assistant-jupyterlab/main/setup_local.sh)

このスクリプトは以下を実行します:

  • Ollamaのインストール(未インストールの場合)
  • 推奨Qiskit Code Assistantモデルのダウンロードと設定
  • ローカルデプロイに対応したJupyterLab拡張機能のセットアップ

利用可能なモデル

現行モデル

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形式のモデルはローカル使用に最適化されており、必要な計算リソースが少なくて済みます:

  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

オープンソースのQiskit Code Assistantモデルは safetensors または GGUF file format で提供されており、以下で説明するようにHugging Faceからダウンロードできます。

トレーニングに使用されたQiskitバージョン

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.

非推奨モデル

これらのモデルは積極的なメンテナンスは行われていませんが、引き続き利用可能です:

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

高度なセットアップ

ローカルセットアップを手動で設定したい場合や、インストール手順をより細かく制御したい場合は、以下のセクションを展開してください。

Download from the Hugging Face website

Hugging FaceウェブサイトからQiskit Code Assistant関連モデルをダウンロードするには、以下の手順に従ってください:

  1. Hugging Face上の目的のQiskitモデルページに移動します。
  2. Files and Versions タブに進み、safetensorsまたはGGUFモデルファイルをダウンロードします。
Download using the Hugging Face CLI

Hugging Face CLIを使用して利用可能なQiskit Code Assistantモデルをダウンロードするには、以下の手順に従ってください:

  1. Hugging Face CLI をインストールします

  2. Hugging Faceアカウントにログインします

    huggingface-cli login
  3. 前のリストから希望するモデルをダウンロードします

    huggingface-cli download <HF REPO NAME> <MODEL PATH> --local-dir <LOCAL PATH>
Manually deploy the Qiskit Code Assistant models in local through Ollama

ダウンロードしたQiskit Code Assistantモデルをデプロイして操作する方法は複数あります。このガイドでは、Ollama を使用する方法を説明します: Hugging Face Hubインテグレーションまたはローカルモデルを使用した Ollamaアプリケーション、または llama-cpp-python パッケージ を使用する方法です。

Ollamaアプリケーションの使用

OllamaアプリケーションはLLMをローカルで実行するためのシンプルなソリューションです。CLIによって、セットアップ全体のプロセス、モデル管理、および操作が非常に簡単になります。素早い実験や、技術的な詳細をあまり扱いたいくないユーザーに最適です。

Ollamaのインストール
  1. Ollamaアプリケーション をダウンロードします

  2. ダウンロードしたファイルをインストールします

  3. インストールしたOllamaアプリケーションを起動します

    情報

    The application is running successfully when the Ollama icon appears in the desktop menu bar. You can also verify the service is running by going to http://localhost:11434/.

  4. ターミナルでOllamaを試してモデルを実行してみましょう。例えば:

    ollama run hf.co/Qiskit/Qwen2.5-Coder-14B-Qiskit
Hugging Face Hubインテグレーションを使ったOllamaのセットアップ

Ollama/Hugging Face Hubインテグレーション は、新しいmodelfileを作成したり、GGUFまたはsafetensorsファイルを手動でダウンロードしたりすることなく、Hugging Face Hub上でホストされているモデルを操作する方法を提供します。モデルの templateparams ファイルはHugging Face Hub上のモデルにデフォルトで含まれています。

  1. Ollamaアプリケーションが実行中であることを確認します。

  2. 目的のモデルページに移動し、URLをコピーします。例えば、https://huggingface.co/Qiskit/Qwen2.5-Coder-14B-Qiskit-GGUF。

  3. ターミナルから以下のコマンドを実行します:

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

hf.co/Qiskit/Qwen2.5-Coder-14B-Qiskit モデル、またはその他の現在推奨されているGGUF公式モデル hf.co/Qiskit/mistral-small-3.2-24b-qiskit-GGUFhf.co/Qiskit/granite-3.3-8b-qiskit-GGUF を使用できます。

手動でダウンロードしたQiskit Code Assistant GGUFモデルをOllamaでセットアップする

https://huggingface.co/Qiskit/Qwen2.5-Coder-14B-Qiskit-GGUF のようなGGUFモデルを手動でダウンロードし、異なるテンプレートやパラメーターを試したい場合は、以下の手順に従ってローカルのOllamaアプリケーションに読み込むことができます。

  1. 以下の内容を入力して Modelfile を作成し、<PATH-TO-GGUF-FILE> をダウンロードしたモデルの実際のパスに更新してください。

    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
    備考

    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

Qiskitモデルの適切な動作を確保するために、HF GGUFリポジトリで提供されているシステムプロンプトの使用を推奨します: mistral-small-3.2-24b-qiskit-GGUFQwen2.5-Coder-14B-Qiskit-GGUFgranite-3.3-8b-qiskit-GGUF、および granite-3.2-8b-qiskit-GGUF のシステムプロンプトです。

Manually connect extensions to local deployment

Qiskit Code AssistantのVS Code拡張機能およびJupyterLab拡張機能を使用して、ローカルにデプロイされたQiskit Code Assistantモデルにプロンプトを送信します。モデルとともにOllamaアプリケーションをセットアップ したら、ローカルサービスに接続するよう拡張機能を設定できます。

Qiskit Code Assistant VS Code拡張機能との接続

Qiskit Code Assistant VS Code拡張機能を使用すると、コードを記述しながらモデルを操作してコード補完を行うことができます。PythonアプリケーションのQiskitコード作成を支援したいユーザーに適しています。

  1. Qiskit Code Assistant VS Code拡張機能 をインストールします。
  2. VS Codeで User Settings に移動し、Qiskit Code Assistant: Url をローカルOllamaデプロイのURL(例: http://localhost:11434)に設定します。
  3. View > Command Palette... に移動し、Developer: Reload Window を選択してVS Codeをリロードします。

OllamaでQiskit Code Assistantモデルが設定されると、ステータスバーに表示され、使用可能な状態になります。

Qiskit Code Assistant JupyterLab拡張機能との接続

Qiskit Code Assistant JupyterLab拡張機能を使用すると、Jupyter Notebook内で直接モデルを操作してコード補完を行うことができます。主にJupyter Notebookを使用するユーザーは、この拡張機能を活用してQiskitコードの記述体験をさらに向上させることができます。

  1. Qiskit Code Assistant JupyterLab拡張機能 をインストールします。
  2. JupyterLabで Settings Editor に移動し、Qiskit Code Assistant Service API をローカルOllamaデプロイのURL(例: http://localhost:11434)に設定します。

OllamaでQiskit Code Assistantモデルが設定されると、ステータスバーに表示され、使用可能な状態になります。

次のステップ

Recommendations