Use Qiskit Code Assistant in Visual Studio Code
Learn how to install, use, configure and uninstall the official Qiskit Code Assistant extension in Visual Studio Code (VS Code).
- This is an experimental feature available only to IBM Quantum™ Premium Plan users.
- Qiskit Code Assistant is in preview release status and is subject to change.
- If you have feedback or want to contact the developer team, use the Qiskit Slack Workspace channel or the related public GitHub repositories.
Install the VS Code extension
To install the VS Code extension, follow these steps:
Install directly from VS Code:
- Launch VS Code.
- Click the Extensions icon in the left toolbar.
- Search for
qiskit
- Find "Qiskit Code Assistant (Beta)" and click Install.
Alternatively, the extension is also available through the VS Code Marketplace.
The extension loads automatically and is listed on the bottom of the VS Code window, as shown. If it is not listed, reload the extension or application.
Configure extension settings
The following settings can be configured:
-
To change keyboard shortcuts, open the Keyboard Shortcuts settings (
Cmd/Ctrl
+Shift
+P
->Preferences: Open Keyboard Shortcuts (JSON)
) and search forqiskit-vscode
. -
You can change the IBM Quantum API token to use in the VS Code command palette. To do that, type
Cmd/Ctrl
+Shift
+P
, search forqiskit
, select the Qiskit Code Assistant: Set IBM Quantum API token command, and paste your IBM Quantum API token. -
[Advanced] To change the instance of the Qiskit Code Assistant Service that the extension should use, go to File -> Preferences -> Settings. On the User tab, search for Qiskit, and edit the
Qiskit Code Assistant: Url
.
Get started using the Qiskit Code Assistant extension for VS Code
Authentication and setup
After installing the extension, it tries to authenticate you. By default, the package tries to authenticate to IBM Quantum services with the defined Qiskit API token, and uses your token from the QISKIT_IBM_TOKEN
environment variable or from the file ~/.qiskit/qiskit-ibm.json
(under the section default-ibm-quantum
). If you need help configuring your account, follow the instructions in Set up to use IBM Quantum Platform.
By default, the extension uses the granite-8b-qiskit
model, which is listed in the Model Picker in the bottom status bar.
The first time you use the granite-8b-qiskit
model, a modal opens listing some major restrictions that you should be aware of when using the model. Clicking Accept
will accept the disclaimer and enable the model for code generation.
Generate code
While you develop your code using Qiskit, you can ask Qiskit Code Assistant to help you. In general, the Assistant suggests better code in response to Python comments or docstrings, but you can use the Assistant anywhere in your file.
To get a code suggestion, type a prompt, then Ctrl
+.
. There are two types of prompts you can use:
- Enter partial code and get a suggestion to finish the code. Example:
from qiskit.circuit import QuantumCircuit from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager from qiskit_ibm_runtime import SamplerV2 as Sampler from qiskit_ibm_runtime.fake_provider import FakeManilaV2 # Bell Circuit qc = QuantumCircuit(2) qc.h(0) qc.cx(0, 1) qc.mea # Type Ctrl + . for a code suggestion.
- Type a pound (#) sign, then type your prompt. Example:
# Give me a random circuit of 5 qubits and a depth of 4.
Work with code suggestions
Use the following to accept, reject, and cycle through suggestions:
- Press
Tab
to accept the suggestion or pressESC
to reject it. - After getting a suggestion, type
Ctrl
+.
again to generate additional suggestions. - When a suggestion is shown, use
Option/Alt
+]
andOption/Alt
+[
to cycle forward and backward, respectively, through the suggestions (if available). - Hover the cursor over the suggestion to use the pop-up toolbar to cycle through the suggestions, as shown:
Uninstall the VS Code extension
To remove Qiskit Code Assistant from VS Code, follow these steps:
- Launch Visual Studio Code.
- Click the Extensions icon.
- Search for
qiskit
and open Qiskit Code Assistant. - Click Uninstall.
Troubleshooting
If you don't see the extension status bar in VS Code, check that the extension is installed and enabled under the extensions tab.
If the extension is installed and enabled, but it cannot select a model, verify that your current API token has been added and the Qiskit Code Assistant: Url
is properly set.
Contribute to the VS Code extension
The code for this official extension is publicly available and open source. Check it out in GitHub.
Next steps
See examples to use Qiskit Code Assistant for circuits, configuring error suppression, and transpiling with pass managers.