Skip to content

PartitionedGraphs extension for DataGraphs and interface overhaul. #55

Merged
mtfishman merged 60 commits intoITensor:mainfrom
jack-dunham:partitions
Feb 6, 2026
Merged

PartitionedGraphs extension for DataGraphs and interface overhaul. #55
mtfishman merged 60 commits intoITensor:mainfrom
jack-dunham:partitions

Conversation

@jack-dunham
Copy link
Contributor

@jack-dunham jack-dunham commented Nov 24, 2025

This PR introduces a change to the DataGraphs interface. Data on an AbstractDataGraph can be queried with the functions getindex, setindex!, isassigned and unsetindex!. To customize the behavior of these function for a custom subtype of AbstractGraph, one should overload the following:

underlying_graph(::AbstractDataGraph) = not_implemented()

is_vertex_assigned(::AbstractDataGraph, vertex) = not_implemented()
is_edge_assigned(::AbstractDataGraph, edge) = not_implemented()

get_vertex_data(::AbstractDataGraph, vertex) = not_implemented()
get_edge_data(::AbstractDataGraph, edge) = not_implemented()

set_vertex_data!(::AbstractDataGraph, data, vertex) = not_implemented()
set_edge_data!(::AbstractDataGraph, data, edge) = not_implemented()

This a bit more verbose than just having a function vertex_data etc that returns a mutable dictionary, but I think it is ultimately more generic. The return value of vertex_data etc is now constructed on the fly, so doing setindex!(vertex_data(g), val, vertex) will not modify the underlying graph.

The benefit of this change is that one no longer require the data on the vertices and edges to be stored as a mutable field; it can be generated on the fly. This then results in constant behavior when defining views of vertex/edge data. One can still use a mutable dictionary to store the data for a given concrete AbstractDataGraph subtype.

DataGraphsPartitionedGraphsExt

This package extension (currently existing as a library in DataGraphs while PartitionedGraphs is a library of NamedGraphs) defines notions of getting data of partitioned and quotient graphs. By default, all index types that can be converted to collections of indices (e.g. QuotientVertex, QuotientVertices, QuotientEdgeEdges) returns subgraphs when using the getindex syntax, inline with the behavior of NamedGraphs. If one wishes to define separate data on the quotient graph on their custom partitioned data graph (this could be separate memory entirely, or data derived from the underlying graph), then one must overload the following:

# Turn off subgraphing for quotient vertices by defining:
NamedGraphs.to_graph_index(::MyGraph, qv::QuotientVertex) = qv

# Customize the behavior of this method:
DataGraphs.get_index_data(graph::MyGraph, qv::QuotientVertex) = ...

# And this method
DataGraphs.is_graph_index_assigned(graph::MyGraph, qv::QuotientVertex) = ...

and similarly for the QuotientEdge methods (if desired). One can also overload:

DataGraphs.set_index_data!(graph::MyGraph, val, qv::QuotientVertex) = ...

to define notions of setting/unsetting data on the quotient vertices. Again, similar methods can be defined for QuotientEdge.

Other Changes

  • AbstractDataGraph now subtypes AbstractNamedGraph. This greatly reduces required method overloads.
  • Added VertexDataView and EdgeDataView objects that behave like dictionaries with respect to the graph data.
  • Added a library extension for the PartitionedGraphs package.

Closes #57, closes #58, closes #59, closes #60, closes #61, closes #62.

@jack-dunham jack-dunham marked this pull request as draft November 24, 2025 23:03
…btype `AbstractNamedGraph`

- Interface now no longer assumes vertex and edge date stored as mutable
field. Instead, requires overloading setters and getters.
- Subtyping `AbstractNamedGraph` cuts down on the method forwarding
almost entirely.
…Graph`

Tests have been adjusted accordingly.
… `getindex`

This now correctly mirrors `DataGraphs` interface.
This is in anticipation of making this change in `DataGraphs`
These are defined on the abstract type
@jack-dunham jack-dunham changed the title PartitionedGraphs extension for DataGraphs. PartitionedGraphs extension for DataGraphs and interface overhaul. Jan 9, 2026
@jack-dunham jack-dunham marked this pull request as ready for review January 9, 2026 21:34
@mtfishman mtfishman closed this Jan 12, 2026
@mtfishman mtfishman reopened this Jan 12, 2026
@mtfishman
Copy link
Member

(I closed and reopened the PR to trigger the tests since NamedGraphs.jl v0.9 is now registered.)

@jack-dunham
Copy link
Contributor Author

Ive accidentally committed a notebook. Let me fix the history.

@mtfishman
Copy link
Member

Ive accidentally committed a notebook. Let me fix the history.

I think the history of the main branch should be ok as long as it is deleted by the time the PR is merged since we always squash and merge so the main branch should only see the final PR state as a commit in the history.

@jack-dunham
Copy link
Contributor Author

Doing the rebase is good git-fu practice for me...

@mtfishman mtfishman marked this pull request as ready for review February 6, 2026 22:29
@mtfishman mtfishman merged commit 94155f9 into ITensor:main Feb 6, 2026
12 of 14 checks passed
@mtfishman
Copy link
Member

Thanks again! Having a carefully thought-out interface here will be very helpful as a basis for a lot of future work.

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.

2 participants