Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/lbaf/Utils/lbsJSONSpecFileMaker.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import os
import yaml
from typing import Set, List, Union

Check warning on line 3 in src/lbaf/Utils/lbsJSONSpecFileMaker.py

View workflow job for this annotation

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

Unused Set imported from typing (unused-import)

from lbaf.Execution.lbsPhaseSpecification import (
PhaseSpecification, SharedBlockSpecification,
RankSpecification, TaskSpecification,
PhaseSpecificationNormalizer
PhaseSpecificationNormalizer,
CommunicationSpecification
)

class JSONSpecFileMaker:
Expand All @@ -26,20 +27,22 @@
"shared": 0,
"rank": 0,
"phase": 0,
"comm": 0,
}

self.id_sets = {
"seq": set(),
"shared": set(),
"rank": set(),
"phase": set(),
"comm": set(),
}


###########################################################################
## Private generators

def generateNextID_(self, key: str) -> int:

Check notice on line 45 in src/lbaf/Utils/lbsJSONSpecFileMaker.py

View workflow job for this annotation

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

Method name "generateNextID_" doesn't conform to snake_case naming style (invalid-name)
"""
Generic function to generate and update the next available ID for a given category.
"""
Expand All @@ -53,7 +56,7 @@
self.current_ids[key] += 1
return next_id

def checkID_(self, try_id: int, key: str) -> int:

Check notice on line 59 in src/lbaf/Utils/lbsJSONSpecFileMaker.py

View workflow job for this annotation

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

Method name "checkID_" doesn't conform to snake_case naming style (invalid-name)

Check notice on line 59 in src/lbaf/Utils/lbsJSONSpecFileMaker.py

View workflow job for this annotation

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

Missing function or method docstring (missing-function-docstring)
if try_id < 0:
try_id = self.generateNextID_(key)
elif id in self.id_sets[key]:
Expand All @@ -64,11 +67,11 @@
###########################################################################
## Private functions for assertions

def assertIDExists_(self, test_id: int, id_type: str):

Check notice on line 70 in src/lbaf/Utils/lbsJSONSpecFileMaker.py

View workflow job for this annotation

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

Method name "assertIDExists_" doesn't conform to snake_case naming style (invalid-name)

Check notice on line 70 in src/lbaf/Utils/lbsJSONSpecFileMaker.py

View workflow job for this annotation

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

Missing function or method docstring (missing-function-docstring)
assert test_id in self.id_sets[id_type], \
f"Task {test_id} has not been created yet. Use createTask() method."

def assertAllTasksHaveBeenAssigned_(self):

Check notice on line 74 in src/lbaf/Utils/lbsJSONSpecFileMaker.py

View workflow job for this annotation

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

Method name "assertAllTasksHaveBeenAssigned_" doesn't conform to snake_case naming style (invalid-name)

Check notice on line 74 in src/lbaf/Utils/lbsJSONSpecFileMaker.py

View workflow job for this annotation

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

Missing function or method docstring (missing-function-docstring)
for t in self.tasks:
assert t in self.assignments, \
f"Task {t} has not been assigned. Call " \
Expand All @@ -79,7 +82,7 @@
###########################################################################
## Public Functions for creating JSON fields

def createTask(self,

Check notice on line 85 in src/lbaf/Utils/lbsJSONSpecFileMaker.py

View workflow job for this annotation

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

Too many arguments (8/7) (too-many-arguments)

Check notice on line 85 in src/lbaf/Utils/lbsJSONSpecFileMaker.py

View workflow job for this annotation

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

Method name "createTask" doesn't conform to snake_case naming style (invalid-name)

Check notice on line 85 in src/lbaf/Utils/lbsJSONSpecFileMaker.py

View workflow job for this annotation

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

Missing function or method docstring (missing-function-docstring)
time: float,
seq_id: int = -1,
collection_id: int = 7,
Expand All @@ -102,10 +105,10 @@
return task

def createSharedBlock(self,
bytes: float,

Check warning on line 108 in src/lbaf/Utils/lbsJSONSpecFileMaker.py

View workflow job for this annotation

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

Redefining built-in 'bytes' (redefined-builtin)
tasks: Union[List[int], List[TaskSpecification]],
rank_id: int = -1,
id: int = -1):

Check warning on line 111 in src/lbaf/Utils/lbsJSONSpecFileMaker.py

View workflow job for this annotation

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

Redefining built-in 'id' (redefined-builtin)
shared_id = self.checkID_(id, "shared")
shared_block = SharedBlockSpecification({
"size": bytes,
Expand All @@ -123,13 +126,22 @@
task_specs[t["seq_id"]] = t
else:
raise RuntimeError(
f"tasks must be a list of ints (IDs) or TaskSpecifications")

Check warning on line 129 in src/lbaf/Utils/lbsJSONSpecFileMaker.py

View workflow job for this annotation

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

Using an f-string that does not have any interpolated variables (f-string-without-interpolation)
shared_block["tasks"] = task_specs
self.shared_blocks[shared_id] = shared_block
return shared_block

def createComm(self, to_obj : int, from_obj : int, size : float) -> CommunicationSpecification:
new_comm = CommunicationSpecification({
'size': size,
'from': from_obj,
'to': to_obj
})
comm_id = self.checkID_(-1, "comm")
self.comms[comm_id] = new_comm

def createRank(self,
id: int = -1,

Check warning on line 144 in src/lbaf/Utils/lbsJSONSpecFileMaker.py

View workflow job for this annotation

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

Redefining built-in 'id' (redefined-builtin)
tasks: Union[List[int], List[TaskSpecification]] = None,
user_defined: dict = None
) -> RankSpecification:
Expand Down Expand Up @@ -192,13 +204,13 @@
###########################################################################
## Standard Getters

def getRank(self, id: int) -> RankSpecification:

Check warning on line 207 in src/lbaf/Utils/lbsJSONSpecFileMaker.py

View workflow job for this annotation

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

Redefining built-in 'id' (redefined-builtin)
return self.ranks[id]

def getTask(self, seq_id: int) -> TaskSpecification:
return self.tasks[seq_id]

def getSharedBlock(self, id: int) -> SharedBlockSpecification:

Check warning on line 213 in src/lbaf/Utils/lbsJSONSpecFileMaker.py

View workflow job for this annotation

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

Redefining built-in 'id' (redefined-builtin)
return self.shared_blocks[id]

###########################################################################
Expand All @@ -220,5 +232,18 @@
# Write out the spec
path = os.path.join(os.getcwd(), "spec.yaml") if path is None else path
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, 'w') as output_file:

Check warning on line 235 in src/lbaf/Utils/lbsJSONSpecFileMaker.py

View workflow job for this annotation

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

Using open without explicitly specifying an encoding (unspecified-encoding)
yaml.dump(spec, output_file, default_flow_style=False)

def makeSpecification(self, phase_id):
self.assertAllTasksHaveBeenAssigned_()
phase = PhaseSpecification({
"tasks": self.tasks,
"shared_blocks": self.shared_blocks,
"communications": self.comms,
"ranks": self.ranks,
"id": phase_id
})
norm = PhaseSpecificationNormalizer()
spec = norm.normalize(phase)
return spec
Loading