-
Notifications
You must be signed in to change notification settings - Fork 0
Support User Query Functions #7
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
Conversation
sarahmish
left a comment
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.
Hi @amzhao16, thank you for opening up this issue! I am thinking about this implementation and have a few suggestions:
- creating
countsdoes help us have one source for counts instead of investigating the variables of all loads, lines, etc. - this, however, removes the readability of the PyGridSim object where now I need two steps into finding how many transformers or loads there are.
- I'm wondering if we can look into a solution that bridges both
Here is an example using __dict__ to get the attributes of a class.
In [2]: class Example:
...: def __init__(self):
...: self.num_loads = 0
...: self.num_lines = 0
...: self.num_pv = 0
In [3]: e = Example()
In [4]: e.__dict__
Out[4]: {'num_loads': 0, 'num_lines': 0, 'num_pv': 0}or a safer implementation would be to implement a function:
def get_counts(self):
return {
"loads": self.num_loads,
"lines": self.num_lines,
...etc
}
I am a bit confused on how these methods reduce the number of calls we would have to make. With the dictionary, wouldn't we still need to do e.dict['num_loads'], which is I think as complicated and less readable than doing something like self.counts['num_loads']. The function implementation still necessitates us to initiate all the variables, which is what I was trying to avoid (self.num_loads, self.num_lines, etc.) but to fetch counts I still have to go through two steps, like get_counts["loads"]. I can switch back to just using self.num_loads, self.num_lines, etc. directly if that's better, but am a bit confused on how these suggestions would mitigate the concern. Thanks, let me know if I'm missing something |
|
It doesn't reduce the number of calls. I want to maintain the readability of the |
Ah I understand. Would it be better to just keep the variables separate then (as it originally was), to keep the readability? I wanted to reduce the number of lines but am thinking the simplest way to preserve this would just be to have them separately. (I didn't think about the fact that users can also just do like circuit.num_loads, but given this information, probably is best to just keep it separate?) |
sarahmish
left a comment
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.
lgtm, thanks @amzhao16!
Add get_types function, where the user can input a component (i.e. "load") and see a list of all possible default parameter sets for that component. Optionally, they can set show_ranges = True which prints the entire config of each type as well.
Add corresponding test suite for this user query functionality.
Also, made a fix to make the init parameters more efficient: just one class variable "self.count" that stores all counts instead of 5 different count variables.