rl-institut / multi-vector-simulator

Multi-vector Simulation Tool assessing and optimizing Local Energy Systems (LES) for the E-LAND project
GNU General Public License v2.0
21 stars 10 forks source link

No check of completeness or default values for json input keys implemented #750

Open smartie2076 opened 3 years ago

smartie2076 commented 3 years ago

As noticed in #722, there is no test implemented that makes sure that a json file provided to the MVS contains all necessary keys, and therefore no default values can be added.

For the csv input files, this is done with REQUIRED_CSV_PARAMETERS, and complimenting this EXTRA_CSV_PARAMETERS adds default values for new parameters that are not jet required. This enables adding new features with new parameters.

However, this check is not run when a json file is used as an input. There are no error messages if parameters are missing, at least not if they are extra parameters. This also means that it is impossible to provide an outdated json file (eg. from the EPA) to the MVS, as the EXTRA_CSV_PARAMETERS are not added to the input file! This requires us to change the EPA-MVS parser everytime whe change the MVS, which we want to avoid using default values for new parameters.

E           AssertionError: In path /home/runner/work/multi-vector-simulator/multi-vector-simulator/tests/benchmark_test_inputs/rerun/mvs_config.json, the following parameters are missing:{'project_data': ['scenario_description']}
E           assert 'missing_parameters' not in {'extra_parameters': {'economic_data': ['crf', 'annuity_factor'], 'paths_to_plots': [], 'project_data': ['sectors'], '...er', 'path_input_folder', 'end_date', 'time_index']}, 'missing_parameters': {'project_data': ['scenario_description']}}
smartie2076 commented 3 years ago

@mahendrark this is what I ment with my comment. Can you provide the json input files that I asked for in the checklist? Especially for EXTRA_CSV_PARAMETERS.

Bachibouzouk commented 3 years ago

The general json structure we have is minimal and could be expanded.

If you wish, we can provide a json schema to check any json against. There is documentation of the special meta json format of json schema. It is like a declarative json file where you have extra special attributes to specify what type is the attribute expected to be. It takes a little while to produce the schema but then it is quite handy to check whether a json file matches the schema or not (and we can define some attributes to be required or not). This is best to only do once we are sure the structure of the json will not change too much :)

Bachibouzouk commented 3 years ago

The strategy I had in the past, as we concentrate more on csv input, is to use the generated json form the csv. A good test would be to compare all the results of a simulation ran with -ext csv and -ext json with the json file generated from the csv, these should be the same

Bachibouzouk commented 3 years ago

utils.compare_input_parameters_with_reference is a function we can use for that purpose

Bachibouzouk commented 3 years ago

Might have been fixed by #761