Skip to content

Conversation

@FilippoOlivo
Copy link
Member

Fixes #521

@FilippoOlivo FilippoOlivo self-assigned this Mar 24, 2025
@FilippoOlivo FilippoOlivo added bug Something isn't working high priority Higher priority pr-to-review Label for PR that are ready to been reviewed labels Mar 24, 2025
@GiovanniCanali
Copy link
Collaborator

Hi @FilippoOlivo!
I have noticed you are removing self loops when building the RadiusGraph. In order to be compliant with pyg, I suggest to handle this through a boolean attribute loop. If True, the graph will contain self loops.

See here for reference: https://pytorch-geometric.readthedocs.io/en/latest/generated/torch_geometric.nn.pool.radius_graph.html#torch_geometric.nn.pool.radius_graph

What do you think, @dario-coscia?

@dario-coscia
Copy link
Collaborator

Hi @FilippoOlivo! I have noticed you are removing self loops when building the RadiusGraph. In order to be compliant with pyg, I suggest to handle this through a boolean attribute loop. If True, the graph will contain self loops.

See here for reference: https://pytorch-geometric.readthedocs.io/en/latest/generated/torch_geometric.nn.pool.radius_graph.html#torch_geometric.nn.pool.radius_graph

What do you think, @dario-coscia?

yes maybe it is the best option!

@FilippoOlivo FilippoOlivo added pr-to-fix Label for PR that needs modification and removed pr-to-review Label for PR that are ready to been reviewed labels Mar 24, 2025
@FilippoOlivo FilippoOlivo changed the title Fix RadiusGraph Self-loops management in KNNGraph and RadiusGraph Mar 25, 2025
@FilippoOlivo FilippoOlivo added pr-to-review Label for PR that are ready to been reviewed and removed pr-to-fix Label for PR that needs modification labels Mar 25, 2025
@FilippoOlivo
Copy link
Member Author

Since the codacy warning is "intentional" and unavoidable in our case, I suggest to manually suppress it. @ndem0 @dario-coscia what do you think?

Copy link
Collaborator

@dario-coscia dario-coscia left a comment

Choose a reason for hiding this comment

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

I don't like a lot the fact that loop is hard coded for both methods. I suggest to add the loop attribute in GraphBuilder __new__ method and use the PyG function remove_self_loops once the edge_index is created. This way you just need to touch GraphBuilder

@FilippoOlivo
Copy link
Member Author

I don't like a lot the fact that loop is hard coded for both methods. I suggest to add the loop attribute in GraphBuilder __new__ method and use the PyG function remove_self_loops once the edge_index is created. This way you just need to touch GraphBuilder

A possible inconsistency arises with KNNGraph. K should include or not self loops?

@dario-coscia
Copy link
Collaborator

I don't like a lot the fact that loop is hard coded for both methods. I suggest to add the loop attribute in GraphBuilder __new__ method and use the PyG function remove_self_loops once the edge_index is created. This way you just need to touch GraphBuilder

A possible inconsistency arises with KNNGraph. K should include or not self loops?

Why inconsistency? I would say that K is the number of points close to a reference point (and including the reference point), then if loop is False this is K-1. This way the behaviour should be similar to radius graph right?

@dario-coscia dario-coscia changed the base branch from master to dev March 31, 2025 14:32
@dario-coscia dario-coscia removed the request for review from ndem0 March 31, 2025 14:53
@dario-coscia dario-coscia merged commit 12291b0 into mathLab:dev Mar 31, 2025
18 of 19 checks passed
@dario-coscia
Copy link
Collaborator

Everything looks good to me, I merge in dev.

dario-coscia pushed a commit that referenced this pull request Apr 4, 2025
* Add self-loop option to RadiusGraph and KNNGraph
dario-coscia pushed a commit that referenced this pull request Apr 8, 2025
* Add self-loop option to RadiusGraph and KNNGraph
dario-coscia pushed a commit that referenced this pull request Apr 14, 2025
* Add self-loop option to RadiusGraph and KNNGraph
FilippoOlivo added a commit to FilippoOlivo/PINA that referenced this pull request Apr 17, 2025
* Add self-loop option to RadiusGraph and KNNGraph
dario-coscia pushed a commit that referenced this pull request Apr 17, 2025
* Add self-loop option to RadiusGraph and KNNGraph
dario-coscia pushed a commit that referenced this pull request Apr 23, 2025
* Add self-loop option to RadiusGraph and KNNGraph
GiovanniCanali pushed a commit to GiovanniCanali/PINA that referenced this pull request Dec 2, 2025
* Add self-loop option to RadiusGraph and KNNGraph
GiovanniCanali pushed a commit to GiovanniCanali/PINA that referenced this pull request Dec 2, 2025
* Add self-loop option to RadiusGraph and KNNGraph
GiovanniCanali pushed a commit to GiovanniCanali/PINA that referenced this pull request Dec 2, 2025
* Add self-loop option to RadiusGraph and KNNGraph
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working high priority Higher priority pr-to-review Label for PR that are ready to been reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Self loops in RadiusGraph

3 participants