Skip to content

Commit

Permalink
#323: displaced CMF calculation where it belongs
Browse files Browse the repository at this point in the history
  • Loading branch information
ppebay committed Jun 11, 2023
1 parent 0e1a92a commit a37415c
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion config/conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ algorithm:
transfer_strategy: Recursive
criterion: Tempered
max_objects_per_transfer: 8
deterministic_transfer: True
deterministic_transfer: False

# Specify output
output_dir: ../output
Expand Down
4 changes: 2 additions & 2 deletions config/user-defined-memory-toy-problem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from_data:
data_stem: ../data/user-defined-memory-toy-problem/toy_mem
phase_ids:
- 0
check_schema: True
check_schema: False

# Specify work model
work_model:
Expand All @@ -27,7 +27,7 @@ algorithm:
transfer_strategy: Clustering
criterion: Tempered
max_objects_per_transfer: 32
deterministic_transfer: True
deterministic_transfer: False

# Specify output
output_dir: ../output
Expand Down
1 change: 0 additions & 1 deletion somefile

This file was deleted.

4 changes: 2 additions & 2 deletions src/lbaf/Execution/lbsClusteringTransferStrategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ def execute(self, known_peers, phase: Phase, ave_load: float):
r_dst = r_try
else:
# Compute transfer CMF given information known to source
p_cmf, c_values = r_src.compute_transfer_cmf(
self._criterion, o_src, targets, False)
p_cmf, c_values = self._compute_transfer_cmf(
r_src, o_src, targets, False)
self._logger.debug(f"CMF = {p_cmf}")
if not p_cmf:
n_rejects += 1
Expand Down
4 changes: 2 additions & 2 deletions src/lbaf/Execution/lbsRecursiveTransferStrategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def execute(self, known_peers, phase: Phase, ave_load: float):
r_dst = r_try
else:
# Compute transfer CMF given information known to source
p_cmf, c_values = r_src.compute_transfer_cmf(
self._criterion, o_src, targets, False)
p_cmf, c_values = self._compute_transfer_cmf(
r_src, o_src, targets, False)
self._logger.debug(f"CMF = {p_cmf}")
if not p_cmf:
n_rejects += 1
Expand Down
41 changes: 41 additions & 0 deletions src/lbaf/Execution/lbsTransferStrategyBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,47 @@ def __init__(self, criterion, parameters: dict, lgr: Logger):
lgr.info(
f"Created {'' if self._deterministic_transfer else 'non'}deterministic transfer strategy, max. {self._max_objects_per_transfer} objects")


def _compute_transfer_cmf(self, r_src, objects: list, targets: set, strict=False):
"""Compute CMF for the sampling of transfer targets."""
# Initialize criterion values
c_values = {}
c_min, c_max = math.inf, -math.inf

# Iterate over potential targets
for r_dst in targets:
# Compute value of criterion for current target
c_dst = self._criterion.compute(r_src, objects, r_dst)

# Do not include rejected targets for strict CMF
if strict and c_dst < 0.:
continue

# Update criterion values
c_values[r_dst] = c_dst
if c_dst < c_min:
c_min = c_dst
if c_dst > c_max:
c_max = c_dst

# Initialize CMF depending on singleton or non-singleton support
if c_min == c_max:
# Sample uniformly if all criteria have same value
cmf = {k: 1.0 / len(c_values) for k in c_values.keys()}
else:
# Otherwise, use relative weights
c_range = c_max - c_min
cmf = {k: (v - c_min) / c_range for k, v in c_values.items()}

# Compute CMF
sum_p = 0.0
for k, v in cmf.items():
sum_p += v
cmf[k] = sum_p

# Return normalized CMF and criterion values
return {k: v / sum_p for k, v in cmf.items()}, c_values

@staticmethod
def factory(
strategy_name:str,
Expand Down
40 changes: 0 additions & 40 deletions src/lbaf/Model/lbsRank.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,43 +244,3 @@ def get_max_object_level_memory(self) -> float:
def get_max_memory_usage(self) -> float:
"""Return maximum memory usage on rank."""
return self.__size + self.get_shared_memory() + self.get_max_object_level_memory()

def compute_transfer_cmf(self, transfer_criterion, objects: list, targets: set, strict=False):
"""Compute CMF for the sampling of transfer targets."""
# Initialize criterion values
c_values = {}
c_min, c_max = math.inf, -math.inf

# Iterate over potential targets
for r_dst in targets:
# Compute value of criterion for current target
c_dst = transfer_criterion.compute(self, objects, r_dst)

# Do not include rejected targets for strict CMF
if strict and c_dst < 0.:
continue

# Update criterion values
c_values[r_dst] = c_dst
if c_dst < c_min:
c_min = c_dst
if c_dst > c_max:
c_max = c_dst

# Initialize CMF depending on singleton or non-singleton support
if c_min == c_max:
# Sample uniformly if all criteria have same value
cmf = {k: 1.0 / len(c_values) for k in c_values.keys()}
else:
# Otherwise, use relative weights
c_range = c_max - c_min
cmf = {k: (v - c_min) / c_range for k, v in c_values.items()}

# Compute CMF
sum_p = 0.0
for k, v in cmf.items():
sum_p += v
cmf[k] = sum_p

# Return normalized CMF and criterion values
return {k: v / sum_p for k, v in cmf.items()}, c_values

0 comments on commit a37415c

Please sign in to comment.