Skip to content

Commit 09914dc

Browse files
Ryan-YuanLikayzliuLijunhaohz
authored
Merge main into package (#19)
* fix doc req * merge general_ref into main (#18) * modify simple code example * refactor code --------- Co-authored-by: Kay (Zekuan) Liu <[email protected]> Co-authored-by: Junhao Li <[email protected]>
1 parent 41e1262 commit 09914dc

16 files changed

+663
-647
lines changed

docs/examples/configs/config_GC_FedAvg.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# setup
1212
device: 'cpu'
1313
seed: 10
14+
seed_split_data: 42
1415

1516
# model_parameters
1617
num_trainers: 10

docs/examples/configs/config_GC_FedProx.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# setup:
1212
device: 'cpu'
1313
seed: 10
14+
seed_split_data: 42
1415

1516
# model_parameters:
1617
num_trainers: 10

docs/examples/configs/config_GC_GCFL.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# setup:
1212
device: 'cpu'
1313
seed: 10
14+
seed_split_data: 42
1415

1516
# model_parameters:
1617
num_trainers: 10

docs/examples/configs/config_GC_SelfTrain.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# setup
1212
device: 'cpu'
1313
seed: 10
14+
seed_split_data: 42
1415

1516
# model_parameters
1617
num_trainers: 10

docs/examples/intro_FedGCN.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
ray.init()
2121

22-
from fedgraph.data_process_nc import load_data
22+
from fedgraph.data_process import FedGCN_load_data
2323
from fedgraph.server_class import Server
2424
from fedgraph.trainer_class import Trainer_General
2525
from fedgraph.utils_nc import (
@@ -62,7 +62,7 @@
6262
# tutorial <https://pytorch-geometric.readthedocs.io/en/latest/notes
6363
# /create_dataset.html>`__ in PyG.
6464

65-
features, adj, labels, idx_train, idx_val, idx_test = load_data(args.dataset)
65+
features, adj, labels, idx_train, idx_val, idx_test = FedGCN_load_data(args.dataset)
6666
class_num = labels.max().item() + 1
6767

6868
if args.dataset in ["simulate", "cora", "citeseer", "pubmed", "reddit"]:

docs/examples/intro_GC.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
sys.path.append("../fedgraph")
2525
sys.path.append("../../")
26-
from fedgraph.data_process_gc import *
26+
from fedgraph.data_process import data_loader_GC
2727
from fedgraph.federated_methods import (
2828
run_GC_fedavg,
2929
run_GC_fedprox,
@@ -113,7 +113,6 @@
113113
# Here we prepare the data for the experiment.
114114
# The data is split into training and test sets, and then the training set
115115
# is further split into training and validation sets.
116-
# The statistics of the data on trainers are also computed and saved.
117116
# The user can also use their own dataset and dataloader.
118117
# The expected format of the dataset is a dictionary with the keys as the trainer names.
119118
# For each trainer, the value `data[trainer]` is a tuple with 4 elements: (dataloader, num_node_features, num_graph_labels, train_size)
@@ -126,32 +125,9 @@
126125
""" using original features """
127126
print("Preparing data (original features) ...")
128127

129-
if args.is_multiple_dataset:
130-
splited_data, df_stats = load_multiple_datasets(
131-
datapath=args.datapath,
132-
dataset_group=args.dataset,
133-
batch_size=args.batch_size,
134-
convert_x=args.convert_x,
135-
seed=seed_split_data,
136-
)
137-
else:
138-
splited_data, df_stats = load_single_dataset(
139-
args.datapath,
140-
args.dataset,
141-
num_trainer=args.num_trainers,
142-
batch_size=args.batch_size,
143-
convert_x=args.convert_x,
144-
seed=seed_split_data,
145-
overlap=args.overlap,
146-
)
128+
splited_data = data_loader_GC(args)
147129
print("Data prepared.")
148130

149-
if args.save_files:
150-
outdir_stats = os.path.join(outdir, f"stats_train_data.csv")
151-
df_stats.to_csv(outdir_stats)
152-
print(f"The statistics of the data are written to {outdir_stats}")
153-
154-
155131
#######################################################################
156132
# Setup server and trainers
157133
# ------------

docs/examples/simple_code_example.py

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
import yaml
1818

1919
sys.path.append("../fedgraph")
20-
sys.path.append("../../")
21-
from fedgraph.data_process_gc import load_single_dataset
22-
from fedgraph.federated_methods import run_FedGCN, run_GC, run_LP
23-
from fedgraph.utils_nc import federated_data_loader
20+
from fedgraph.data_process import data_loader
21+
from fedgraph.federated_methods import run_fedgraph
2422

2523
#######################################################################
2624
# Specify the task
@@ -44,30 +42,14 @@
4442

4543
with open(config_file_path, "r") as f:
4644
config = attridict(yaml.safe_load(f))
45+
config.fedgraph_task = fedgraph_task
4746

4847
print(config)
4948

50-
if fedgraph_task == "FedGCN":
51-
data = federated_data_loader(config)
52-
elif fedgraph_task == "GC":
53-
seed_split_data = 42 # seed for splitting data must be fixed
54-
data, _ = load_single_dataset(
55-
config.datapath,
56-
dataset=config.dataset,
57-
num_trainer=config.num_trainers,
58-
batch_size=config.batch_size,
59-
convert_x=config.convert_x,
60-
seed=seed_split_data,
61-
overlap=config.overlap,
62-
)
49+
data = data_loader(config) # Load federated data
6350

6451
#######################################################################
6552
# Run FedGCN method
6653
# ------------
6754

68-
if fedgraph_task == "FedGCN":
69-
run_FedGCN(config, data)
70-
elif fedgraph_task == "GC":
71-
run_GC(config, data)
72-
elif fedgraph_task == "LP":
73-
run_LP(config)
55+
run_fedgraph(config, data)

docs/fedgraph.data_process_gc.rst

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/fedgraph.data_process_nc.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Data Process for Node Classification
1+
Data Process
22
============
33

44
.. automodule:: fedgraph.data_process

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ attridict
1818
fedgraph
1919
dtaidistance
2020
gdown
21+
pandas

0 commit comments

Comments
 (0)