Skip to content

31 node attrs - #130

Open
eriknw wants to merge 1 commit into
python-graphblas:26-overflow-fallbackfrom
eriknw:31-node-attrs
Open

eriknw wants to merge 1 commit into
python-graphblas:26-overflow-fallbackfrom
eriknw:31-node-attrs

Conversation

@eriknw

@eriknw eriknw commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Serve attribute_assortativity_coefficient, numeric_assortativity_coefficient, attribute_mixing_matrix, attribute_mixing_dict and node_attribute_xy. NetworkX asks the conversion for the node attribute these names read (node_attrs="attribute"), and the conversion refused every request for node attributes, so they always fell back. It now carries the named attribute for these names only: each node's value, numbered as a dict keys it (1, 1.0 and True are one value, as in NetworkX's counts). The value pairs along the edges are counted in two sparse products, and the answers come from those counts.

  • Floats agree with NetworkX's within rounding, not bit for bit. Both coefficients are taken from the counts in float64. attribute_assortativity_coefficient is (trace - a . b) / (1 - a . b) of the pairs' joint distribution, as NetworkX's attribute_ac computes it from a dense matrix; over the tests' graphs and values it was within 9.7e-16 of NetworkX's. numeric_assortativity_coefficient is the Pearson correlation of the pairs whose two values are held by nodes in nodes, with the moments taken about the means; it was within 2.2e-16 of the correlation computed exactly from NetworkX's pairs. Neither has a limit on the number of distinct values now.
  • Where NetworkX squares ints past about 3e9, it does so in int64, which wraps, and its numeric coefficient is wrong; here the values are floats and the coefficient is the true one. So 240 and 2.040, one value, give one answer whichever of them the first node of nodes holds, where NetworkX's changes.
  • Counts and pairs are exact. Orders NetworkX leaves arbitrary are not kept: without mapping, NetworkX numbers the values of attribute_mixing_matrix as a set of them iterates; here they are numbered in the order nodes first hold them, with None for a missing value last unless a node holds None. attribute_mixing_dict has NetworkX's keys and counts, its keys in another order, and node_attribute_xy yields NetworkX's pairs edge by edge as the matrix stores them, not along each node's adjacency. With a mapping, the matrix is NetworkX's.
  • A node without the attribute counts as None, as in NetworkX's mixing; numeric_assortativity_coefficient raises KeyError for it, as NetworkX does
  • Left to NetworkX: multigraphs; a graph class with its own adjacency or nodes, as the conversion reads the graph's own adjacency and node data; an attribute that is None, callable or unhashable; values no dict can key (lists); for numeric_assortativity_coefficient, values that are not real numbers, where NetworkX raises, and an iterator nodes, which NetworkX reads twice
  • Other names still have node attributes refused, as does a request for node and edge attributes together. A conversion carrying an attribute is reused by names that ask for none
  • The conversion for these names builds the structural matrix in one pass over the adjacency rather than through scipy; the matrix is the same. It no longer records the order of each node's neighbors
  • Not served: the bipartite projections, which return graphs keeping node data
  • The additional_docs notes say how values are numbered and what is left to NetworkX
  • Views: until 27 stale views #128 is in, a view converted for these names answers from that conversion after the graph under it changes, as other names do on this base; before, NetworkX answered these names on views. Once 27 stale views #128 is in, the node-attribute conversion registers its source as the other conversions do, and a view follows its graph
  • A value written in place after a call (G.nodes[n]["a"] = x) is not seen, since it empties no NetworkX cache, as for edge data; nx.set_node_attributes, add_node, add_edge and remove_node are seen
  • Speed on G(1e5, 1e6) with five int values, graphblas first in the backend priority, on a graph already converted (NetworkX caches the conversion), against the base of this change: attribute_assortativity_coefficient 5.3 ms where it took 13.4, attribute_mixing_matrix 4.9 where 13.2, numeric_assortativity_coefficient 5.1 as before, and, newly served, attribute_mixing_dict 5.0 ms where NetworkX took 820 and list(node_attribute_xy(...)) 144 where NetworkX took 743. Medians of five calls in each of three interleaved rounds. Indicative, load 8 to 11. Peak memory stayed under 0.8 GB

Stacked on #126.

NetworkX asks the conversion for the node attribute that
attribute_assortativity_coefficient, numeric_assortativity_coefficient,
attribute_mixing_matrix, attribute_mixing_dict and node_attribute_xy
read, and the conversion refused every request for node attributes, so
they always fell back. It now carries the named attribute for the names
that read one: each value numbered as a dict keys it, and a node
without it read as None, as NetworkX's mixing reads it. Other names
still have node attributes refused.

The value pairs along the edges are counted with GraphBLAS. The
coefficients come from the counts in float64, within rounding of
NetworkX's, for any number of values; where NetworkX squares ints past
about 3e9 in int64, which wraps, the numeric coefficient is the true
one. NetworkX meets the values along each node's neighbors, in the
order the edges were added, which a matrix does not keep. Without a
mapping the mixing matrix numbers them in the order nodes first hold
them, where NetworkX's numbering is a set's arbitrary order, and the
mixing dict's keys and node_attribute_xy's pairs come in the matrix's
order. A graph class with its own adjacency or nodes, an attribute that
is None, callable or unhashable, and values no dict can key are left
to NetworkX.
@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.86885% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.73%. Comparing base (4dca4dc) to head (71111ea).

Additional details and impacted files
@@                   Coverage Diff                    @@
##           26-overflow-fallback     #130      +/-   ##
========================================================
+ Coverage                 93.47%   93.73%   +0.25%     
========================================================
  Files                       194      196       +2     
  Lines                     12466    13062     +596     
  Branches                   1444     1522      +78     
========================================================
+ Hits                      11653    12244     +591     
- Misses                      555      560       +5     
  Partials                    258      258              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant