Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed for dot-parsed networkx graphs #768

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nopbrick
Copy link

@nopbrick nopbrick commented Dec 5, 2020

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-io
Copy link

codecov-io commented Dec 5, 2020

Codecov Report

Merging #768 (e0097a7) into main (a201e2f) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           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%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a201e2f...e0097a7. Read the comment docs.

@arcondello
Copy link
Member

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?

@arcondello arcondello added the bug label Dec 7, 2020
@nopbrick
Copy link
Author

nopbrick commented Dec 8, 2020

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.

image

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.

@arcondello
Copy link
Member

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.

@nopbrick
Copy link
Author

Sure thing @arcondello, attaching the file.
I changed the extension from dot to txt since github does not support uploading dot files.
graph.txt

@arcondello
Copy link
Member

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?

@nopbrick
Copy link
Author

nopbrick commented Feb 4, 2021

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))

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants