-
Notifications
You must be signed in to change notification settings - Fork 20
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 function to output ParameterNode as YAML #295
base: master
Are you sure you want to change the base?
Conversation
…de data as a YAML file WIP fixes: PolicyEngine#274
…e node data as a YAML file WIP fixes: PolicyEngine#274
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #295 +/- ##
==========================================
+ Coverage 79.73% 83.10% +3.36%
==========================================
Files 192 193 +1
Lines 10057 10115 +58
Branches 1311 1051 -260
==========================================
+ Hits 8019 8406 +387
+ Misses 1753 1421 -332
- Partials 285 288 +3 ☔ View full report in Codecov by Sentry. |
WIP fixes: PolicyEngine#274
…ictionary form WIP fixes: PolicyEngine#274
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your continued work on this, @SylviaDu99. This is a challenging component, so it's great to have your experience here. I made a couple of structural recommendations, but a lot boils down to these two things:
- I'd move the meat of the function back to
ParameterNode
and limit the method you wrote inAtInstantLike
to do just what it says - get a dictionary of attributes - I'd programmatically iterate over all attrs, then remove ones we don't want, instead of hard-coding what we do want, as I think the former is more maintainable.
Thanks for your work, and I look forward to chatting with you about it tomorrow.
|
||
def get_attr_dict(self) -> dict: | ||
attr_dict = {} | ||
attr_list = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the best practice here would be to keep this method as simple as possible, then do a bit more work with it where we actually use it. What I would do here is:
- Programmatically loop over all attributes and feed into a relevant data structure
- Return said structure
I wouldn't recurse downward here, either. I think we can do that inside our custom ParameterNode
method, where we're more broadly defining what we're doing.
@@ -274,3 +276,11 @@ def get_child(self, path: str) -> "ParameterNode": | |||
f"Could not find the parameter (failed at {name})." | |||
) | |||
return node | |||
|
|||
def write_yaml(self, file_path: Path) -> yaml: | |||
data = self.get_attr_dict() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's at this point where I'd do some of what you've done in AtInstantLike
, though I'm not sure you need to hard-code the keys we need. I would just define a list of the keys we don't want, run the function from here, use the list to remove any keys we don't want, then recurse here, as you've done
…es in dictionary form; write_yaml in ParameterNode class now do most of the job WIP fixes: PolicyEngine#274
@SylviaDu99 Thanks for your revisions to this. I decided to test this out by printing out the entirety of the
|
WIP
fixes: #274
Added
write_yaml
function to output ParameterNode data to a YAML file;test_write_yaml
test to produce a sample output