esm-tools / esm_runscripts

GNU General Public License v2.0
3 stars 5 forks source link

prints an explanatory error message if a scenario is not implemented … #174

Closed denizural closed 3 years ago

denizural commented 3 years ago

This PR solves the issue https://github.com/esm-tools/esm_runscripts/issues/172

I tested different solutions and finally decided that this one gives the most useful error message to the user. This error message provides the user

eg. if you try to run ECHAM with the scenario scenario: 1percCO2, now these lines will be printed:

ERROR: Missing Scenario Configuration
-------------------------------------

Scenario 1percCO2 for the model jsbach (version: 3.20p1) has not been implemented yet.
The input file variable LU_HIST of forcing_sources can not be fully resolved:

/work/bb0519/foci_input2/JSBACH/input/r0010/T63/New_Hampshire_LCC/hist_harvest/LUH_harvest_T63_1850.nc:
    to: 1850
/work/bb0519/foci_input2/JSBACH/input/r0010/T63/New_Hampshire_LCC/hist_harvest/LUH_harvest_T63_@YEAR@.nc:
    from: 1851

Instead of

Traceback (most recent call last):
  File "/home/shkifmsw/.local/bin/esm_runscripts", line 11, in <module>
    load_entry_point('esm-runscripts', 'console_scripts', 'esm_runscripts')()
  File "/home/shkifmsw/esm/esm_runscripts/esm_runscripts/cli.py", line 202, in main
    Setup()
  File "/home/shkifmsw/esm/esm_runscripts/esm_runscripts/sim_objects.py", line 50, in __call__
    self.compute(*args, **kwargs)
  File "/home/shkifmsw/esm/esm_runscripts/esm_runscripts/sim_objects.py", line 84, in compute
    self.config = compute.run_job(self.config)
  File "/home/shkifmsw/esm/esm_runscripts/esm_runscripts/compute.py", line 32, in run_job
    config = evaluate(config, "compute", "compute_recipe")
  File "/home/shkifmsw/esm/esm_runscripts/esm_runscripts/helpers.py", line 49, in evaluate
    framework_recipe, framework_plugins, config
  File "/home/shkifmsw/.local/lib/python3.7/site-packages/esm_plugin_manager/esm_plugin_manager.py", line 138, in work_through_recipe
    config = getattr(submodule, workitem)(config)
  File "/home/shkifmsw/esm/esm_runscripts/esm_runscripts/filelists.py", line 941, in assemble
    config = complete_targets(config)
  File "/home/shkifmsw/esm/esm_runscripts/esm_runscripts/filelists.py", line 126, in complete_targets
    config[model][filetype + "_sources"][categ]
  File "/sw/tools/python/anaconda3/2019.03/skl/lib/python3.7/posixpath.py", line 146, in basename
    p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not dict

I tried the same hack in other parts of the esm_runscripts but did not find anything yet. Maybe someone else will in the future and then we can use the same solution there too.

After the merge and bump, I will merge the HIST case stuff.

mandresm commented 3 years ago

This is very specific to models where scenario plays role and _sources are a dictionary. It could be that in the future we add more functionalities to the _sources making it sometimes a dict, or that other models use a different name than scenario for their case variable. Then the error message will be still confusing. I'm not sure, it looks that it needs to be a bit more general. What about not mentioning the scenario but just that the error looks like something like this:

ERROR: Sources not properly resolved
---------------------------------------

The input file variable LU_HIST of forcing_sources can not be fully resolved:

/work/bb0519/foci_input2/JSBACH/input/r0010/T63/New_Hampshire_LCC/hist_harvest/LUH_harvest_T63_1850.nc:
    to: 1850
/work/bb0519/foci_input2/JSBACH/input/r0010/T63/New_Hampshire_LCC/hist_harvest/LUH_harvest_T63_@YEAR@.nc:
    from: 1851

However, if _sources being a dictionary always depends on scenario and there is a specific handling of the scenario variable inside esm_runscripts then the fix is already good, as it would only happen when scenario is in use.

seb-wahl commented 3 years ago

Although I like the very precise error message, I think it's too specific. I would add the model version to the error message and leave out the scenario specific stuff. I vaguely think to remember that I had this error message in other cases, too, when @YEAR@ things could not be resolved. But apart from that. Thanks for the quick and solid fix to get rid of the confusing error message.