Skip to content

Commit

Permalink
#558: base of reconstructed PR post conflict resolution and integrati…
Browse files Browse the repository at this point in the history
…on of changes
  • Loading branch information
ppebay committed Dec 30, 2024
1 parent 1fb6416 commit 285e66a
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/lbaf/Applications/LBAF_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class InternalParameters:

# From data input options
data_stem: Optional[str] = None
ranks_per_node : Optional[int] = 1

# From samplers input options
n_ranks: Optional[int] = None
Expand Down Expand Up @@ -150,6 +151,8 @@ def init_parameters(self, config: dict, base_dir: str):
else:
self.phase_ids = from_data.get("phase_ids")
self.expected_ranks = from_data.get("expected_ranks")
if (rpn := from_data.get("ranks_per_node")) is not None:
self.ranks_per_node = int(rpn)

# Parse sampling parameters if present
from_samplers = config.get("from_samplers")
Expand Down
12 changes: 12 additions & 0 deletions src/lbaf/Execution/lbsAlgorithmBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@ def _initialize(self, p_id, phases, statistics):
f"across {self._rebalanced_phase.get_number_of_ranks()} ranks "
f"into phase {self._rebalanced_phase.get_id()}")

# Replicate nodes on rebalanced phase
ranks_per_node = 1
new_nodes: List[Node] = []

Check failure on line 200 in src/lbaf/Execution/lbsAlgorithmBase.py

View workflow job for this annotation

GitHub Actions / code-quality (ubuntu-latest, 3.8)

Undefined variable 'Node' (undefined-variable)
phase_ranks = self._initial_phase.get_ranks()
if (nr := len(phase_ranks)) > 0 and phase_ranks[0].node is not None:
ranks_per_node = phase_ranks[0].node.get_number_of_ranks()
if ranks_per_node > 1:
n_nodes = int(nr / ranks_per_node)
new_nodes = list(map(
lambda n_id: Node(self._logger, n_id),

Check failure on line 207 in src/lbaf/Execution/lbsAlgorithmBase.py

View workflow job for this annotation

GitHub Actions / code-quality (ubuntu-latest, 3.8)

Undefined variable 'Node' (undefined-variable)
list(range(0, n_nodes))))

# Initialize run statistics
self._update_statistics(statistics)

Expand Down
75 changes: 75 additions & 0 deletions src/lbaf/Model/lbsNode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#
#@HEADER
###############################################################################
#
# lbsNode.py
# DARMA/LB-analysis-framework => LB Analysis Framework
#
# Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
# (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
# Government retains certain rights in this software.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Questions? Contact [email protected]
#
###############################################################################
#@HEADER
#

import copy

Check warning on line 44 in src/lbaf/Model/lbsNode.py

View workflow job for this annotation

GitHub Actions / code-quality (ubuntu-latest, 3.8)

Unused import copy (unused-import)
import math

Check warning on line 45 in src/lbaf/Model/lbsNode.py

View workflow job for this annotation

GitHub Actions / code-quality (ubuntu-latest, 3.8)

Unused import math (unused-import)
import functools
import operator
from logging import Logger
from typing import Optional

Check warning on line 49 in src/lbaf/Model/lbsNode.py

View workflow job for this annotation

GitHub Actions / code-quality (ubuntu-latest, 3.8)

Unused Optional imported from typing (unused-import)

class Node:
"""A class representing a node to which a set of ranks are assigned."""

def __init__(
self,
logger: Logger,
n_id: int = -1):

# Assign logger to instance variable
self.__logger = logger #pylint:disable=unused-private-member

# Member variables passed by constructor
self.__index = n_id

Check warning on line 63 in src/lbaf/Model/lbsNode.py

View workflow job for this annotation

GitHub Actions / code-quality (ubuntu-latest, 3.8)

Unused private member `Node.__index` (unused-private-member)
self.__ranks = set()

def get_max_memory_usage(self):
"""Combine all memory usages for each rank to get the node memory usage."""
return functools.reduce(
operator.add, map(lambda r: r.get_max_memory_usage(), list(self.__ranks)))

def add_rank(self, rank):
self.__ranks.add(rank)

def get_number_of_ranks(self) -> int:
return len(self.__ranks)
2 changes: 1 addition & 1 deletion src/lbaf/Model/lbsPhase.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def get_ranks(self):

def copy_ranks(self, phase: Self):
"""Copy ranks from one phase to self."""
new_ranks = set()
new_ranks: Set[Rank] = set()
for r in phase.get_ranks():
# Minimally instantiate rank and copy
new_r = Rank(self.__logger)
Expand Down
19 changes: 13 additions & 6 deletions src/lbaf/Model/lbsRank.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,21 @@
from .lbsBlock import Block
from .lbsObject import Object
from .lbsQOIDecorator import qoi
from .lbsNode import Node

class Rank:
"""A class representing a rank to which objects are assigned."""

def __init__(
self,
logger: Logger,
r_id: int = -1,
migratable_objects: set = None,
sentinel_objects: set = None):
self,
logger: Logger,
r_id: int = -1,
migratable_objects: set = None,
sentinel_objects: set = None,
node: Node = None):

# Assign logger to instance variable
self.__logger = logger #pylint:disable=unused-private-member
self.__logger = logger

# Member variables passed by constructor
self.__index = r_id
Expand All @@ -82,6 +84,11 @@ def __init__(
# Start with empty metadata
self.__metadata = {}

# Optionally, the rank is connected to a node
self.node = node
if node is not None:
node.add_rank(self)

def copy(self, rank):
"""Specialized copy method."""
# Copy all flat member variables
Expand Down

0 comments on commit 285e66a

Please sign in to comment.