Skip to content

Variables in ${...} notation are not resolved when the date is initialized. #1453

Description

@seb-wahl

Describe the bug
Variables in ${...} notation are not resolved when the date is initialized.

To Reproduce
Add the following to your runscript

general:
   runlength: 1
   unit: 'm' # 'd' for day, 'y' for year
   choose_unit:
      'd':
         nday: ${general.runlength}
         unitUpper: 'D'
      'm':
         #nmonth: 1                                # works
         nmonth: ${general.runlength} # doesn't work
         unitUpper: 'M'
      'y':
         nyear: ${runlength}
         unitUpper: 'Y'

crashes with the following error:

(esm-tools) [b350071@levante1 icon-fesom]$ esm_runscripts -e if325 icon-fesom-pictl-v3-daily.yaml
Initializing run_number=12 and date=1850-05-01_00:00:00
Traceback (most recent call last):
  File "/home/b/b350071/miniforge3/envs/esm-tools/bin/esm_runscripts", line 33, in <module>
    sys.exit(load_entry_point('esm-tools', 'console_scripts', 'esm_runscripts')())
  File "/home/b/b350071/esm/esm_tools/src/esm_runscripts/cli.py", line 236, in main
    setup = SimulationSetup(command_line_config=command_line_config)
  File "/home/b/b350071/esm/esm_tools/src/esm_runscripts/sim_objects.py", line 113, in __init__
    self.config = prepare.run_job(self.config)
  File "/home/b/b350071/esm/esm_tools/src/esm_runscripts/prepare.py", line 19, in run_job
    helpers.evaluate(config, "prepare", "prepare_recipe")
  File "/home/b/b350071/esm/esm_tools/src/esm_runscripts/helpers.py", line 75, in evaluate
    config = esm_plugin_manager.work_through_recipe(
  File "/home/b/b350071/esm/esm_tools/src/esm_plugin_manager/esm_plugin_manager.py", line 159, in work_through_recipe
    config = getattr(submodule, workitem)(config)
  File "/home/b/b350071/esm/esm_tools/src/esm_runscripts/prepare.py", line 124, in _initialize_calendar
    config = set_restart_chunk(config)
  File "/home/b/b350071/esm/esm_tools/src/esm_runscripts/prepare.py", line 149, in set_restart_chunk
    nmonth = int(config["general"].get("nmonth", nmonth))
ValueError: invalid literal for int() with base 10: '${runlength}'

which, at least to me, indicates the variables are not resolved yet, when set_restart_chunk is called. If I set month: 1 in the above example, things work as expected.
Expected behavior
I would expect that ${runlength} is resolved

System (please complete the following information):

  • Supercomputer: levante
  • Version: 6.61.0

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions