Skip to content

Commit

Permalink
Jack's review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
boothby committed Nov 18, 2021
1 parent ae4020d commit 9f8611c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 57 deletions.
37 changes: 15 additions & 22 deletions dwave_networkx/generators/pegasus.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,39 +260,32 @@ def efilter(e): return qfilter(*e[0]) and qfilter(*e[1])

if data:
v = 0
def coord_label():
return q
def int_label():
return v
if nice_coordinates:
def this_label():
return pegasus_to_nice(q)
other_name = 'linear_index'
other_label = int_label
def fill_data():
q = (u, w, k, z)
d = get_node_data(pegasus_to_nice(q))
if d is not None:
d['linear_index'] = v
d['pegasus_index'] = q
elif coordinates:
this_label = coord_label
other_name = 'linear_index'
other_label = int_label
def fill_data():
d = get_node_data((u, w, k, z))
if d is not None:
d['linear_index'] = v
else:
this_label = int_label
other_name = 'pegasus_index'
other_label = coord_label
def fill_data():
d = get_node_data(v)
if d is not None:
d['pegasus_index'] = (u, w, k, z)

get_node_data = G.nodes.get
for u in range(2):
for w in range(m):
for k in range(12):
for z in range(m1):
q = u, w, k, z
p = this_label()
d = get_node_data(p)
if d is not None:
d[other_name] = other_label()
fill_data()
v += 1

if nice_coordinates:
for p, d in G.nodes(data=True):
d['pegasus_index'] = nice_to_pegasus(p)
return G


Expand Down
58 changes: 23 additions & 35 deletions dwave_networkx/generators/zephyr.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def zephyr_graph(m, t=4, create_using=None, node_list=None, edge_list=None,
The graph uses a "nicer" coordinate system, more compatible with Chimera
addressing. These coordinates are 5-tuples taking the form
:math:`(j, y, x, u, k)` where :math:`0 <= j < 2`, :math:`0 <= x < m`,
:math:`0 <= y < m`, :math:`0 <= u < 2`, and :math:`0 <= k < 4`.
:math:`0 <= y < m`, :math:`0 <= u < 2`, and :math:`0 <= k < 2t`.
For any given :math:`0 <= j < 2`, the subgraph of nodes with :math:`j = j0`
has the structure of `chimera(M, M, 2*t)` with the addition of odd couplers.
Supercedes the `coordinates` parameter. Certain nodes are removed from
Expand Down Expand Up @@ -208,51 +208,39 @@ def label(u, w, k, j, z):
G.add_nodes_from(nodes) # for singleton nodes

if data:
v = 0
def coord_label():
return q
def int_label():
return v
if nice_coordinates:
def this_label():
return zephyr_to_nice(q)
other_name = 'linear_index'
other_label = int_label
elif coordinates or nice_coordinates:
this_label = coord_label
other_name = 'linear_index'
other_label = int_label
def fill_data():
q = (u, w, k, j, z)
p = zephyr_to_nice(q)
d = get_node_data(p)
if d is not None:
d['linear_index'] = v
d['zephyr_index'] = q

elif coordinates:
def fill_data():
d = get_node_data((u, w, k, j, z))
if d is not None:
d['linear_index'] = v

else:
this_label = int_label
other_name = 'zephyr_index'
other_label = coord_label
def fill_data():
d = get_node_data(v)
if d is not None:
d['zephyr_index'] = (u, w, k, j, z)

v = 0
get_node_data = G.nodes.get
for u in range(2):
for w in range(M):
for k in range(t):
for j in (0, 1):
for z in range(m):
q = u, w, k, j, z
p = this_label()
d = get_node_data(p)
if d is not None:
d[other_name] = other_label()
fill_data()
v += 1

if nice_coordinates:
remove = set()
for p, d in G.nodes(data=True):
if 0 <= p[1] < m and 0 <= p[2] < m:
d['zephyr_index'] = nice_to_zephyr(p)
else:
remove.add(p)
if node_list is None and edge_list is None:
G.remove_nodes_from(remove)

elif nice_coordinates:
if node_list is None and edge_list is None:
G.remove_nodes_from([p for p in G if not 0 <= p[1] < m or not 0 <= p[2] < m])
if node_list is None and edge_list is None and nice_coordinates:
G.remove_nodes_from([p for p in G if not 0 <= p[1] < m or not 0 <= p[2] < m])

return G

Expand Down

0 comments on commit 9f8611c

Please sign in to comment.