Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
levtelyatnikov committed May 15, 2024
2 parents 8173c96 + 202d33e commit f715db1
Showing 7 changed files with 64 additions and 256 deletions.
16 changes: 0 additions & 16 deletions .devcontainer/Dockerfile

This file was deleted.

18 changes: 0 additions & 18 deletions .devcontainer/devcontainer.json

This file was deleted.

129 changes: 0 additions & 129 deletions .devcontainer/pyproject.toml

This file was deleted.

35 changes: 11 additions & 24 deletions env.bash
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
# #!/bin/bash

# set -e

# # Step 1: Upgrade pip
# pip install --upgrade pip

# # Step 2: Install dependencies
# yes | pip install -e '.[all]'
# yes | pip install --no-dependencies git+https://github.com/pyt-team/TopoNetX.git
# yes | pip install --no-dependencies git+https://github.com/pyt-team/TopoModelX.git
# yes | pip install torch==2.0.1 --extra-index-url https://download.pytorch.org/whl/cu115
# yes | pip install torch-scatter torch-sparse -f https://data.pyg.org/whl/torch-2.0.1+cu115.html
# yes | pip install torch-cluster -f https://data.pyg.org/whl/torch-2.0.0+cu115.html
# yes | pip install lightning>=2.0.0
# yes | pip install numpy pre-commit jupyterlab notebook ipykernel


yes | conda create -n topox python=3.11.3
conda activate topox
#conda create -n topox python=3.11.3
#conda activate topox

pip install --upgrade pip
pip install -e '.[all]'

yes | pip install --no-dependencies git+https://github.com/pyt-team/TopoNetX.git
yes | pip install --no-dependencies git+https://github.com/pyt-team/TopoModelX.git
pip install git+https://github.com/pyt-team/TopoNetX.git
pip install git+https://github.com/pyt-team/TopoModelX.git
pip install git+https://github.com/pyt-team/TopoEmbedX.git

yes | pip install torch==2.0.1 --extra-index-url https://download.pytorch.org/whl/cu115
yes | pip install torch-scatter torch-sparse -f https://data.pyg.org/whl/torch-2.0.1+cu115.html
yes | pip install torch-cluster -f https://data.pyg.org/whl/torch-2.0.0+cu115.html
yes | pip install numpy pre-commit jupyterlab notebook ipykernel
CUDA="cu115" # if available, select the CUDA version suitable for your system
# e.g. cpu, cu102, cu111, cu113, cu115
pip install torch==2.0.1 --extra-index-url https://download.pytorch.org/whl/${CUDA}
pip install torch-scatter torch-sparse -f https://data.pyg.org/whl/torch-2.0.1+${CUDA}.html
pip install torch-cluster -f https://data.pyg.org/whl/torch-2.0.0+${CUDA}.html

pytest

5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -45,6 +45,10 @@ dependencies=[
"lightning==2.2.1",
"einops==0.7.0",
"wandb==0.16.4",
"tabulate",
"ipykernel",
"notebook",
"jupyterlab",
"rich",
"rootutils",
"pytest",
@@ -167,4 +171,5 @@ checks = [
exclude = [
'\.undocumented_method$',
'\.__init__$',
'\.__repr__$',
]
73 changes: 48 additions & 25 deletions test/data/test_Dataloaders.py
Original file line number Diff line number Diff line change
@@ -62,44 +62,67 @@ def test_lift_features(self):
----------
None
"""
def check_shape(batch, elems, key):
"""Check that the batched data has the expected shape."""
if 'x_' in key or 'x'==key:
rows = 0
for i in range(len(elems)):
rows += elems[i][key].shape[0]
assert batch[key].shape[0] == rows
assert batch[key].shape[1] == elems[0][key].shape[1]
elif 'edge_index' in key:
cols = 0
for i in range(len(elems)):
cols += elems[i][key].shape[1]
assert batch[key].shape[0] == 2
assert batch[key].shape[1] == cols
elif 'batch_' in key:
rows = 0
n = int(key.split('_')[1])
for i in range(len(elems)):
rows += elems[i][f'x_{n}'].shape[0]
assert batch[key].shape[0] == rows
elif key in elems[0].keys():
for i in range(len(batch[key].shape)):
i_elems = 0
for j in range(len(elems)):
i_elems += elems[j][key].shape[i]
assert batch[key].shape[i] == i_elems

def check_separation(matrix, n_elems_0_row, n_elems_0_col):
"""Check that the matrix is separated into two parts diagonally concatenated."""
assert torch.all(matrix[:n_elems_0_row, n_elems_0_col:] == 0)
assert torch.all(matrix[n_elems_0_row:, :n_elems_0_col] == 0)

def check_values(matrix, m1, m2):
"""Check that the values in the matrix are the same as the values in the original data."""
assert torch.allclose(matrix[:m1.shape[0], :m1.shape[1]], m1)
assert torch.allclose(matrix[m1.shape[0]:, m1.shape[1]:], m2)


batch = next(iter(self.val_dataloader))
elems = []
for i in range(self.batch_size):
elems.append(self.val_dataset.data_lst[i])

# Check that the batched data has the expected shape
# Check shape
for key in batch.keys():
if key in elems[0].keys():
if 'x_' in key or 'x'==key:
assert batch[key].shape[0] == elems[0][key].shape[0]+elems[1][key].shape[0]
assert batch[key].shape[1] == elems[0][key].shape[1]
elif 'edge_index' in key:
assert batch[key].shape[0] == 2
assert batch[key].shape[1] == elems[0][key].shape[1]+elems[1][key].shape[1]
else:
for i in range(len(batch[key].shape)):
assert batch[key].shape[i] == elems[0][key].shape[i]+elems[1][key].shape[i]
else:
if 'batch_' in key:
i = int(key.split('_')[1])
assert batch[key].shape[0] == elems[0][f'x_{i}'].shape[0]+elems[1][f'x_{i}'].shape[0]
check_shape(batch, elems, key)

# Check that the batched data is separated correctly
for key in batch.keys():
if 'incidence_' in key:
i = int(key.split('_')[1])
if i==0:
n0_row = 1
else:
n0_row = torch.sum(batch[f'batch_{i-1}']==0)
n0_col = torch.sum(batch[f'batch_{i}']==0)
check_separation(batch[key].to_dense(), n0_row, n0_col)
# Check that the batched data is separated correctly and the values are correct
if self.batch_size == 2:
for key in batch.keys():
if 'incidence_' in key:
i = int(key.split('_')[1])
if i==0:
n0_row = 1
else:
n0_row = torch.sum(batch[f'batch_{i-1}']==0)
n0_col = torch.sum(batch[f'batch_{i}']==0)
check_separation(batch[key].to_dense(), n0_row, n0_col)
check_values(batch[key].to_dense(),
elems[0][key].to_dense(),
elems[1][key].to_dense())

# Check that going back to a list of data gives the same data
batch_list = to_data_list(batch)
44 changes: 0 additions & 44 deletions topobenchmarkx/=0.12.10

This file was deleted.

0 comments on commit f715db1

Please sign in to comment.