From e0097a79e59fe68497399ac0885416039e0da551 Mon Sep 17 00:00:00 2001 From: Filip Ceglik Date: Sat, 5 Dec 2020 19:33:59 +0100 Subject: [PATCH] fixed for dot-parsed networkx graphs --- dimod/bqm/adjdictbqm.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/dimod/bqm/adjdictbqm.py b/dimod/bqm/adjdictbqm.py index e304c7ed8..d9f013fcb 100644 --- a/dimod/bqm/adjdictbqm.py +++ b/dimod/bqm/adjdictbqm.py @@ -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)