Feature: run prototype with command line tool#36
Conversation
Signed-off-by: Sylvain Leclerc <sylvain.leclerc@rte-france.com>
to test see tests/unittests/data/components_for_thermal_cluster.yml
allows to take data with several scenarios
src/andromede/main/main.py
Outdated
| return resolve_components_and_cnx(parse_yaml_components(comp), model) | ||
|
|
||
|
|
||
| if __name__ == "__main__": |
There was a problem hiding this comment.
For clarity, I suggest to put all that is bellow here in a "main" function:
| if __name__ == "__main__": | |
| if __name__ == "__main__": | |
| main() |
enable the possibility to use the command with only the parameter --study fix the fact that the preloaded_libraries parameter in the resolve_library method didn't keep the preloaded models in the returned library
src/andromede/main/main.py
Outdated
| database = None | ||
|
|
||
| if args.study: | ||
| if args.models or args.component or args.timeseries: |
There was a problem hiding this comment.
I think there's a way in ParseArgs to create exclusive groups, i.e., sets of arguments that can't be passed together so you would automatically check for this, but maybe it won't be enough for your needs here :)
There was a problem hiding this comment.
there is but you can't make an argument excludes with other arguments which are not mutually exclusive
the importing order is an depth-first travelsal of the tree going from every library to the root or an already imported library the algo : - checks if there is cycles and raise error if so - can import models form 2 separated tree - doesnt check if ports are defined twice no test available the code isnt commented
sylvlecl
left a comment
There was a problem hiding this comment.
A few suggestions:
- adding a "console script" entry point
- moving some new methods to more appropriate places in inner modules
src/andromede/model/parsing.py
Outdated
|
|
||
| class InputLibrary(BaseModel): | ||
| id: str | ||
| dependence: Optional[str] = None |
There was a problem hiding this comment.
We should allow a list here to import multiple libraries --> "dependencies"
src/andromede/main/main.py
Outdated
| if import_stack[-1].dependence in did: | ||
| lib = resolve_library(import_stack[-1], [output_lib]) | ||
|
|
||
| output_lib.models.update(lib.models) |
There was a problem hiding this comment.
we can add a check here that there is no name conflict between models
src/andromede/main/main.py
Outdated
| lib = resolve_library(import_stack[-1], [output_lib]) | ||
|
|
||
| output_lib.models.update(lib.models) | ||
| output_lib.port_types.update(lib.port_types) |
There was a problem hiding this comment.
we can add a check here that there is no name conflict between port types
src/andromede/main/main.py
Outdated
| yaml_libraries[yaml_lib.id] = yaml_lib | ||
|
|
||
| todo = list(yaml_libraries.values()) | ||
| did = list() |
There was a problem hiding this comment.
Note that it's better to use a set for this kind of use: a search in a set is more efficient than in a list (to be honest here it does not really matter in practice because it will always be small).
src/andromede/main/main.py
Outdated
| parser.error( | ||
| "--study flag can't be use with --models, --component and --timeseries" | ||
| ) | ||
| components_path = args.study / "input" / "components" / "components.yml" |
There was a problem hiding this comment.
Let's move this logic (of parsing all data from one directory) to andromede.study.parsing
src/andromede/main/main.py
Outdated
| print("scenario ", scenario) | ||
| print("status : ", status) | ||
|
|
||
| print("avarage final cost : ", problem.solver.Objective().Value()) |
src/andromede/main/main.py
Outdated
| def main() -> None: | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument( | ||
| "--study", type=Path, help="path to the root dirertory of the study" |
src/andromede/main/main.py
Outdated
| "--component", type=Path, help="path to the component file, *.yml" | ||
| ) | ||
| parser.add_argument( | ||
| "--timeseries", type=Path, help="path to the timeseries dirertory" |
fix old test, changing input library to list of input libraries
No description provided.