Source code for p2pfl.learning.frameworks.simulation
"""Module for the efficient parallel local simulation of the learning process (based on Ray)."""fromtypingimportTypefromp2pfl.learning.aggregators.aggregatorimportAggregatorfromp2pfl.learning.dataset.p2pfl_datasetimportP2PFLDatasetfromp2pfl.learning.frameworks.learnerimportLearnerfromp2pfl.learning.frameworks.p2pfl_modelimportP2PFLModelfromp2pfl.utils.check_rayimportray_installed#### Ray###
[docs]deftry_init_learner_with_ray(learner:Type[Learner],model:P2PFLModel,data:P2PFLDataset,addr:str,aggregator:Aggregator)->Learner:""" Create a learner instance. Args: learner: The learner class. model: The model of the learner. data: The data of the learner. addr: The address of the learner. aggregator: The aggregator that we are using. """learner_instance=learner(model,data,addr,aggregator=aggregator)ifray_installed():fromp2pfl.learning.frameworks.simulation.virtual_learnerimportVirtualNodeLearnerlearner_instance=VirtualNodeLearner(learner_instance,addr)returnlearner_instance