Computes the total weights contained within a BinaryPartition subtree. Args: partition: a BinaryPartition subtree to compute the associated weights for weights_by_proc_id: a list of weights associated with each proc_id Returns: The sum of all weights for each proc_id enco
(
partition: mp.BinaryPartition, weights_by_proc_id: List[float]
)
| 50 | |
| 51 | |
| 52 | def get_total_weight( |
| 53 | partition: mp.BinaryPartition, weights_by_proc_id: List[float] |
| 54 | ) -> float: |
| 55 | """Computes the total weights contained within a BinaryPartition subtree. |
| 56 | |
| 57 | Args: |
| 58 | partition: a BinaryPartition subtree to compute the associated weights for |
| 59 | weights_by_proc_id: a list of weights associated with each proc_id |
| 60 | |
| 61 | Returns: |
| 62 | The sum of all weights for each proc_id encountered in the subtree. |
| 63 | |
| 64 | Raises: |
| 65 | ValueError: if sim.chunk_layout includes nodes with duplicate proc_ids |
| 66 | """ |
| 67 | if partition_has_duplicate_proc_ids(partition): |
| 68 | raise ValueError("Duplicate proc_ids found in chunk_layout!") |
| 69 | if partition.proc_id is not None: |
| 70 | return weights_by_proc_id[partition.proc_id] |
| 71 | elif partition.left is not None and partition.right is not None: |
| 72 | left_weight = get_total_weight(partition.left, weights_by_proc_id) |
| 73 | right_weight = get_total_weight(partition.right, weights_by_proc_id) |
| 74 | return left_weight + right_weight |
| 75 | else: |
| 76 | raise ValueError("Partition missing proc_id or left, right attributes!") |
| 77 | |
| 78 | |
| 79 | def get_left_right_total_weights( |
no test coverage detected