Skip to content

Commit

Permalink
Merge pull request #14 from ispras/new_dir_structure
Browse files Browse the repository at this point in the history
New dir structure
  • Loading branch information
LukyanovKirillML authored Jul 18, 2024
2 parents 91ec385 + d10f110 commit 146f328
Show file tree
Hide file tree
Showing 54 changed files with 747 additions and 787 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 0 additions & 4 deletions demo/back_explainers_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ def explainers_test():
dataset_mg_small, _, results_dataset_path_mg_small = DatasetManager.get_by_full_name(
full_name=("multiple-graphs", "custom", "small",),
features={'attr': {'a': 'as_is'}},
dataset_attack_type='original',
labeling='binary',
dataset_ver_ind=0
)

dataset_sg_example, _, results_dataset_path_sg_example = DatasetManager.get_by_full_name(
full_name=("single-graph", "custom", "example",),
features={'attr': {'a': 'as_is'}},
dataset_attack_type='original',
labeling='binary',
dataset_ver_ind=0
)
Expand All @@ -36,7 +34,6 @@ def explainers_test():
graph="small"),
DatasetVarConfig(features={'attr': {'a': 'as_is'}},
labeling='binary',
dataset_attack_type='original',
dataset_ver_ind=0)
)
gen_dataset_sg_example = DatasetManager.get_by_config(
Expand All @@ -46,7 +43,6 @@ def explainers_test():
graph="example"),
DatasetVarConfig(features={'attr': {'a': 'as_is'}},
labeling='binary',
dataset_attack_type='original',
dataset_ver_ind=0)
)
gen_dataset_mg_small.train_test_split(percent_train_class=0.6, percent_test_class=0.4)
Expand Down
4 changes: 0 additions & 4 deletions demo/backend_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ def backend_demo():
# Init datasets VK and Cora
# dataset_cora, _, results_dataset_path_cora = DatasetManager.get_by_full_name(
# full_name=("single-graph", "Planetoid", 'Cora'),
# dataset_attack_type='original',
# dataset_ver_ind=0)
# dataset_comp, _, results_dataset_path_comp = DatasetManager.get_by_full_name(
# full_name=("single-graph", "Amazon", "Computers",),
# dataset_attack_type='original',
# dataset_ver_ind=0
# )
# dataset_mg_example, _, results_dataset_path_mg_example = DatasetManager.get_by_full_name(
# full_name=("multiple-graphs", "custom", "example",),
# features={'attr': {'type': 'as_is'}},
# dataset_attack_type='original',
# labeling='binary',
# dataset_ver_ind=0
# )
Expand Down Expand Up @@ -53,7 +50,6 @@ def backend_demo():
graph="example"),
DatasetVarConfig(features={'attr': {'type': 'as_is'}},
labeling='binary',
dataset_attack_type='original',
dataset_ver_ind=0)
)
gen_dataset_mg_example.train_test_split(percent_train_class=0.6, percent_test_class=0.4)
Expand Down
1 change: 0 additions & 1 deletion demo/user_exp_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def test_Konst_model():
dataset, data, results_dataset_path = DatasetManager.get_by_full_name(
full_name=full_name,
features={'attr': {'a': 'as_is', 'b': 'as_is'}},
dataset_attack_type='original',
labeling='threeClasses',
dataset_ver_ind=0
)
Expand Down
28 changes: 0 additions & 28 deletions experiments/GNNExplainerDIG_exp_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,12 @@ def dig_GNNExplainer_test():
my_device = device('cuda' if is_available() else 'cpu')
my_device = device('cpu')

# dataset, data, results_dataset_path = DatasetManager.get_pytorch_geometric(
# full_name=("single-graph", "Planetoid", 'Cora'),
# dataset_attack_type='original')
# dataset, data, results_dataset_path = DatasetManager.get_pytorch_geometric(
# full_name=("single-graph", "pytorch-geometric-other", 'KarateClub'),
# dataset_attack_type='original',
# dataset_ver_ind=0)

dataset, data, results_dataset_path = DatasetManager.get_by_full_name(
full_name=("single-graph", "Planetoid", 'Cora'),
dataset_attack_type='original',
dataset_ver_ind=0)

# dataset, data, results_dataset_path = DatasetManager.get_by_full_name(
# full_name=("multiple-graphs", "TUDataset", 'PROTEINS'),
# dataset_attack_type='original',
# dataset_ver_ind=0
# )

# dataset, data, results_dataset_path = DatasetManager.get_pytorch_geometric(
# # full_name=("single-graph", "vk_samples", "vk2-ff40-N100000-A.1612175945",),
# full_name=("single-graph", "vk_samples", "vk2-ff20-N10000-A.1611943634",),
# # full_name=("single-graph", "vk_samples", "vk2-ff20-N1000-U.1612273925",),
# # features=('sex',),
# features={'str_f': tuple(), 'str_g': None, 'attr': {
# # "('personal', 'political')": 'one_hot',
# # "('occupation', 'type')": 'one_hot', # Don't work now
# # "('relation',)": 'one_hot',
# # "('age',)": 'one_hot',
# "('sex',)": 'one_hot',
# }},
# # features={'str_f': tuple(), 'str_g': None, 'attr': {'sex': 'one_hot', }},
# labeling='sex1',
# dataset_attack_type='original',
# dataset_ver_ind=0
# )

Expand Down
32 changes: 0 additions & 32 deletions experiments/GNNExplainerGEOM_exp_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,9 @@ def geom_GNNExplainer_test():
my_device = device('cuda' if is_available() else 'cpu')
my_device = device('cpu')

# dataset, data, results_dataset_path = DatasetManager.get_pytorch_geometric(
# full_name=("single-graph", "Planetoid", 'Cora'),
# dataset_attack_type='original')
# dataset, data, results_dataset_path = DatasetManager.get_pytorch_geometric(
# full_name=("single-graph", "pytorch-geometric-other", 'KarateClub'),
# dataset_attack_type='original',
# dataset_ver_ind=0)

dataset, data, results_dataset_path = DatasetManager.get_by_full_name(
full_name=("single-graph", "Planetoid", 'Cora'),
dataset_attack_type='original',
dataset_ver_ind=0)
# dataset, data, results_dataset_path = DatasetManager.get_pytorch_geometric(
# full_name=("multiple-graphs", "TUDataset", 'PROTEINS'),
# dataset_attack_type='original',
# dataset_ver_ind=0
# )

# dataset, data, results_dataset_path = DatasetManager.get_pytorch_geometric(
# # full_name=("single-graph", "vk_samples", "vk2-ff40-N100000-A.1612175945",),
# full_name=("single-graph", "vk_samples", "vk2-ff20-N10000-A.1611943634",),
# # full_name=("single-graph", "vk_samples", "vk2-ff20-N1000-U.1612273925",),
# # features=('sex',),
# features={'str_f': tuple(), 'str_g': None, 'attr': {
# # "('personal', 'political')": 'one_hot',
# # "('occupation', 'type')": 'one_hot', # Don't work now
# # "('relation',)": 'one_hot',
# # "('age',)": 'one_hot',
# "('sex',)": 'one_hot',
# }},
# # features={'str_f': tuple(), 'str_g': None, 'attr': {'sex': 'one_hot', }},
# labeling='sex1',
# dataset_attack_type='original',
# dataset_ver_ind=0
# )

gcn2 = model_configs_zoo(dataset=dataset, model_name='gcn_gcn')

Expand Down
1 change: 0 additions & 1 deletion experiments/GradCAM_exp_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def GradCAM_test():

dataset, data, results_dataset_path = DatasetManager.get_by_full_name(
full_name=("single-graph", "Planetoid", 'Cora'),
dataset_attack_type='original',
dataset_ver_ind=0)

# print(dataset)
Expand Down
32 changes: 0 additions & 32 deletions experiments/GraphMask_exp_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,9 @@ def test_graph_mask(configuration):
my_device = device('cuda' if is_available() else 'cpu')
my_device = device('cpu')

# dataset, data, results_dataset_path = DatasetManager.get_pytorch_geometric(
# full_name=("single-graph", "Planetoid", 'Cora'),
# dataset_attack_type='original')
# dataset, data, results_dataset_path = DatasetManager.get_pytorch_geometric(
# full_name=("single-graph", "pytorch-geometric-other", 'KarateClub'),
# dataset_attack_type='original',
# dataset_ver_ind=0)

dataset, data, results_dataset_path = DatasetManager.get_by_full_name(
full_name=("single-graph", "Planetoid", 'Cora'),
dataset_attack_type='original',
dataset_ver_ind=0)
# dataset, data, results_dataset_path = DatasetManager.get_pytorch_geometric(
# full_name=("multiple-graphs", "TUDataset", 'PROTEINS'),
# dataset_attack_type='original',
# dataset_ver_ind=0
# )

# dataset, data, results_dataset_path = DatasetManager.get_pytorch_geometric(
# # full_name=("single-graph", "vk_samples", "vk2-ff40-N100000-A.1612175945",),
# full_name=("single-graph", "vk_samples", "vk2-ff20-N10000-A.1611943634",),
# # full_name=("single-graph", "vk_samples", "vk2-ff20-N1000-U.1612273925",),
# # features=('sex',),
# features={'str_f': tuple(), 'str_g': None, 'attr': {
# # "('personal', 'political')": 'one_hot',
# # "('occupation', 'type')": 'one_hot', # Don't work now
# # "('relation',)": 'one_hot',
# # "('age',)": 'one_hot',
# "('sex',)": 'one_hot',
# }},
# # features={'str_f': tuple(), 'str_g': None, 'attr': {'sex': 'one_hot', }},
# labeling='sex1',
# dataset_attack_type='original',
# dataset_ver_ind=0
# )

gcn2 = model_configs_zoo(dataset=dataset, model_name='gcn_gcn')

Expand Down
1 change: 0 additions & 1 deletion experiments/NeuralAnalysis_our_exp_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def test_neural_analysis(percent_train_class: float = 0.8, percent_test_class: f
full_name = ("multiple-graphs", "TUDataset", 'MUTAG')
dataset, data, results_dataset_path = DatasetManager.get_by_full_name(
full_name=full_name,
dataset_attack_type='original',
dataset_ver_ind=0
)

Expand Down
2 changes: 0 additions & 2 deletions experiments/ProtGNN_exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def test_prot(i=None, conv=None, batch_size=24, seed=5,
"""
dataset, data, results_dataset_path = Datasets.get_pytorch_geometric(
full_name=("single-graph", "TUDataset", 'MUTAG'),
dataset_attack_type='original',
dataset_ver_ind=0)
"""

Expand All @@ -50,7 +49,6 @@ def test_prot(i=None, conv=None, batch_size=24, seed=5,
full_name = ("multiple-graphs", "TUDataset", 'MUTAG')
dataset, data, results_dataset_path = DatasetManager.get_by_full_name(
full_name=full_name,
dataset_attack_type='original',
dataset_ver_ind=0
)

Expand Down
48 changes: 15 additions & 33 deletions experiments/attack_defense_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@

from torch import device

from attacks.attack_base import RandomPoisonAttack
from defense.defense_base import BadRandomPoisonDefender
from models_builder.attack_defense_manager import AttackAndDefenseManager
from src.aux.utils import OPTIMIZERS_PARAMETERS_PATH, EXPLAINERS_LOCAL_RUN_PARAMETERS_PATH, \
EXPLAINERS_INIT_PARAMETERS_PATH, POISON_ATTACK_PARAMETERS_PATH, POISON_DEFENSE_PARAMETERS_PATH
from src.explainers.explainers_manager import FrameworkExplainersManager
from src.aux.utils import POISON_ATTACK_PARAMETERS_PATH, POISON_DEFENSE_PARAMETERS_PATH
from src.models_builder.gnn_models import FrameworkGNNModelManager, Metric
from src.aux.configs import ModelManagerConfig, ModelModificationConfig, ExplainerInitConfig, ExplainerRunConfig, \
ConfigPattern, ExplainerModificationConfig
from src.aux.configs import ModelModificationConfig, ConfigPattern
from src.base.datasets_processing import DatasetManager
from src.models_builder.models_zoo import model_configs_zoo

Expand All @@ -28,28 +22,14 @@ def test_attack_defense():
full_name = ("single-graph", "Planetoid", 'Cora')
# full_name = ("multiple-graphs", "TUDataset", 'PROTEINS')

# dataset, data, results_dataset_path = DatasetManager.get_pytorch_geometric(
# full_name=("single-graph", "Planetoid", 'Cora'),
# dataset_attack_type='original')
# dataset, data, results_dataset_path = DatasetManager.get_pytorch_geometric(
# full_name=("single-graph", "pytorch-geometric-other", 'KarateClub'),
# dataset_attack_type='original',
# dataset_ver_ind=0)

# dataset, data, results_dataset_path = DatasetManager.get_pytorch_geometric(
# full_name=("single-graph", "Planetoid", 'Cora'),
# dataset_attack_type='original',
# dataset_ver_ind=0)
dataset, data, results_dataset_path = DatasetManager.get_by_full_name(
full_name=full_name,
dataset_attack_type='original',
dataset_ver_ind=0
)

# dataset, data, results_dataset_path = DatasetManager.get_by_full_name(
# full_name=("single-graph", "custom", "example",),
# features={'attr': {'a': 'as_is', 'b': 'as_is'}},
# dataset_attack_type='original',
# labeling='threeClasses',
# dataset_ver_ind=0
# )
Expand All @@ -68,7 +48,6 @@ def test_attack_defense():
# }},
# # features={'str_f': tuple(), 'str_g': None, 'attr': {'sex': 'one_hot', }},
# labeling='sex1',
# dataset_attack_type='original',
# dataset_ver_ind=0
# )

Expand Down Expand Up @@ -115,8 +94,8 @@ def test_attack_defense():
modification=ModelModificationConfig(model_ver_ind=0, epochs=steps_epochs)
)

save_model_flag = False
# save_model_flag = True
# save_model_flag = False
save_model_flag = True

# data.x = data.x.float()
gnn_model_manager.gnn.to(my_device)
Expand All @@ -131,20 +110,24 @@ def test_attack_defense():
}
)

# poison_defense_config = ConfigPattern(
# _class_name="BadRandomPoisonDefender",
# _import_path=POISON_DEFENSE_PARAMETERS_PATH,
# _config_class="PoisonDefenseConfig",
# _config_kwargs={
# "n_edges_percent": 0.1,
# }
# )
poison_defense_config = ConfigPattern(
_class_name="BadRandomPoisonDefender",
_class_name="EmptyPoisonDefender",
_import_path=POISON_DEFENSE_PARAMETERS_PATH,
_config_class="PoisonDefenseConfig",
_config_kwargs={
"n_edges_percent": 0.1,
}
)

attack_defense_manager = AttackAndDefenseManager(gen_dataset=dataset, gnn_manager=gnn_model_manager)
attack_defense_manager.set_poison_attacker(poison_attack_config=poison_attack_config)
attack_defense_manager.set_poison_defender(poison_defense_config=poison_defense_config)

attack_defense_manager.conduct_experiment()
gnn_model_manager.set_poison_attacker(poison_attack_config=poison_attack_config)
gnn_model_manager.set_poison_defender(poison_defense_config=poison_defense_config)

warnings.warn("Start training")
dataset.train_test_split()
Expand Down Expand Up @@ -172,7 +155,6 @@ def test_attack_defense():
print(metric_loc)



if __name__ == '__main__':
test_attack_defense()

Expand Down
2 changes: 0 additions & 2 deletions experiments/computation_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,15 +677,13 @@ def computation_graph_data(x, edge_index, inputs, result, tensors, ops, edges):
full_name=("single-graph", "custom", 'example'),
features={'attr': {'a': 'as_is'}},
labeling='binary',
dataset_attack_type='original',
dataset_ver_ind=0)

# # multi
# dataset, data, results_dataset_path = DatasetManager.get_pytorch_geometric(
# full_name=("multiple-graphs", "custom", 'example'),
# features={'attr': {'type': 'as_is'}},
# labeling='binary',
# dataset_attack_type='original',
# dataset_ver_ind=0)

sage1: torch.nn.Module = GNNStructure(
Expand Down
Loading

0 comments on commit 146f328

Please sign in to comment.