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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions dimod/bqm/adjdictbqm.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,18 @@ def _init_components(self, linear, quadratic, offset, vartype):
adj = self._adj

if isinstance(quadratic, abc.Mapping):
for (u, v), bias in quadratic.items():
self.add_variable(u)
self.add_variable(v)
for quadraticitem in quadratic.items():
key = quadraticitem[0]
bias = quadraticitem[1]
self.add_variable(key[0])
self.add_variable(key[1])

if u == v and vartype is Vartype.SPIN:
if key[0] == key[1] and vartype is Vartype.SPIN:
offset = offset + bias # not += on off-chance it's mutable
elif u in adj[v]:
adj[u][v] = adj[v][u] = adj[u][v] + bias
elif key[0] in adj[key[1]]:
adj[key[0]][key[1]] = adj[key[1]][key[0]] = adj[key[0]][key[1]] + bias
else:
adj[u][v] = adj[v][u] = bias
adj[key[0]][key[1]] = adj[key[1]][key[0]] = bias
elif isinstance(quadratic, abc.Iterator):
for u, v, bias in quadratic:
self.add_variable(u)
Expand Down