Repository navigation
55 local bridges - #158
Open
eriknw wants to merge 1 commit into
Open
55 local bridges#158eriknw wants to merge 1 commit into
eriknw wants to merge 1 commit into
Conversation
A local bridge is an edge whose two ends share no neighbor. They are the edges of the strict upper triangle where a masked A @ A has no entry; A keeps its self-loops, so a node with one is its own neighbor, as in NetworkX. Each pair comes with its end first in node order first, as G.edges gives it, and the pairs come in node order of both ends. A span is the shortest length between the two ends without their edge. Spans are computed for a batch of edges at a time as the generator is read, a row per edge, each row started from the first end's other neighbors with that end taken as reached. Without a weight this is a breadth-first search that stops at the other end. With a weight it is Bellman-Ford over lengths that changed and are still below the other end's length so far. Weights are served when they are Python ints or floats, at least 0 and finite, and ints while no length can reach 2**63; other weights, and weight functions, are left to NetworkX. A batch holds as many rows as its memory allows, at the bytes a row takes per node at a batch's peak, measured for each kind of row. The rows filled so far are held as a bitmap once more than 1% full: held sparse, they were copied at each update, and a random tree of 20000 nodes, where each row searches a whole side, peaked at 1.7 GiB without weights and 3.3 GiB with them. It now peaks at 0.2 and 0.3 GiB. Values a matrix cannot hold, such as strings, are declined at the conversion, so NetworkX answers without spans, as it reads no weight then, and with spans raises as its generator is read.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 61-generic-declines #158 +/- ##
=======================================================
+ Coverage 92.90% 93.12% +0.21%
=======================================================
Files 182 185 +3
Lines 11294 11632 +338
Branches 1281 1313 +32
=======================================================
+ Hits 10493 10832 +339
Misses 547 547
+ Partials 254 253 -1 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
local_bridges. A local bridge is an edge whose two ends share no neighbor. Its span is the length of the shortest path between its ends once the edge is taken away, or inf where there is none.Which edges: those of the strict upper triangle where a masked
A @ Ahas no entry.Akeeps its self-loops, so no edge at a node with a self-loop is a local bridge, and no self-loop is one. NetworkX intersects the two ends' neighbor sets, and a self-loop puts a node in its own.What comes out:
(u, v, span)whenwith_span is True, and(u, v)otherwise. As in NetworkX,with_span=1ornp.True_gives pairs.Order: the first end of each pair is the one that comes first in the graph's node order, as
G.edgesgives it. Pairs come by their first end and then by their second, both in node order. NetworkX goes by each node's adjacency order instead, so the order can differ. On 3600 random graphs it differed in 2430, while the pairs and spans were the same in all of them.It returns a generator, as NetworkX does. A call that is declined is declined at the call, where NetworkX's dispatcher can still hand it to NetworkX. The graph is read at the call, and the spans are computed for a batch of edges at a time as the generator is read. NetworkX reads the graph while its generator runs, so a change made to the graph in the meantime shows in NetworkX's answer, or raises RuntimeError there, but not here.
Spans without a weight: a breadth-first search per edge, one row per edge in a batch. Each row starts from the first end's other neighbors, with the first end already taken as reached, so the edge itself is never walked. A row stops when it reaches the second end.
Spans with a weight: Bellman-Ford rows, started the same way. A row walks on only from lengths that changed and are still below its second end's length so far. NetworkX's Dijkstra and this both give the least sum over paths, added from the first end. Float addition is monotone, so the float spans are the same floats, not only close.
Memory: a batch holds as many rows as 1 GiB allows, at the bytes a row may take per node of the graph at a batch's peak: 32 for breadth-first rows and 96 for Bellman-Ford rows. These are twice or more what was measured at 20000 nodes, on a random tree, where a row searches a whole side, and on random bipartite graphs, whose frontiers are wide: up to 8.5 and 45.3 bytes, with rows reaching about half the nodes. The rows filled so far are held as a bitmap once more than 1% full. Held sparse, they were copied at each update: on the 20000-node random tree the spans peaked at 1.7 GiB without weights and 3.3 GiB with int weights. They now peak at 251 MiB, and at 294 MiB with weights.
Weights served: Python ints or floats, which convert to an int64 or float64 matrix, that are at least 0 and finite. Ints are served while the number of nodes times the largest weight stays below 2**62. A missing weight is 1, as in NetworkX, and when every weight is the int 1 the spans are hop counts.
Weights left to NetworkX:
Ints mixed with floats: the matrix holds floats, so a span over ints only is 3.0 here and 3 in NetworkX. The values are equal. In 137 of 600 random graphs with such a mix, at least one span differed in type this way.
Errors: directed graphs and multigraphs raise NetworkXNotImplemented in NetworkX before dispatch, and a directed backend graph raises the same here.
Speed (indicative; median of five interleaved rounds on a shared machine at a one-minute load of 15 to 19, conversion included):
with_span=FalseIn a tree every span is inf, and each row searches the whole of its first end's side. On the weighted grid the spans are short, and the time goes to the number of batches: at 90000 nodes the memory bound holds a batch to 124 rows, about 1450 batches. With
with_span=Falsethe conversion is most of the time: 0.55 s with it cached. This is faster at every size measured, so there is no size gate.Stacked on #156.