Skip to content

Commit

Permalink
#562: writer: use object qoi getter instead of hard-coded qois
Browse files Browse the repository at this point in the history
  • Loading branch information
cwschilly committed Dec 19, 2024
1 parent 6228882 commit cb24d13
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
34 changes: 13 additions & 21 deletions src/lbaf/IO/lbsVTDataWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ def __init__(
def __create_tasks(self, rank_id, objects, migratable):
"""Create per-object entries to be outputted to JSON."""
tasks = []
entity_qoi = ["id", "seq_id", "collection_id", "index"]
exclude_from_user_defined = ["packed_id", "load", "shared_id"]

for o in objects:
unused_params = o.get_unused_params()
task_data = {
"entity": {
"home": rank_id,
Expand All @@ -115,41 +117,31 @@ def __create_tasks(self, rank_id, objects, migratable):
"time": o.get_load()
}

if o.get_packed_id() is not None:
task_data["entity"]["id"] = o.get_packed_id()

if o.get_seq_id() is not None:
task_data["entity"]["seq_id"] = o.get_seq_id()

if o.get_collection_id() is not None:
task_data["entity"]["collection_id"] = o.get_collection_id()

if o.get_index() is not None:
task_data["entity"]["index"] = o.get_index()

unused_params = o.get_unused_params()
if unused_params:
task_data["entity"].update(unused_params)

task_data["entity"] = dict(sorted(task_data["entity"].items()))

user_defined = o.get_user_defined()
if user_defined:
task_data["user_defined"] = dict(sorted(user_defined.items()))
else:
task_data["user_defined"] = dict()

Check notice on line 128 in src/lbaf/IO/lbsVTDataWriter.py

View workflow job for this annotation

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

Consider using '{}' instead of a call to 'dict'. (use-dict-literal)

task_data["user_defined"]["object_memory"] = o.get_size()
task_data["user_defined"]["object_overhead_memory"] = o.get_overhead()
task_data["user_defined"]["rank_id"] = o.get_rank_id()
task_data["user_defined"]["sent_volume"] = o.get_sent_volume()
task_data["user_defined"]["received_volume"] = o.get_received_volume()
task_data["user_defined"]["max_volume"] = o.get_max_volume()
object_qois = o.get_QOIs()

for qoi_name, qoi_getter in object_qois.items():
if qoi_name in entity_qoi and qoi_getter() is not None:
task_data["entity"][qoi_name] = qoi_getter()
elif qoi_name not in (entity_qoi + exclude_from_user_defined):
task_data["user_defined"][qoi_name] = qoi_getter()

if o.get_shared_id() is not None:
task_data["user_defined"]["shared_id"] = o.get_shared_id()
else:
task_data["user_defined"]["shared_id"] = -1

task_data["entity"] = dict(sorted(task_data["entity"].items()))

tasks.append(task_data)

return tasks
Expand Down
7 changes: 6 additions & 1 deletion src/lbaf/Model/lbsObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,12 @@ def get_unused_params(self) -> dict:

def __get_qoi_name(self, qoi_ftn) -> str:
"""Return the QOI name from the given QOI getter function"""
return qoi_ftn[4:] if qoi_ftn.startswith("get_") else qoi_ftn
qoi = qoi_ftn[4:] if qoi_ftn.startswith("get_") else qoi_ftn

Check warning on line 300 in src/lbaf/Model/lbsObject.py

View workflow job for this annotation

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

Redefining name 'qoi' from outer scope (line 47) (redefined-outer-name)
if qoi == "size":
qoi = "object_memory"
elif qoi == "overhead":
qoi = "overhead_memory"
return qoi

def get_QOIs(self) -> list:
"""Get all methods decorated with the QOI decorator.
Expand Down

0 comments on commit cb24d13

Please sign in to comment.