Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to to_dict functions to Destination and TagSetManager classes #119

Merged
merged 6 commits into from
Jan 17, 2024
Merged
Changes from 1 commit
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
42 changes: 42 additions & 0 deletions tpv/core/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ def from_dict(tags: list[dict]) -> TagSetManager:
tag_list.append(Tag(name="scheduling", value=tag_val, tag_type=TagType.REJECT))
return TagSetManager(tags=tag_list)

def to_dict(self) -> dict:
result_dict = {
'require': [tag.value for tag in self.tags if tag.tag_type == TagType.REQUIRE],
'prefer': [tag.value for tag in self.tags if tag.tag_type == TagType.PREFER],
'accept': [tag.value for tag in self.tags if tag.tag_type == TagType.ACCEPT],
'reject': [tag.value for tag in self.tags if tag.tag_type == TagType.REJECT]
}
return result_dict


class Entity(object):

Expand Down Expand Up @@ -578,6 +587,39 @@ def from_dict(loader, entity_dict):
handler_tags=entity_dict.get('tags')
)

def to_dict(self):
dest_dict = {
'id': self.id,
'abstract': self.abstract,
'runner': self.runner,
'destination_name_override': self.dest_name,
'cores': self.cores,
'mem': self.mem,
'gpus': self.gpus,
'min_cores': self.min_cores,
'min_mem': self.min_mem,
'min_gpus': self.min_gpus,
'max_cores': self.max_cores,
'max_mem': self.max_mem,
'max_gpus': self.max_gpus,
'min_accepted_cores': self.min_accepted_cores,
'min_accepted_mem': self.min_accepted_mem,
'min_accepted_gpus': self.min_accepted_gpus,
'max_accepted_cores': self.max_accepted_cores,
'max_accepted_mem': self.max_accepted_mem,
'max_accepted_gpus': self.max_accepted_gpus,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be split I think, otherwise, the superclass method will be aware of its subclasses. The min_accepted related fields should go to the Destination class, and rules should go to the EntityWithRules class.

'env': self.env,
'params': self.params,
'resubmit': self.resubmit,
'scheduling': self.tpv_dest_tags.to_dict(),
'inherits': self.inherits,
'context': self.context,
'rules': self.rules,
'tags': self.handler_tags
}

return dest_dict

def __repr__(self):
return f"runner={self.runner}, dest_name={self.dest_name}, min_accepted_cores={self.min_accepted_cores}, "\
f"min_accepted_mem={self.min_accepted_mem}, min_accepted_gpus={self.min_accepted_gpus}, "\
Expand Down