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

Hypergraph checks #249

Merged
merged 42 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a400565
allsets
Oct 30, 2023
2077aae
teamplate
Oct 30, 2023
eb524d9
template
Oct 30, 2023
81e8f74
7/10
Oct 31, 2023
fbbb5ab
hypersage left
Nov 2, 2023
77ab206
hypersage
Nov 2, 2023
f39174b
tutorials
Nov 5, 2023
18719d5
tests
Nov 6, 2023
6834282
hypergraphs
Nov 6, 2023
41c38a8
comments correction
Nov 6, 2023
66b3125
checked CCs
Nov 6, 2023
697fcfb
checked hp/ccs
Nov 6, 2023
a9856bd
no docker
Nov 6, 2023
e002b53
no docker
Nov 6, 2023
51ce579
conflict resolve
levtelyatnikov Nov 7, 2023
546008a
changed weight to none
levtelyatnikov Nov 7, 2023
19e7db3
changed weight to none
levtelyatnikov Nov 7, 2023
8d2273a
checking issue with dataset
levtelyatnikov Nov 7, 2023
9f8d034
checking issue with dataset
levtelyatnikov Nov 7, 2023
4592c28
checking issue with datat
levtelyatnikov Nov 7, 2023
aa6ed60
lint changes
levtelyatnikov Nov 7, 2023
d2a096f
lint changes
levtelyatnikov Nov 7, 2023
44e75ed
locally works
levtelyatnikov Nov 7, 2023
6621531
locally everything works
levtelyatnikov Nov 7, 2023
f362b7c
locally everything works
levtelyatnikov Nov 7, 2023
cbef409
add allsettr
levtelyatnikov Nov 7, 2023
5f44f6e
added allsettr
levtelyatnikov Nov 7, 2023
0a2161d
added allsettr
levtelyatnikov Nov 7, 2023
7b5ec25
added allsettr
levtelyatnikov Nov 7, 2023
c1df84e
new allsettr
levtelyatnikov Nov 7, 2023
6d53cd2
corrections
levtelyatnikov Nov 7, 2023
b745e70
corrections and black .
levtelyatnikov Nov 7, 2023
751aef8
allsettransformer once more
levtelyatnikov Nov 7, 2023
8d2ce7d
allsettransformer once more
levtelyatnikov Nov 7, 2023
98bc6ee
allsettransformer once more
levtelyatnikov Nov 7, 2023
86c28dc
Merge branch 'main' into hypergraph_checks
levtelyatnikov Nov 9, 2023
e1484f5
fix path
levtelyatnikov Nov 9, 2023
5a6cd25
fix path
levtelyatnikov Nov 9, 2023
f584f79
tests magic bug
levtelyatnikov Nov 9, 2023
630e185
fix cora path
levtelyatnikov Nov 9, 2023
ce0ee73
allsettransformer num_epochs=0
levtelyatnikov Nov 9, 2023
62513dc
fix bug with groupd
levtelyatnikov Nov 9, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/test_tutorials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
torch-version: [2.0.1]
include:
- torch-version: 2.0.1
test-group: [1, 2, 3, 4]
test-group: [1, 2, 3]

steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ coverage.xml
**/__pycache__/**
__pycache__/
docs/build/
data/
venv_*/

TopoNetX/
topomodelx/nn/cell/attcxn_layer.py
topomodelx/base/debug.ipynb
tutorials/hypergraph/citeseer6cls3703.pt.1
tutorials/hypergraph/cora
tags
tags
22 changes: 11 additions & 11 deletions .test_durations
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,18 @@
"test/tutorials/test_cell.py::test_tutorial[tutorials/cell/ccxn_train.ipynb]": 10.362705206964165,
"test/tutorials/test_cell.py::test_tutorial[tutorials/cell/cwn_train.ipynb]": 10.345093041891232,
"test/tutorials/test_combinatorial.py::test_tutorial[tutorials/combinatorial/hmc_train.ipynb]": 113.72826133295894,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/allset_train.ipynb]": 10.690549792023376,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/allset_transformer_train.ipynb]": 17.616297374945134,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/dhgcn_train.ipynb]": 47.93890062533319,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/hmpnn_train.ipynb]": 7.804051124723628,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/hnhn_train.ipynb]": 5.239491417305544,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/allset_train.ipynb]": 8.943679120042361,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/allset_transformer_train.ipynb]": 5.0502030230127275,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/dhgcn_train.ipynb]": 80.38319573295303,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/hmpnn_train.ipynb]": 5.240434563951567,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/hnhn_train.ipynb]": 5.292717668809928,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/hnhn_train_bis.ipynb]": 16.502087499015033,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/hypergat_train.ipynb]": 16.043949334183708,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/hypersage_train.ipynb]": 44.49209712515585,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/unigcn_train.ipynb]": 5.906059790868312,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/unigcnii_train.ipynb]": 19.70078912517056,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/unigin_train.ipynb]": 8.093902500113472,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/unisage_train.ipynb]": 8.754238750087097,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/hypergat_train.ipynb]": 16.28355930291582,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/hypersage_train.ipynb]": 8.78812964912504,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/unigcn_train.ipynb]": 6.283768973895349,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/unigcnii_train.ipynb]": 6.922894097981043,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/unigin_train.ipynb]": 6.994051485904492,
"test/tutorials/test_hypergraph.py::test_tutorial[tutorials/hypergraph/unisage_train.ipynb]": 4.923791292007081,
"test/tutorials/test_simplicial.py::test_tutorial[tutorials/simplicial/dist2cycle_train.ipynb]": 5.09599137515761,
"test/tutorials/test_simplicial.py::test_tutorial[tutorials/simplicial/hsn_train.ipynb]": 4.862493500346318,
"test/tutorials/test_simplicial.py::test_tutorial[tutorials/simplicial/san_train.ipynb]": 5.597147291759029,
Expand Down
2 changes: 1 addition & 1 deletion test/nn/cell/test_can.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_forward(self):
num_classes=1,
n_layers=2,
att_lift=False,
)
).to(device)

x_0 = torch.rand(2, 2)
x_1 = torch.rand(2, 2)
Expand Down
2 changes: 1 addition & 1 deletion test/nn/cell/test_ccxn.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_forward(self):
num_classes=1,
n_layers=2,
att=False,
)
).to(device)

x_0 = torch.rand(2, 2)
x_1 = torch.rand(2, 2)
Expand Down
2 changes: 1 addition & 1 deletion test/nn/cell/test_cwn.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_forward(self):
hid_channels=16,
num_classes=1,
n_layers=2,
)
).to(device)

x_0 = torch.rand(2, 2)
x_1 = torch.rand(2, 2)
Expand Down
2 changes: 1 addition & 1 deletion test/nn/combinatorial/test_hmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_forward(self):
intermediate_channels = [2, 2, 2]
final_channels = [2, 2, 2]
channels_per_layer = [[in_channels, intermediate_channels, final_channels]]
model = HMC(channels_per_layer, negative_slope=0.2, num_classes=2)
model = HMC(channels_per_layer, negative_slope=0.2, num_classes=2).to(device)

x_0 = torch.rand(2, 2)
x_1 = torch.rand(2, 2)
Expand Down
9 changes: 4 additions & 5 deletions test/nn/hypergraph/test_allset.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ def test_forward(self):
model = AllSet(
in_channels=4,
hidden_channels=4,
out_channels=4,
n_layers=2,
mlp_num_layers=1,
)
).to(device)

x_0 = torch.rand(4, 4)
incidence_1 = torch.from_numpy(np.random.rand(4, 4)).to_sparse()

x_0 = torch.tensor(x_0).float().to(device)
x_0 = x_0.float().to(device)
incidence_1 = incidence_1.float().to(device)

y = model(x_0, incidence_1)
assert y.shape == torch.Size([])
x_0, _ = model(x_0, incidence_1)
assert x_0.shape == (4, 4)
6 changes: 4 additions & 2 deletions test/nn/hypergraph/test_allset_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ def test_forward(self, allset_layer):
incidence_1 = torch.tensor(
[[1, 0, 0], [0, 1, 1], [1, 1, 1]], dtype=torch.float32
).to_sparse()
output = allset_layer.forward(x_0, incidence_1)
assert output.shape == (3, 64)
x_0, x_1 = allset_layer.forward(x_0, incidence_1)

assert x_0.shape == (3, 64)
assert x_1.shape == (3, 64)

def test_AllSetBlock(self):
"""Test the AllSetBlock class.
Expand Down
9 changes: 4 additions & 5 deletions test/nn/hypergraph/test_allset_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ def test_forward(self):
in_channels=2,
hidden_channels=2,
heads=1,
out_channels=1,
n_layers=2,
mlp_num_layers=1,
)
).to(device)

x_0 = torch.rand(2, 2)
incidence_1 = torch.from_numpy(np.random.rand(2, 2)).to_sparse()

x_0 = torch.tensor(x_0).float().to(device)
x_0 = x_0.float().to(device)
incidence_1 = incidence_1.float().to(device)

y = model(x_0, incidence_1)
assert y.shape == torch.Size([])
x_0, _ = model(x_0, incidence_1)
assert x_0.shape == (2, 2)
5 changes: 3 additions & 2 deletions test/nn/hypergraph/test_allset_transformer_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ def test_forward(self, allset_transformer_layer):
incidence_1 = torch.tensor(
[[1, 0, 0], [0, 1, 1], [1, 1, 1]], dtype=torch.float32
).to_sparse()
output = allset_transformer_layer.forward(x_0, incidence_1)
assert output.shape == (3, 64)
x_0, x_1 = allset_transformer_layer.forward(x_0, incidence_1)
assert x_0.shape == (3, 64)
assert x_1.shape == (3, 64)

def test_forward_with_invalid_input(self, allset_transformer_layer):
"""Test the forward pass of the allsettransformer layer with invalid input."""
Expand Down
12 changes: 8 additions & 4 deletions test/nn/hypergraph/test_dhgcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ class TestDHGCNL:
def test_forward(self):
"""Test forward method."""
# device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = DHGCN(channels_node=8, n_layers=2)
in_channels, hidden_channels = 8, 4
model = DHGCN(
in_channels=in_channels, hidden_channels=hidden_channels, n_layers=2
)

x_0 = torch.rand(8, 8)
n_nodes = 8
x_0 = torch.rand(n_nodes, in_channels)

y = model(x_0)
assert y.shape == torch.Size([])
x_0, _ = model(x_0)
assert x_0.shape == torch.Size([n_nodes, hidden_channels])
6 changes: 3 additions & 3 deletions test/nn/hypergraph/test_dhgcn_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_kmeans(self, dhgcn_layer):
output = dhgcn_layer.kmeans(x_0, k=dhgcn_layer.k_centroids)
assert output.shape == (2, 4)
if torch.cuda.is_available():
x_0 = x_0.to("gpu")
x_0 = x_0
output = dhgcn_layer.kmeans(x_0, k=dhgcn_layer.k_centroids)
assert output.device.type == x_0.device.type

Expand All @@ -41,8 +41,8 @@ def test_kmeans_with_invalid_input(self, dhgcn_layer):
def test_forward(self, dhgcn_layer):
"""Test the forward pass of the DHGCN layer."""
x = torch.randn(4, 10)
output = dhgcn_layer.forward(x)
assert output.shape == (4, 10)
x_0, _ = dhgcn_layer.forward(x)
assert x_0.shape == (4, 10)

def test_forward_invalid_input(self, dhgcn_layer):
"""Test the forward pass of the DHGCN layer."""
Expand Down
28 changes: 15 additions & 13 deletions test/nn/hypergraph/test_hmpnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ class TestHMPNN:
def test_forward(self):
"""Test forward method."""
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = HMPNN(8, (8, 8), 1, 1).to(device)

x_0 = torch.rand(8, 8)
x_1 = torch.rand(8, 8)

adjacency_1 = torch.from_numpy(np.random.rand(8, 8)).to_sparse()

x_0, x_1 = (
torch.tensor(x_0).float().to(device),
torch.tensor(x_1).float().to(device),
)
in_channels = 8
hidden_channels = 32
model = HMPNN(
in_channels=in_channels,
hidden_channels=hidden_channels,
).to(device)

n_nodes, n_edges = 8, 10
x_0 = torch.rand(n_nodes, in_channels).float().to(device)
x_1 = torch.rand(n_edges, in_channels).float().to(device)

adjacency_1 = torch.from_numpy(np.random.rand(n_nodes, n_edges)).to_sparse()
adjacency_1 = adjacency_1.float().to(device)

y = model(x_0, x_1, adjacency_1)
assert y.shape == torch.Size([8, 1])
x_0, x_1 = model(x_0, x_1, adjacency_1)
assert x_0.shape == torch.Size([n_nodes, hidden_channels])
assert x_1.shape == torch.Size([n_edges, hidden_channels])
55 changes: 9 additions & 46 deletions test/nn/hypergraph/test_hnhn.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import torch

from topomodelx.nn.hypergraph.hnhn import HNHN, HNHNNetwork
from topomodelx.nn.hypergraph.hnhn import HNHN


class TestHNHN:
Expand All @@ -14,55 +14,18 @@ def test_forward(self):
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

adjacency_1 = torch.from_numpy(np.random.rand(2, 2)).to_sparse()
adjacency_1 = adjacency_1.float().to(device)
adjacency_1 = adjacency_1.float()
hidden_channels = 5

model = HNHN(
channels_node=2,
channels_edge=2,
in_channels=2,
hidden_channels=hidden_channels,
incidence_1=adjacency_1,
n_classes=1,
n_layers=2,
).to(device)

x_0 = torch.rand(2, 2)
x_1 = torch.rand(2, 2)
x_0 = torch.rand(2, 2).float().to(device)

x_0, x_1 = (
torch.tensor(x_0).float().to(device),
torch.tensor(x_1).float().to(device),
)

y1, y2 = model(x_0, x_1)
assert y1.shape == torch.Size([2, 1])
assert y2.shape == torch.Size([2])


class TestHNHNNetwork:
"""Test the HNHNNetwork."""

def test_forward(self):
"""Test forward method."""
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

adjacency_1 = torch.from_numpy(np.random.rand(2, 2)).to_sparse()
adjacency_1 = adjacency_1.float().to(device)

model = HNHNNetwork(
channels_node=2,
channels_edge=2,
incidence_1=adjacency_1,
n_classes=1,
n_layers=2,
).to(device)

x_0 = torch.rand(2, 2)
x_1 = torch.rand(2, 2)

x_0, x_1 = (
torch.tensor(x_0).float().to(device),
torch.tensor(x_1).float().to(device),
)

y1, y2 = model(x_0, x_1)
assert y1.shape == torch.Size([2, 1])
assert y2.shape == torch.Size([2])
x_0, x_1 = model(x_0)
assert x_0.shape == torch.Size([2, hidden_channels])
assert x_1.shape == torch.Size([2, hidden_channels])
21 changes: 10 additions & 11 deletions test/nn/hypergraph/test_hnhn_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,28 @@ class TestHNHNLayer:
@pytest.fixture
def template_layer(self):
"""Initialize and return an HNHN layer."""
channels_node = 5
channels_edge = 8
self.in_channels = 5
self.hidden_channels = 8
n_nodes = 10
n_edges = 20
incidence_1 = torch.randint(0, 2, (n_nodes, n_edges)).float()

return HNHNLayer(
channels_node=channels_node,
channels_edge=channels_edge,
in_channels=self.in_channels,
hidden_channels=self.hidden_channels,
incidence_1=incidence_1,
)

def test_forward(self, template_layer):
"""Test the forward pass of the HNHN layer."""
n_nodes, n_edges = template_layer.incidence_1.shape
channels_node = template_layer.channels_node
channels_edge = template_layer.channels_edge
x_0 = torch.randn(n_nodes, channels_node)
x_1 = torch.randn(n_edges, channels_edge)
x_0_out, x_1_out = template_layer.forward(x_0, x_1)

assert x_0_out.shape == x_0.shape
assert x_1_out.shape == x_1.shape
x_0 = torch.randn(n_nodes, self.in_channels)
x_0_out, x_1_out = template_layer.forward(x_0)

assert x_0_out.shape == (n_nodes, self.hidden_channels)
assert x_1_out.shape == (n_edges, self.hidden_channels)

return

def test_compute_normalization_matrices(self, template_layer):
Expand Down
44 changes: 0 additions & 44 deletions test/nn/hypergraph/test_hnhn_layer_bis.py

This file was deleted.

Loading