Skip to content

Refactor TGB Mock in Tests - #76

Merged
Jacob-Chmura merged 7 commits into
mainfrom
refactor/tgb_mock
Jul 2, 2025
Merged

Refactor TGB Mock in Tests#76
Jacob-Chmura merged 7 commits into
mainfrom
refactor/tgb_mock

Conversation

@Jacob-Chmura

@Jacob-Chmura Jacob-Chmura commented Jun 27, 2025

Copy link
Copy Markdown
Member

Purpose

The purpose of this PR is to refactor the TGB mock dataset objects in our DGData.from_tgb unit tests.

Key Changes

  • I did catch a bug in the from_tgb when working with NodeProp datasets, which occurs if there are no node events within a dataset split (e.g. no node features in validation set):

I guarded this accordingly:

tgm/tgm/data.py

Lines 415 to 438 in 968ed03

if len(node_label_dict):
# Node events could be missing from the current data split (e.g. validation)
num_node_events = 0
node_label_dim = 0
for t in node_label_dict:
for node_id, label in node_label_dict[t].items():
num_node_events += 1
node_label_dim = label.shape[0]
temp_node_timestamps = np.zeros(num_node_events, dtype=np.int64)
temp_node_ids = np.zeros(num_node_events, dtype=np.int64)
temp_dynamic_node_feats = np.zeros(
(num_node_events, node_label_dim), dtype=np.float32
)
idx = 0
for t in node_label_dict:
for node_id, label in node_label_dict[t].items():
temp_node_timestamps[idx] = t
temp_node_ids[idx] = node_id
temp_dynamic_node_feats[idx] = label
idx += 1
node_timestamps = torch.from_numpy(temp_node_timestamps).long()
node_ids = torch.from_numpy(temp_node_ids).long()
dynamic_node_feats = torch.from_numpy(temp_dynamic_node_feats).float()

Relevant Prs

Close #70

@Jacob-Chmura Jacob-Chmura self-assigned this Jun 27, 2025
@Jacob-Chmura
Jacob-Chmura changed the base branch from main to dev/time_id_remap June 27, 2025 13:59
Comment thread test/test_data.py
val_indices = np.arange(num_train, num_train + num_val)
test_indices = np.arange(num_train + num_val, num_events)
@pytest.fixture
def tgb_dataset_factory():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nice and clean

Comment thread test/test_data.py
val_mask = np.zeros(num_events, dtype=bool)
val_mask[val_indices] = True
def test_from_tgbl(mock_dataset_cls, tgb_dataset_factory, split, with_node_feats):
dataset = tgb_dataset_factory(split, with_node_feats)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nice

Base automatically changed from dev/time_id_remap to main July 2, 2025 19:25
@Jacob-Chmura
Jacob-Chmura merged commit de226fb into main Jul 2, 2025
4 of 5 checks passed
@Jacob-Chmura
Jacob-Chmura deleted the refactor/tgb_mock branch July 2, 2025 19:31
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.

Clean up and Properly Mock TGB Dataset Objects

2 participants