This guide walks you through using Visual Studio Code (VS Code) to run and explore D-Wave’s official sample applications. D-Wave maintains an active GitHub collection (dwave-examples) containing beginner notebooks, basic script implementations, and industry-specific optimization applications.
Prerequisites
Before starting, ensure you have the following installed on your machine:
Step-by-Step Guide to Running D-Wave Samples in VS Code
1.Clone the Sample Repository:Clone a D-Wave sample repository from GitHub.
Open VS Code and launch the terminal (Ctrl+\`` or Cmd+``).
For beginners, clone the simple-ocean-programs repository:
Bash
git clone https://github.com/dwave-examples/simple-ocean-programs.git
cd simple-ocean-programs
Then, open this folder in VS Code via File > Open Folder... (or run code . in your terminal).
2.Create & Activate Virtual Environment:Isolate dependencies within the VS Code workspace.
In the VS Code terminal, create a local Python virtual environment:
macOS/Linux:
Bash
python3 -m venv .venv
source .venv/bin/activate
Windows (PowerShell):
PowerShell
python -m venv .venv
.\.venv\Scripts\Activate.ps1
Press Ctrl+Shift+P (or Cmd+Shift+P), search for Python: Select Interpreter, and select .venv/bin/python (or .venv\Scripts\python.exe).
3.Install Project Dependencies:Install Ocean SDK and requirements.
Upgrade pip and install the repository requirements (or standard Ocean SDK):
Bash
pip install --upgrade pip
pip install -r requirements.txt
(If no requirements.txt exists in the repository, simply run pip install dwave-ocean-sdk dwave-inspector).
4.Authenticate with D-Wave Leap:Connect local environment to D-Wave Leap hardware.
Run the interactive configuration CLI inside the VS Code terminal:
Bash
dwave setup
Paste your D-Wave Leap API Token when prompted and accept the defaults. Verify connectivity to quantum hardware by running:
Bash
dwave ping
5.Run Sample Applications:Run Python scripts or interactive Jupyter notebooks.
Choose how you want to execute your sample:
-
Python Script (.py): Open a sample file (e.g., Basic_Programs/minimum_vertex_cover.py), click the Play icon (▷) in the upper-right corner of the editor window, or press F5 to debug.
-
Jupyter Notebook (.ipynb): Open any .ipynb file in VS Code. Ensure the top-right kernel selector points to your .venv environment, then click Run All.
Exploring Key D-Wave Sample Repositories
D-Wave provides starter templates and notebooks tailored to different skill levels:
| Repository Name |
Description |
Best For |
simple-ocean-programs |
Basic QUBO and Ising formulations, graph embedding, and BQM basics. |
Absolute Beginners |
hybrid-computing-notebook |
Tutorials on using Leap's hybrid solvers for large-scale constraint problems. |
Intermediate Developers |
maximum-cut |
Solving the Max-Cut problem on graphs using dwave-networkx and QPU samplers. |
Graph Optimization |
portfolio-optimization |
Financial portfolio balancing using Quadratic Unconstrained Binary Optimization (QUBO). |
Industry Applications |
Visualizing QPU Embeddings with D-Wave Inspector
When running QPU-native samples, you can launch the interactive D-Wave Inspector directly from VS Code.
Add the inspector call to any script after sampling:
Python
import dimod
import dwave.inspector
from dwave.system import DWaveSampler, EmbeddingComposite
# Generate a random BQM problem
bqm = dimod.generators.ran_r(1, 10)
sampler = EmbeddingComposite(DWaveSampler())
sampleset = sampler.sample(bqm, num_reads=100)
# Opens the interactive graph/QPU embedding visualizer in your web browser
dwave.inspector.show(sampleset)
Running this script in VS Code automatically launches a local web browser interface showing physical qubit allocations, chain breaks, and energy landscapes on the QPU hardware.