Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c9a1839
fix: ensure tensors are on the correct device
tizianocitro Feb 3, 2026
7087427
fix: rename node features to x everywhere
tizianocitro Feb 3, 2026
5b26a72
feat: add unit tests for hdata on mps
tizianocitro Feb 4, 2026
34e94dc
fix: add default to ones for missing node features
tizianocitro Feb 4, 2026
bb68ccf
fix: add default to ones for missing node features
tizianocitro Feb 4, 2026
02d9b2c
fix: resolve conflicts
tizianocitro Feb 4, 2026
af6979d
feat: add sparse dropout
tizianocitro Feb 5, 2026
3713715
fix: remove flaky test
tizianocitro Feb 5, 2026
9ec1555
fix: add default to ones for missing node features
tizianocitro Feb 4, 2026
9f26c22
refactor: improve comment on node feature fallback
tizianocitro Feb 5, 2026
fedfaec
feat: add standard datasets (#27)
ddevin96 Feb 5, 2026
50d0723
feat: add graph structure
tizianocitro Feb 5, 2026
a4f405d
docs: update with news modules and update actions (#28)
ddevin96 Feb 5, 2026
b7c7031
fix: action syntax (#29)
ddevin96 Feb 5, 2026
0845806
feat: complete test for dataset (#30)
ddevin96 Feb 5, 2026
86539a5
feat: add standard datasets (#27)
ddevin96 Feb 5, 2026
e94d6b8
Merge branch 'main' into feat/first-model
tizianocitro Feb 5, 2026
ae16099
feat: add hypergraph structure
tizianocitro Feb 6, 2026
f04bb0e
refactor: move hif_test to hif_utils_test
tizianocitro Feb 6, 2026
d82b11c
refactor: move tests to parametrized with pytest.param for better rea…
tizianocitro Feb 6, 2026
d8989a1
feat: add graph utils and partial unit testing
tizianocitro Feb 6, 2026
5179631
feat: add unit tests for get_sparse_normalized_degree_matrix
tizianocitro Feb 6, 2026
5e3b560
feat: add unit tests for get_sparse_normalized_laplacian
tizianocitro Feb 6, 2026
48ddd62
feat: add unit tests for smoothing_with_gcn_laplacian_matrix
tizianocitro Feb 6, 2026
9ff0861
feat: add unit tests for to_undirected_edge_index
tizianocitro Feb 6, 2026
9800132
refactor: move methods to graph class
tizianocitro Feb 6, 2026
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
22 changes: 12 additions & 10 deletions hyperbench/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import requests

from enum import Enum
from typing import Any, Dict, List, Optional, Tuple, Union
from typing import Any, Dict, List, Optional, Tuple
from torch import Tensor
from torch.utils.data import Dataset as TorchDataset
from hyperbench.types.hypergraph import HIFHypergraph
from hyperbench.types.hdata import HData
from hyperbench.types import HData, HIFHypergraph
from hyperbench.utils.hif_utils import validate_hif_json


Expand Down Expand Up @@ -137,14 +136,14 @@ def __getitem__(self, index: int | List[int]) -> HData:
sampled_edge_index, sampled_node_ids, sampled_edge_ids
)

new_node_features = self.hdata.x[sampled_node_ids]
new_x = self.hdata.x[sampled_node_ids]

new_edge_attr = None
if self.hdata.edge_attr is not None and len(sampled_edge_ids) > 0:
new_edge_attr = self.hdata.edge_attr[sampled_edge_ids]

return HData(
x=new_node_features,
x=new_x,
edge_index=new_edge_index,
edge_attr=new_edge_attr,
num_nodes=len(sampled_node_ids),
Expand Down Expand Up @@ -185,8 +184,9 @@ def process(self) -> HData:
]
)
else:
# Fallback to zeros if no numeric attributes
x = torch.zeros((num_nodes, 1), dtype=torch.float)
# Fallback to ones if no node features, 1 is better as it can help during
# training (e.g., avoid zero multiplication), especially in first epochs
x = torch.ones((num_nodes, 1), dtype=torch.float)

# remap node and edge IDs to 0-based contiguous IDs
# Use dict comprehension for faster lookups
Expand Down Expand Up @@ -322,7 +322,7 @@ def __sample_edge_index(
node_ids = edge_index[0]
edge_ids = edge_index[1]

sampled_node_ids = torch.tensor(sampled_node_ids_list)
sampled_node_ids = torch.tensor(sampled_node_ids_list, device=node_ids.device)

# Find incidences where the node is in our sampled node set
# Example: edge_index[0] = [0, 0, 1, 2, 3, 4], sampled_node_ids = [0, 3]
Expand Down Expand Up @@ -405,9 +405,11 @@ def __to_0based_ids(
Returns:
Tensor of 0-based ids.
"""
id_to_0based_id = torch.zeros(n, dtype=torch.long)
device = original_ids.device

id_to_0based_id = torch.zeros(n, dtype=torch.long, device=device)
n_ids_to_keep = len(ids_to_keep)
id_to_0based_id[ids_to_keep] = torch.arange(n_ids_to_keep)
id_to_0based_id[ids_to_keep] = torch.arange(n_ids_to_keep, device=device)
return id_to_0based_id[original_ids]


Expand Down
8 changes: 4 additions & 4 deletions hyperbench/data/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ def __batch_node_features(self, batch: List[HData]) -> Tuple[Tensor, int]:
Returns:
Tensor: Concatenated node features with shape (total_nodes, num_features).
"""
per_sample_node_features = [data.x for data in batch]
per_sample_x = [data.x for data in batch]

# Stack all nodes along the node dimension from all samples into a single tensor
batched_node_features = torch.cat(per_sample_node_features, dim=0)
total_nodes = batched_node_features.size(0)
batched_x = torch.cat(per_sample_x, dim=0)
total_nodes = batched_x.size(0)

return batched_node_features, total_nodes
return batched_x, total_nodes

def __batch_edges(self, batch: List[HData]) -> Tuple[Tensor, Optional[Tensor], int]:
"""Batches hyperedge indices and attributes, adjusting indices for concatenated nodes.
Expand Down
4 changes: 2 additions & 2 deletions hyperbench/tests/data/dataset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ class TestDataset(Dataset):


def test_process_with_no_node_attributes_fallback():
"""Test process() falls back to torch zeros when no numeric attributes."""
"""Test process() falls back to torch ones when no node features."""
mock_hypergraph = HIFHypergraph(
network_type="undirected",
nodes=[
Expand All @@ -746,7 +746,7 @@ class TestDataset(Dataset):
dataset = TestDataset()

assert dataset.hdata.x.shape == (2, 1)
assert torch.allclose(dataset.hdata.x, torch.tensor([[0.0], [0.0]]))
assert torch.allclose(dataset.hdata.x, torch.tensor([[1.0], [1.0]]))


def test_process_with_single_node_attribute():
Expand Down
Loading