def test_customized_graph_dataset(): result = experiment(model="gin", task="graph_classification", dataset="mygraphdataset", degree_feature=True, max_epoch=10) result = list(result.values())[0][0] assert result["Acc"] >= 0
def test_customized_graph_dataset_graph2vec(): dataset = MyGraphClassificationDataset() result = experiment(model="graph2vec", dataset=dataset, degree_node_features=False, epochs=10, cpu=True) result = list(result.values())[0][0] assert result["acc"] >= 0
def test_experiment(): results = experiment(task="node_classification", dataset="cora", model="gcn", hidden_size=32, max_epoch=10, cpu=True) assert ("cora", "gcn") in results assert results[("cora", "gcn")][0]["Acc"] > 0
def test_autognn_experiment(): results = experiment( dataset="cora", model="autognn", seed=[1], n_trials=10, epochs=2, cpu=True, ) assert ("cora", "autognn") in results assert results[("cora", "autognn")][0]["test_acc"] > 0
def test_auto_experiment(): def search_space_example(trial): return { "lr": trial.suggest_categorical("lr", [1e-3, 5e-3, 1e-2]), "hidden_size": trial.suggest_categorical("hidden_size", [16, 32, 64, 128]), "dropout": trial.suggest_uniform("dropout", 0.5, 0.9), } results = experiment( dataset="cora", model="gcn", seed=[1, 2], n_trials=2, epochs=10, search_space=search_space_example, cpu=True, ) assert ("cora", "gcn") in results assert results[("cora", "gcn")][0]["test_acc"] > 0
def test_auto_experiment(): def func_search_example(trial): return { "lr": trial.suggest_categorical("lr", [1e-3, 5e-3, 1e-2]), "hidden_size": trial.suggest_categorical("hidden_size", [16, 32, 64, 128]), "dropout": trial.suggest_uniform("dropout", 0.5, 0.9), } results = experiment( task="node_classification", dataset="cora", model="gcn", seed=[1, 2], n_trials=2, max_epoch=10, func_search=func_search_example, cpu=True, ) assert ("cora", "gcn") in results assert results[("cora", "gcn")][0]["Acc"] > 0
# load or generate your dataset edge_index = torch.randint(0, num_nodes, (2, num_edges)) x = torch.randn(num_nodes, feat_dim) y = torch.randint(0, 2, (num_nodes, )) # set train/val/test mask in node_classification task train_mask = torch.zeros(num_nodes).bool() train_mask[0:int(0.3 * num_nodes)] = True val_mask = torch.zeros(num_nodes).bool() val_mask[int(0.3 * num_nodes):int(0.7 * num_nodes)] = True test_mask = torch.zeros(num_nodes).bool() test_mask[int(0.7 * num_nodes):] = True data = Graph(x=x, edge_index=edge_index, y=y, train_mask=train_mask, val_mask=val_mask, test_mask=test_mask) return data if __name__ == "__main__": # Train customized dataset via defining a new class dataset = MyNodeClassificationDataset() experiment(dataset=dataset, model="gcn") # Train customized dataset via feeding the graph data to NodeDataset data = generate_random_graph(num_nodes=100, num_edges=300, num_feats=30) dataset = NodeDataset(data=data) experiment(dataset=dataset, model="gcn")