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

Fix: VirtualNode mistakenly treats node features as edge features #5819

Merged
merged 3 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `BaseStorage.get()` functionality ([#5240](https://github.com/pyg-team/pytorch_geometric/pull/5240))
- Added a test to confirm that `to_hetero` works with `SparseTensor` ([#5222](https://github.com/pyg-team/pytorch_geometric/pull/5222))
### Changed
- Fixed a bug in which `VirtualNode` mistakenly treated node features as edge features ([#5819](https://github.com/pyg-team/pytorch_geometric/pull/5819))
- Fixed `setter` and `getter` handling in `BaseStorage` ([#5815](https://github.com/pyg-team/pytorch_geometric/pull/5815))
- Fixed `path` in `hetero_conv_dblp.py` example ([#5686](https://github.com/pyg-team/pytorch_geometric/pull/5686))
- Fix `auto_select_device` routine in GraphGym for PyTorch Lightning>=1.7 ([#5677](https://github.com/pyg-team/pytorch_geometric/pull/5677))
Expand Down
16 changes: 11 additions & 5 deletions torch_geometric/transforms/virtual_node.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import copy

import torch
from torch import Tensor

Expand Down Expand Up @@ -35,22 +37,26 @@ def __call__(self, data: Data) -> Data:
new_type = edge_type.new_full((num_nodes, ), int(edge_type.max()) + 1)
edge_type = torch.cat([edge_type, new_type, new_type + 1], dim=0)

for key, value in data.items():
old_data = copy.copy(data)
for key, value in old_data.items():
if key == 'edge_index' or key == 'edge_type':
continue

if isinstance(value, Tensor):
dim = data.__cat_dim__(key, value)
dim = old_data.__cat_dim__(key, value)
size = list(value.size())

fill_value = None
if key == 'edge_weight':
size[dim] = 2 * num_nodes
fill_value = 1.
elif data.is_edge_attr(key):
elif key == 'batch':
size[dim] = 1
fill_value = int(value[0])
elif old_data.is_edge_attr(key):
size[dim] = 2 * num_nodes
fill_value = 0.
elif data.is_node_attr(key):
elif old_data.is_node_attr(key):
size[dim] = 1
fill_value = 0.

Expand All @@ -62,6 +68,6 @@ def __call__(self, data: Data) -> Data:
data.edge_type = edge_type

if 'num_nodes' in data:
data.num_nodes = data.num_nodes + 1
data.num_nodes = old_data.num_nodes + 1

return data