Skip to content

Add a distance cutoff to Dijkstra path lengths - #1702

Open
Ge Li (galleonli) wants to merge 1 commit into
Qiskit:mainfrom
galleonli:feature/dijkstra-distance-cutoff
Open

Ge Li (galleonli) wants to merge 1 commit into
Qiskit:mainfrom
galleonli:feature/dijkstra-distance-cutoff

Conversation

@galleonli

Copy link
Copy Markdown

Fixes #1674.

Add an optional cutoff to dijkstra_shortest_path_lengths and its graph/digraph variants. The boundary is inclusive, including zero-cost paths when the cutoff is zero. A goal beyond the cutoff returns an empty mapping. Negative and NaN cutoffs raise ValueError.

The bounded path uses the existing Rust Dijkstra traversal, with a Rust visitor that stops when the next finalized distance exceeds the cutoff. It records results in a sparse mapping rather than allocating and scanning a graph-sized distance array. This avoids Python visitor callbacks; the edge-cost callable still runs in Python. Omitting the cutoff keeps the existing Dijkstra implementation. No Rust core API changes are needed.

Local validation on macOS arm64: the Python suite passed with 2,390 tests and 20 skips. Another 16,800 queries on 800 seeded multigraphs matched NetworkX, covering directed and undirected graphs, removed nodes, parallel edges, zero weights, and goals. Rust workspace tests, strict Clippy, stubtest, Ruff, rustfmt and the Rust core documentation build passed.

In same-environment release-build comparisons, a 100,000-node path queried to distance 10 took about 1.14 µs, versus 4.08 µs with a Python visitor. A 200-by-200 grid queried to distance 8 took 15.5 µs versus 84.6 µs. These are synthetic graph-query timings, not application benchmarks. Unbounded calls measured 3–7% slower across the two builds, despite retaining the original algorithm; this remains a performance limitation of the current patch. The existing node-bound visit bitset is also retained, so the query does not use strictly radius-only memory.

Codex assisted with implementation, tests, benchmarking, and this description.

@CLAassistant

CLAassistant commented Nov 2, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support distance cutoff in Dijkstra shortest-path searches

2 participants