-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a0e4ec
commit 78f5ed2
Showing
5 changed files
with
161 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import os | ||
import shutil | ||
import rootutils | ||
from hydra import compose | ||
import torch | ||
|
||
from topobenchmark.data.preprocessor import PreProcessor | ||
from topobenchmark.data.utils.utils import load_manual_graph | ||
from topobenchmark.data.batching import NeighborCellsLoader | ||
from topobenchmark.run import initialize_hydra | ||
|
||
initialize_hydra() | ||
|
||
path = "/temp/graph2simplicial_lifting/" | ||
if os.path.isdir(path): | ||
shutil.rmtree(path) | ||
cfg = compose(config_name="run.yaml", | ||
overrides=["dataset=graph/manual_dataset", "model=simplicial/san"], | ||
return_hydra_config=True) | ||
|
||
data = load_manual_graph() | ||
preprocessed_dataset = PreProcessor(data, path, cfg['transforms']) | ||
data = preprocessed_dataset[0] | ||
|
||
batch_size=2 | ||
|
||
rank = 0 | ||
n_cells = data[f'x_{rank}'].shape[0] | ||
train_prop = 0.5 | ||
n_train = int(train_prop * n_cells) | ||
train_mask = torch.zeros(n_cells, dtype=torch.bool) | ||
train_mask[:n_train] = 1 | ||
|
||
y = torch.zeros(n_cells, dtype=torch.long) | ||
data.y = y | ||
|
||
loader = NeighborCellsLoader(data, | ||
rank=rank, | ||
num_neighbors=[-1], | ||
input_nodes=train_mask, | ||
batch_size=batch_size, | ||
shuffle=False) | ||
train_nodes = [] | ||
for batch in loader: | ||
train_nodes += [n for n in batch.n_id[:batch_size]] | ||
for i in range(n_train): | ||
assert i in train_nodes | ||
|
||
rank = 1 | ||
n_cells = data[f'x_{rank}'].shape[0] | ||
train_prop = 0.5 | ||
n_train = int(train_prop * n_cells) | ||
train_mask = torch.zeros(n_cells, dtype=torch.bool) | ||
train_mask[:n_train] = 1 | ||
|
||
y = torch.zeros(n_cells, dtype=torch.long) | ||
data.y = y | ||
|
||
loader = NeighborCellsLoader(data, | ||
rank=rank, | ||
num_neighbors=[-1,-1], | ||
input_nodes=train_mask, | ||
batch_size=batch_size, | ||
shuffle=False) | ||
|
||
train_nodes = [] | ||
for batch in loader: | ||
train_nodes += [n for n in batch.n_id[:batch_size]] | ||
for i in range(n_train): | ||
assert i in train_nodes | ||
shutil.rmtree(path) | ||
|
||
|
||
path = "/temp/graph2hypergraph_lifting/" | ||
if os.path.isdir(path): | ||
shutil.rmtree(path) | ||
cfg = compose(config_name="run.yaml", | ||
overrides=["dataset=graph/manual_dataset", "model=hypergraph/allsettransformer"], | ||
return_hydra_config=True) | ||
|
||
data = load_manual_graph() | ||
preprocessed_dataset = PreProcessor(data, path, cfg['transforms']) | ||
data = preprocessed_dataset[0] | ||
|
||
batch_size=2 | ||
|
||
rank = 0 | ||
n_cells = data[f'x_0'].shape[0] | ||
train_prop = 0.5 | ||
n_train = int(train_prop * n_cells) | ||
train_mask = torch.zeros(n_cells, dtype=torch.bool) | ||
train_mask[:n_train] = 1 | ||
|
||
y = torch.zeros(n_cells, dtype=torch.long) | ||
data.y = y | ||
|
||
loader = NeighborCellsLoader(data, | ||
rank=rank, | ||
num_neighbors=[-1], | ||
input_nodes=train_mask, | ||
batch_size=batch_size, | ||
shuffle=False) | ||
train_nodes = [] | ||
for batch in loader: | ||
train_nodes += [n for n in batch.n_id[:batch_size]] | ||
for i in range(n_train): | ||
assert i in train_nodes | ||
|
||
rank = 1 | ||
n_cells = data[f'x_hyperedges'].shape[0] | ||
train_prop = 0.5 | ||
n_train = int(train_prop * n_cells) | ||
train_mask = torch.zeros(n_cells, dtype=torch.bool) | ||
train_mask[:n_train] = 1 | ||
|
||
y = torch.zeros(n_cells, dtype=torch.long) | ||
data.y = y | ||
|
||
loader = NeighborCellsLoader(data, | ||
rank=rank, | ||
num_neighbors=[-1,-1], | ||
input_nodes=train_mask, | ||
batch_size=batch_size, | ||
shuffle=False) | ||
|
||
train_nodes = [] | ||
for batch in loader: | ||
train_nodes += [n for n in batch.n_id[:batch_size]] | ||
for i in range(n_train): | ||
assert i in train_nodes | ||
shutil.rmtree(path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
""" Init file for batching module. """ | ||
|
||
from .neighbor_cells_loader import NeighborCellsLoader | ||
|
||
__all__ = [ | ||
"NeighborCellsLoader", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters