dwave-networkx icon indicating copy to clipboard operation
dwave-networkx copied to clipboard

edge_list and node_list behave unexpectedly in graph generators

Open jackraymond opened this issue 3 months ago • 5 comments

Description It is useful to permute node and edge orderings in graph creation for example to randomize the behaviour of otherwise deterministic methods.

  • dwave_networkx graph node ordering doesn't seem to respond to the ordering of the node_list parameter.
  • When the edge_list parameter is provided matching the default, the node_ordering is changed relative to the default.

To Reproduce

T = dnx.pegasus_graph(2)
node_list = list(T.nodes())
node_list.reverse()
T2 = dnx.pegasus_graph(2, node_list=node_list)  # Same graph
print(T2.nodes())  # original ordering, ignores provided ordering.
edge_list = list(T1.edges())
node_list = list(T1.nodes())
T3 = dnx.pegasus_graph(2, node_list=node_list, edge_list=edge_list)
print(T3.nodes())  # Does not match T1.nodes(), which is unexpected.

Expected behavior node_list should dictate node order, edge_list should dictate edge order.

Environment:

  • OS: [Ubuntu 22.04.3 LTS]
  • Python version: [e.g. 3.12.0]

Additional context I'll make a pull request to correct this unless a good case can be made not to, don't really want to mess with these core generators unnecessarily. I want to use in combination with minorminer.subgraph.find_subgraph(S, T) which deterministically searches for a subgraph. Reordering the target (T) nodes allows a more uniform distribution across the processor with respect to some source graph S.

jackraymond avatar Nov 06 '24 21:11 jackraymond