.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/simple_code_example.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorials_simple_code_example.py: Simple FedGraph Example ================ Run a simple example of FedGraph. (Time estimate: 3 minutes) .. GENERATED FROM PYTHON SOURCE LINES 11-13 Load libraries ------------ .. GENERATED FROM PYTHON SOURCE LINES 13-23 .. code-block:: Python import sys import attridict import yaml sys.path.append("../fedgraph") from fedgraph.data_process import data_loader from fedgraph.federated_methods import run_fedgraph .. GENERATED FROM PYTHON SOURCE LINES 24-26 Specify the task ------------ .. GENERATED FROM PYTHON SOURCE LINES 26-34 .. code-block:: Python fedgraph_task = "GC" assert fedgraph_task in ["FedGCN", "GC", "LP"] GC_algorithm = "GCFL" # For GC task, the user must specify the GC algorithm if fedgraph_task == "GC": assert GC_algorithm in ["SelfTrain", "FedAvg", "FedProx", "GCFL"] .. GENERATED FROM PYTHON SOURCE LINES 35-37 Load configuration and federated data ------------ .. GENERATED FROM PYTHON SOURCE LINES 37-51 .. code-block:: Python config_file_path = ( f"configs/config_{fedgraph_task}_{GC_algorithm}.yaml" if fedgraph_task == "GC" else f"configs/config_{fedgraph_task}.yaml" ) with open(config_file_path, "r") as f: config = attridict(yaml.safe_load(f)) config.fedgraph_task = fedgraph_task print(config) data = data_loader(config) # Load federated data .. rst-class:: sphx-glr-script-out .. code-block:: none {'model': 'GCFL', 'dataset': 'IMDB-BINARY', 'is_multiple_dataset': False, 'datapath': './data', 'convert_x': False, 'overlap': False, 'device': 'cpu', 'seed': 10, 'seed_split_data': 42, 'num_trainers': 10, 'num_rounds': 200, 'local_epoch': 1, 'lr': 0.001, 'weight_decay': 0.0005, 'nlayer': 3, 'hidden': 64, 'dropout': 0.5, 'batch_size': 128, 'standardize': False, 'seq_length': 5, 'epsilon1': 0.05, 'epsilon2': 0.1, 'outbase': './outputs', 'save_files': False, 'fedgraph_task': 'GC'} Dataset name: IMDB-BINARY Total number of graphs: 1000 .. GENERATED FROM PYTHON SOURCE LINES 52-54 Run FedGCN method ------------ .. GENERATED FROM PYTHON SOURCE LINES 54-56 .. code-block:: Python run_fedgraph(config, data) .. rst-class:: sphx-glr-script-out .. code-block:: none Done setting up devices. Running GCFL ... > Training round 10 finished. > Training round 20 finished. > Training round 30 finished. > Training round 40 finished. > Training round 50 finished. > Training round 60 finished. > Training round 70 finished. > Training round 80 finished. > Training round 90 finished. > Training round 100 finished. > Training round 110 finished. > Training round 120 finished. > Training round 130 finished. > Training round 140 finished. > Training round 150 finished. > Training round 160 finished. > Training round 170 finished. > Training round 180 finished. > Training round 190 finished. > Training round 200 finished. test_acc 0-IMDB-BINARY 0.583333 1-IMDB-BINARY 0.700000 2-IMDB-BINARY 0.545455 3-IMDB-BINARY 0.700000 4-IMDB-BINARY 0.600000 5-IMDB-BINARY 0.555556 6-IMDB-BINARY 0.181818 7-IMDB-BINARY 0.454545 8-IMDB-BINARY 0.600000 9-IMDB-BINARY 0.818182 Average test accuracy: 0.5711937211309069 .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 13.148 seconds) .. _sphx_glr_download_tutorials_simple_code_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: simple_code_example.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: simple_code_example.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_