dwave-networkx
raw JSON → 0.8.18 verified Fri May 01 auth: no python
A NetworkX extension providing graphs and algorithms relevant to working with the D-Wave System. Current version: 0.8.18. Release cadence: roughly quarterly.
pip install dwave-networkx Common errors
error ModuleNotFoundError: No module named 'dwave_networkx' ↓
cause Package not installed or installed in wrong environment.
fix
Run 'pip install dwave-networkx' in the correct Python environment.
error ImportError: cannot import name 'chimera_graph' ↓
cause Using incorrect import path (e.g., from dwave_networkx.generators import chimera_graph instead of from dwave_networkx import chimera_graph).
fix
Use 'from dwave_networkx import chimera_graph'.
error AttributeError: module 'dwave_networkx' has no attribute 'draw_chimera' ↓
cause Matplotlib is not installed, or using an old version of dwave-networkx before drawing functions were added.
fix
Install Matplotlib: 'pip install matplotlib'. If that doesn't work, update dwave-networkx to >=0.8.10.
error ValueError: The graph is not bipartite? ↓
cause Using a graph not compatible with the expected topology (e.g., trying to embed a non-bipartite graph into a Chimera structure).
fix
Ensure the input graph matches the topology requirements. Check the documentation for the specific algorithm.
Warnings
breaking Version 0.8.14 dropped support for Python 3.7 and earlier. If you are using Python 3.7 or below, you must use an older version (<=0.8.13). ↓
fix Upgrade Python to 3.9+ or pin dwave-networkx to 0.8.13.
breaking Version 0.8.12 removed dependency on dwave-preprocessing. If your code relied on dwave-preprocessing being installed implicitly, you need to add it explicitly. ↓
fix Run 'pip install dwave-preprocessing' if you use its features directly.
deprecated The dwave-networkx package uses some deprecated NetworkX APIs that may be removed in future NetworkX versions. For example, the use of `nx.MultiGraph` in certain graph constructors may need updating. ↓
fix Monitor NetworkX deprecation warnings. Use `import warnings; warnings.filterwarnings('ignore', category=DeprecationWarning)` if needed.
gotcha Drawing functions (e.g., `draw_chimera`, `draw_zephyr`) require Matplotlib to be installed. They will raise an ImportError if Matplotlib is missing. ↓
fix Install Matplotlib: 'pip install matplotlib'.
gotcha The `maximum_independent_set` algorithm uses `dimod.ExactSolver()` by default, which is only suitable for very small graphs. For larger graphs, provide a different sampler. ↓
fix Pass a sampler like `dwave.system.DWaveSampler()` to the algorithm.
Imports
- dwave_networkx wrong
import dwave_networkx.dwave_networkx as dnxcorrectimport dwave_networkx as dnx - chimera_graph
from dwave_networkx import chimera_graph - draw_chimera wrong
import dwave_networkx.draw.draw_chimeracorrectfrom dwave_networkx import draw_chimera
Quickstart
import networkx as nx
import dwave_networkx as dnx
import dimod
# Create a Chimera graph (hardware graph)
G = dnx.chimera_graph(1, 1, 4)
print(f"Nodes: {len(G.nodes)}, Edges: {len(G.edges)}")
# Example: maximum independent set (QUBO formulation)
from dimod import ExactSolver
# Solve maximum independent set on a small graph
H = nx.path_graph(3)
qubo, offset = dnx.algorithms.independent_set.maximum_independent_set_qubo(H)
sampler = ExactSolver()
sampleset = sampler.sample_qubo(qubo)
solution = dnx.algorithms.independent_set.maximum_independent_set(H, sampler)
print(f"Maximum independent set: {solution}")