fixed for dot-parsed networkx graphs
Hi, while using the dimod library with networkx to solve the minimum vertex cover problem, I noticed that the dimod library is having issues with networkx graph objects generated from dot files using read_dot function. The dimod function _init_components was using a (u,v) tuple in a for loop. It worked well for all other graphs except those generated from dot files. The quadratic parameter was a collection of dicts which in my case did not always have 2-element keys. When the bias was different than -1.0, the dict contained a 3-element key with a zero at the end (always). To solve this issue i changed how the function iterates over a quadratic collection to avoid the "too many values to unpack" error.
Codecov Report
Merging #768 (e0097a7) into main (a201e2f) will increase coverage by
0.00%. The diff coverage is100.00%.
@@ Coverage Diff @@
## main #768 +/- ##
=======================================
Coverage 92.00% 92.00%
=======================================
Files 63 63
Lines 4666 4668 +2
=======================================
+ Hits 4293 4295 +2
Misses 373 373
| Impacted Files | Coverage Δ | |
|---|---|---|
| dimod/bqm/adjdictbqm.py | 94.75% <100.00%> (+0.04%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update a201e2f...e0097a7. Read the comment docs.
Hi @filipceglik , thanks for the PR. I think we definitely want to support networkx graphs created this way, but I am worried that the current solution will have unintended side-effects. Are you referring to graphs constructed with read_dot?
Could you post a short example of the code that's not working for you?
Hi @arcondello, absolutely. I have a function in my code which returns the networkx graph using the read_dot function. Perhaps this is a bug in the read_dot function but I wasn't able to track where this might be going wrong. I am pasting the code below. At one point the quadratic variable has keys with 3 items inside of them for the bias different that -1.0.

Please bear in mind that I am not a professional developer, just someone who noticed this behavior for this particular case so please keep me informed on any issues this solution might create and I am sure we can work some correct solution if it indeed turns out to be a bug in the dimod.
Hi @filipceglik , thanks! I actually meant an example of a dotfile, I am not familiar with that format. Sorry for the confusion!
Agree that we should get this working.
Sure thing @arcondello, attaching the file. I changed the extension from dot to txt since github does not support uploading dot files. graph.txt
Hi @filipceglik , does your program look something like
G = nx.drawing.nx_agraph.read_dot(dotfile)
bqm = dimod.BQM.from_networkx_graph(G)
or are you constructing the BQM some other way?
Hi @arcondello,
I am really sorry, I haven't seen your reply and I just looked at the PR.
This is the most logic of my program, it's parsing the dotfile and uses the dwave quantum computing API to determine the minimum vertex cover of a graph.
I am creating the sampler using
EmbeddingComposite(DWaveSampler(endpoint=ENDPOINT, token=TOKEN, solver=SOLVER))
