4747
4848from .lbsBlock import Block
4949from .lbsObject import Object
50-
50+ from . lbsQOIDecorator import qoi
5151
5252class Rank :
5353 """A class representing a rank to which objects are assigned."""
@@ -99,12 +99,14 @@ def __lt__(self, other):
9999 def __repr__ (self ):
100100 return f"<Rank index: { self .__index } >"
101101
102+ @qoi
102103 def get_id (self ) -> int :
103104 """Return rank ID."""
104105 return self .__index
105106
107+ @qoi
106108 def get_size (self ) -> float :
107- """Return object size ."""
109+ """Return rank working memory ."""
108110 return self .__size
109111
110112 def set_size (self , size ):
@@ -162,26 +164,31 @@ def get_shared_block_with_id(self, b_id: int) -> Block:
162164 return block
163165 return None
164166
167+ @qoi
165168 def get_number_of_shared_blocks (self ) -> float :
166169 """Return number of shared memory blocks on rank."""
167170 return len (self .__shared_blocks )
168171
172+ @qoi
169173 def get_number_of_homed_blocks (self ) -> float :
170174 """Return number of memory blocks on rank also homed there."""
171175 return sum (
172176 b .get_home_id () == self .get_id ()
173177 for b in self .__shared_blocks )
174178
179+ @qoi
175180 def get_number_of_uprooted_blocks (self ) -> float :
176181 """Return number of uprooted memory blocks on rank."""
177182 return len (self .__shared_blocks ) - self .get_number_of_homed_blocks ()
178183
184+ @qoi
179185 def get_homed_blocks_ratio (self ) -> float :
180186 """Return fraction of memory blocks on rank also homed there."""
181187 if len (self .__shared_blocks ) > 0 :
182188 return self .get_number_of_homed_blocks () / len (self .__shared_blocks )
183189 return math .nan
184190
191+ @qoi
185192 def get_shared_memory (self ):
186193 """Return total shared memory on rank."""
187194 return float (sum (b .get_size () for b in self .__shared_blocks ))
@@ -190,6 +197,7 @@ def get_objects(self) -> set:
190197 """Return all objects assigned to rank."""
191198 return self .__migratable_objects .union (self .__sentinel_objects )
192199
200+ @qoi
193201 def get_number_of_objects (self ) -> int :
194202 """Return number of objects assigned to rank."""
195203 return len (self .__sentinel_objects ) + len (self .__migratable_objects )
@@ -241,18 +249,22 @@ def remove_migratable_object(self, o: Object):
241249 """Remove objects from migratable objects."""
242250 self .__migratable_objects .remove (o )
243251
252+ @qoi
244253 def get_load (self ) -> float :
245254 """Return total load on rank."""
246255 return sum (o .get_load () for o in self .__migratable_objects .union (self .__sentinel_objects ))
247256
257+ @qoi
248258 def get_migratable_load (self ) -> float :
249259 """Return migratable load on rank."""
250260 return sum (o .get_load () for o in self .__migratable_objects )
251261
262+ @qoi
252263 def get_sentinel_load (self ) -> float :
253264 """Return sentinel load on rank."""
254265 return sum (o .get_load () for o in self .__sentinel_objects )
255266
267+ @qoi
256268 def get_received_volume (self ):
257269 """Return volume received by objects assigned to rank from other ranks."""
258270 # Iterate over all objects assigned to rank
@@ -269,6 +281,7 @@ def get_received_volume(self):
269281 # Return computed volume
270282 return volume
271283
284+ @qoi
272285 def get_sent_volume (self ):
273286 """Return volume sent by objects assigned to rank to other ranks."""
274287 # Iterate over all objects assigned to rank
@@ -287,6 +300,7 @@ def get_sent_volume(self):
287300 # Return computed volume
288301 return volume
289302
303+ @qoi
290304 def get_max_object_level_memory (self ) -> float :
291305 """Return maximum object-level memory on rank."""
292306 # Iterate over all objects assigned to rank
@@ -302,6 +316,16 @@ def get_max_object_level_memory(self) -> float:
302316 # Return maximum object-level memory for this rank
303317 return total_size + max_overhead
304318
319+ @qoi
305320 def get_max_memory_usage (self ) -> float :
306321 """Return maximum memory usage on rank."""
307322 return self .__size + self .get_shared_memory () + self .get_max_object_level_memory ()
323+
324+ def get_QOIs (self ) -> list :
325+ """Get all methods decorated with the QOI decorator.
326+ """
327+ qoi_methods : dict = {
328+ name : getattr (self , name )
329+ for name in dir (self )
330+ if callable (getattr (self , name )) and not name .startswith ("__" ) and hasattr (getattr (self , name ), "is_qoi" ) }
331+ return qoi_methods
0 commit comments