Skip to content
Snippets Groups Projects
Commit 612cf42e authored by Rishi Sharma's avatar Rishi Sharma
Browse files

Initial Commit

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #87726 failed
from decentralizepy.mappings.Mapping import Mapping
class Linear(Mapping):
"""
This class defines the mapping:
uid = machine_id * procs_per_machine + rank
"""
def __init__(self, n_machines, procs_per_machine):
"""
Constructor
Parameters
----------
n_machines : int
Number of machines involved in learning
procs_per_machine : int
Number of processes spawned per machine
"""
super().__init__(n_machines * procs_per_machine)
self.n_machines = n_machines
self.procs_per_machine = procs_per_machine
def get_uid(self, rank: int, machine_id: int):
"""
Gives the global unique identifier of the node
Parameters
----------
rank : int
Node's rank on its machine
machine_id : int
node's machine in the cluster
Returns
-------
int
the unique identifier
"""
return machine_id * self.procs_per_machine + rank
def get_machine_and_rank(self, uid: int):
"""
Gives the rank and machine_id of the node
Parameters
----------
uid : int
globally unique identifier of the node
Returns
-------
2-tuple
a tuple of machine_id and rank
"""
return (uid // self.procs_per_machine), (uid % self.procs_per_machine)
class Mapping:
"""
This class defines the bidirectional mapping between:
1. The unique identifier
2. machine_id and rank
"""
def __init__(self, n_procs):
"""
Constructor
"""
self.n_procs = n_procs
def get_uid(self, rank: int, machine_id: int):
"""
Gives the global unique identifier of the node
Parameters
----------
rank : int
Node's rank on its machine
machine_id : int
node's machine in the cluster
Returns
-------
int
the unique identifier
"""
raise NotImplementedError
def get_machine_and_rank(self, uid: int):
"""
Gives the rank and machine_id of the node
Parameters
----------
uid : int
globally unique identifier of the node
Returns
-------
2-tuple
a tuple of machine_id and rank
"""
raise NotImplementedError
from .Linear import Linear
from .Mapping import Mapping
class Node:
"""
This class defines the node (entity that performs learning, sharing and communication).
"""
def __init__(self, rank, mapping, graph, options):
"""
Constructor
Parameters
----------
rank : int
Rank of process local to the machine
mapping : decentralizepy.mappings
The object containing the mapping rank <--> uid
graph : decentralizepy.graphs
The object containing the global graph
dataset : decentralizepy.datasets class
The class whose object will be instantiated to init the dataset
"""
self.rank = rank
self.graph = graph
self.mapping = mapping
self.options = options
def __get_item__(self, i):
"""
Function to get the item with index i.
Parameters
----------
i : int
Index
Returns
-------
2-tuple
A tuple of the ith data sample and it's corresponding label
"""
return self.x[i], self.y[i]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment