Integrating the D-Wave Ocean SDK into Visual Studio Code with a dedicated virtual environment establishes a secure, isolated, and scalable environment that streamlines the entire quantum development lifecycle. By isolating complex dependencies like dimod, dwave-system, and heavy scientific libraries within a local workspace, you prevent system-wide package conflicts, avoid dependency breakage, and simplify team collaboration through reproducible environments. VS Code amplifies developer productivity by pairing with extensions like Pylance and Jupyter to deliver immediate IntelliSense, inline documentation, type checking, and interactive visualization for mathematical objects like Binary Quadratic Models (BQMs) before executing costly hardware requests. Furthermore, this integration offers built-in security by allowing API credentials (DWAVE_API_TOKEN) to load dynamically from localized .env files—preventing accidental key exposure in version control—while built-in debugging tools enable deep inspection of multi-sample energy landscapes without cluttering code with temporary print statements.
Setting up inside VS Code allows you to leverage built-in virtual environment detection, terminal integration, and interactive debugging.
Step 1: Open Project Directory in VS Code
-
Launch VS Code.
-
Go to File > Open Folder... (or Cmd+O / Ctrl+O).
-
Create a new folder named dwave-quantum and open it.
Step 2: Create & Select the Virtual Environment
VS Code integrates directly with Python virtual environments to ensure code completion and linting point to the correct packages.
1.Open Integrated Terminal:Use the integrated terminal.
Open the built-in terminal by pressing `Ctrl+`` (or Terminal > New Terminal from the top menu).
On macOS/Linux:
Bash
python3 -m venv .venv
On Windows:
DOS
python -m venv .venv
Tip: If VS Code shows a prompt asking "We noticed a new virtual environment has been created. Do you want to select it for the workspace folder?", click Yes.
macOS/Linux:
Bash
source .venv/bin/activate
pip install dwave-ocean-sdk
Windows (PowerShell):
PowerShell
.\.venv\Scripts\Activate.ps1
pip install dwave-ocean-sdk
Step 3: Configure Authentication & Settings
VS Code allows you to configure your API key through the terminal or via workspace environment files.
Option A: Terminal Setup (Recommended)
Run the standard CLI prompt inside the VS Code terminal:
Bash
dwave setup
Follow the prompts to paste your D-Wave Leap API key. This saves a global configuration file in your user home directory (~/.config/dwave/dwave.conf).
Option B: Local Environment Variables (.env file)
If you prefer keeping credentials local to the project directory:
-
Create a file named .env in your project root.
-
Add your Leap token:
Code snippet
DWAVE_API_TOKEN=YOUR_LEAP_API_TOKEN_HERE
-
VS Code’s Python extension automatically loads .env variables when running scripts.
Step 4: Run & Debug Ocean SDK Scripts
-
Create a new file named app.py in the file explorer.
-
Add your Ocean script (e.g., the QUBO example from the KB article).
-
Click the Play icon (▷) in the upper-right corner of the editor window, or press F5 to start debugging.
Recommended VS Code Extensions for D-Wave Development
| Extension |
Publisher |
Description |
| Python |
Microsoft |
Essential support for debugging, IntelliSense, and environment selection. |
| Pylance |
Microsoft |
Provides fast, high-performance language support and autocomplete for dimod and dwave packages. |
| Jupyter |
Microsoft |
Allows running Ocean SDK models interactively in .ipynb notebooks inside VS Code. |