question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Additional option for `torch_geometric.utils.subgraph`

See original GitHub issue

🚀 The feature, motivation and pitch

I’ve come across dropout_node again and I found an unexpected behavior for this function. For an example provided in the doc-string:

        >>> edge_index = torch.tensor([[0, 1, 1, 2, 2, 3],
        ...                            [1, 0, 2, 1, 3, 2]])
        >>> edge_index, edge_mask, node_mask = dropout_node(edge_index)
        >>> edge_index
        tensor([[0, 1],
                [1, 0]])
        >>> edge_mask
        tensor([ True,  True, False, False, False, False])
        >>> node_mask
        tensor([ True,  True, False, False])

Actually, we need to remove all edges that contained the dropped nodes [0, 1], but subgraph only drops edges that both ends are in the subset [0,1]: https://github.com/pyg-team/pytorch_geometric/blob/081a964638459d1374f2e90de8ccfc9f0ea1f043/torch_geometric/utils/subgraph.py#L98

So in this case it should be | rather than & in the above code? Should we add an additional option to support this?

Alternatives

Add an option for subgraph to support | rather than & in some cases. https://github.com/pyg-team/pytorch_geometric/blob/081a964638459d1374f2e90de8ccfc9f0ea1f043/torch_geometric/utils/subgraph.py#L98

Additional context

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
rusty1scommented, Oct 3, 2022

Sorry for the confusion. Don’t we already do this?

edge_mask = node_mask[edge_index[0]] & node_mask[edge_index[1]] 

only maintains the edges for which both endpoints are in the non-dropped node set.

0reactions
EdisonLeeeeecommented, Oct 3, 2022

Oh you are right, my bad. Everything looks okay, sorry for the wasted time here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

torch_geometric.utils — pytorch_geometric documentation
Computes the induced subgraph of edge_index around all nodes in node_idx reachable within k ... See the documentation of torch-scatter for more information....
Read more >
torch_geometric.utils.subgraph - PyTorch Geometric
Source code for torch_geometric.utils.subgraph ... optional): If set to :obj:`True`, will return the edge mask to filter out additional edge features.
Read more >
torch_geometric.utils — pytorch_geometric 2.0.1 documentation
Computes the k -hop subgraph of edge_index around node node_idx . homophily. The homophily of a graph characterizes how likely nodes with the...
Read more >
torch_geometric.utils.subgraph — pytorch_geometric 1.3.2 ...
Source code for torch_geometric.utils.subgraph. import torch from .num_nodes import maybe_num_nodes. [docs]def subgraph(subset, edge_index, edge_attr=None, ...
Read more >
torch_geometric.utils.subgraph — pytorch_geometric 2.0.1 ...
Source code for torch_geometric.utils.subgraph. import torch from .num_nodes import maybe_num_nodes. [docs]def subgraph(subset, edge_index, edge_attr=None, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found