## This file is part of the federated_learning_p2p (p2pfl) distribution# (see https://github.com/pguijas/p2pfl).# Copyright (c) 2022 Pedro Guijas Bravo.## This program is free software: you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation, version 3.## This program is distributed in the hope that it will be useful, but# WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU# General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program. If not, see <http://www.gnu.org/licenses/>.#"""Example of a P2PFL MNIST node using a MLP model and a MnistFederatedDM.This node only starts, create a node2 and connect to it in order to start the federated learning process."""importargparsefromp2pfl.learning.dataset.p2pfl_datasetimportP2PFLDatasetfromp2pfl.learning.frameworks.pytorch.lightning_learnerimportLightningLearnerfromp2pfl.learning.frameworks.pytorch.lightning_modelimportMLP,LightningModelfromp2pfl.nodeimportNodefromp2pfl.utils.utilsimportset_test_settingsset_test_settings()def__get_args()->argparse.Namespace:parser=argparse.ArgumentParser(description="P2PFL MNIST node using a MLP model and a MnistFederatedDM.")parser.add_argument("--port",type=int,help="The port.",required=True)returnparser.parse_args()
[docs]defnode1(port:int)->None:""" Start a node1 and waits for a key press to stop it. Args: port: The port where the node will be listening. """node=Node(LightningModel(MLP()),P2PFLDataset.from_huggingface("p2pfl/MNIST"),address=f"127.0.0.1:{port}",learner=LightningLearner)node.start()input("Press any key to stop\n")node.stop()