Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add NeighborLoader #497

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

feat: add NeighborLoader #497

wants to merge 17 commits into from

Conversation

askorupka
Copy link
Collaborator

This PR adds NeighborLoader functionality for big graphs.
This is similar to https://pytorch-geometric.readthedocs.io/en/latest/tutorial/neighbor_loader.html

PR with documentation will follow.

@askorupka
Copy link
Collaborator Author

Hi @CarloLucibello I just wanted to check if it's ok to add Graphs to deps instead of weakdeps, or do you see any better solutions instead.
I need it to use Graphs.neighbors function in graph subsampling.

GraphNeuralNetworks/src/samplers.jl Outdated Show resolved Hide resolved
GraphNeuralNetworks/src/samplers.jl Outdated Show resolved Hide resolved
GraphNeuralNetworks/src/samplers.jl Outdated Show resolved Hide resolved
end
end

function induced_subgraph(graph::GNNGraph, nodes::Vector{Int})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a generically useful function, this should go into GNNGraphs.jl, be documented and exported, possibly in a separate PR.

Moreover, since Graphs.jl defines this interface, we should overload Graphs.induced_interface.

Notice that we already have the very similar function sample_neighbors in GNNGraphs.jl. Let's implement induced_interface as well in order to be Graphs.jl compliant. At some point we could merge the two functionalities though.

Copy link
Collaborator Author

@askorupka askorupka Sep 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opened another PR #499

return backup_gnn # Return empty graph if no nodes are provided
end

return GNNGraph(source, target, ndata = new_features) # Return the new GNNGraph with subgraph and features
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The returned graph should inherit all the node and the edge features from the original graph.
you can get them through getobs(graph.ndata, node_ids) and getobs(graph.edata, edge_ids).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid this is not working, I also don't see docs about this method

julia> getobs(g.ndata, 1)
ERROR: UndefVarError: `getobs` not defined
Stacktrace:
 [1] top-level scope
   @ REPL[8]:1

end

# Extract features for the new nodes
new_features = graph.x[:, nodes]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you shouldn't assume that a graph has node features named x

src/samplers.jl Outdated Show resolved Hide resolved
@CarloLucibello
Copy link
Owner

Hi @CarloLucibello I just wanted to check if it's ok to add Graphs to deps instead of weakdeps, or do you see any better solutions instead.
I need it to use Graphs.neighbors function in graph subsampling.

It is fine, Graphs.jl is already a dependence through GNNGraphs.jl

@askorupka
Copy link
Collaborator Author

Now dependent on & blocked by #499

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