Closed ryandeng1 closed 5 months ago
The code is panicking when accessing the scores for the shortest path but the culprit is probably this: https://github.com/Qiskit/rustworkx/blob/eb896fbd88c8bd086379cd2d46b2a1f74981bc9e/rustworkx-core/src/shortest_path/dijkstra.rs#L115C28-L115C33
Maybe the subgraph does not have the current .node_bound()
set? We'll investigate more and try to release a fix in 0.14.2 if possible.
Ok I think get why you are getting a panic. The good news is there is no bug in rustworkx
and that the code is working as intended. However, you will need to rewrite your code.
Here is a short snippet to reproduce the same error message you posted:
import rustworkx as rx
graph = rx.generators.generalized_petersen_graph(5, 2)
sub_nodes = [6, 7, 8, 9, 5]
subg = graph.subgraph(sub_nodes)
# This works, subgraph generates new node indices
paths = rx.dijkstra_shortest_paths(subg, 0)
# This panics like reported
paths_fail = rx.dijkstra_shortest_paths(subg, sub_nodes[0])
Subgraph generates new node indices, hence you need to account for that in your code. You should not call shortest path functions with the old node indices.
The fix from our side will be to add a more clear error message so you get an Exception
and not a panic crashing your program.
Closed by #1134. Once the backport #1135 merges I plan to release 0.14.2
Information
What is the current behavior?
I see a panic when running
rustworkx.dijkstra_shortest_paths
andrustworkx.dijkstra_shortest_path_lengths
on a graph produced byPyGraph.subgraph
. The subgraphs are quite small, hundreds of nodes while the main graph is 100k nodes.Running on the larger graph seems to work fine. I think it may be due to the fact that the node ids remain the same as the one in the original graph, but they might be accessed in a way that goes out of bounds in the subgraph?
What is the expected behavior?
Steps to reproduce the problem
Pseudocode:
The error occurs on https://github.com/Qiskit/rustworkx/blob/eb896fbd88c8bd086379cd2d46b2a1f74981bc9e/rustworkx-core/src/distancemap.rs#L52 according to what is outputted.