Improve Grid and Scenario init flexibility#323
Conversation
|
Haha, this makes life easier when doing quick checks 👍 |
| if isinstance(descriptor, int): | ||
| descriptor = str(descriptor) | ||
| if not isinstance(descriptor, str): | ||
| raise TypeError("Descriptor must be a string") |
There was a problem hiding this comment.
Should we change the error message to: descriptor must be a int/str ?
| raise ValueError(f"Engine must be one of {','.join(supported_engines)}") | ||
|
|
||
| if isinstance(interconnect, str): | ||
| interconnect = [interconnect] |
There was a problem hiding this comment.
Maybe we can add:
if not isinstance(interconnect, list):
raise TypeError("interconnect must be a str/list for a single-interconnect and a list for multiple")
and update the docstring accordingly. How does it sound
There was a problem hiding this comment.
"interconnect must be a str or list of str"? "single" and "multiple" doesn't really track for "USA", which is a single string representing three interconnects.
There was a problem hiding this comment.
I guess it would be nice to check the value of interconnect. We can use the check_interconnect function in the powersimdata.scenario.helpers module. It is probably out of the scope of the PR but since we are dealing with arguments it would be sweet.
There was a problem hiding this comment.
We already have a check_interconnect in powersimdata.network.usa_tamu.usa_tamu_model for the TAMU grids, this function gets used when we create scenarios so it should also have been checked by the time we're loading any grids/scenarios from FromREISE or FromREISEjl grids, right?
The version in powersimdata.scenario.helpers seems like it has some hardcoded values that apply to USA/TAMU but would not be valid once we expand our geographical reach.
There was a problem hiding this comment.
Indeed. I forgot about that one!
There was a problem hiding this comment.
I think at some we will need to set an attributes in the Grid class that encloses the model we use. Right now, it will always be usa_tamu. Each model will then have its own check_interconnect and other meaningful methods and a higher level function will use the right ones in the scenario framework depending on the model.
There was a problem hiding this comment.
That said, I am not sure that we need a new model in the ScenarioList.csv file. We could just pack a new str in the case.mat and we retrieve it when we build the grid back from the grid.mat. Because I really like to re-process the old MAT-file.
There was a problem hiding this comment.
Error message updated.
e55b5bf to
4e77e76
Compare
Purpose
Allow greater flexibility and reduce syntax for common inits.
What the code is doing
Testing
We can make use of the Grid equality check to test.
Time estimate
5 minutes