esm-tools / esm_tools

Simple Infrastructure for Earth System Simulations
https://esm-tools.github.io/
GNU General Public License v2.0
25 stars 12 forks source link

maximum recursion depth exceeded while calling a Python object #1184

Open JanStreffing opened 1 month ago

JanStreffing commented 1 month ago

I added a new model version, something I have done quite a few times before. I must have made a silly mistake, but I can't seem to spot it.

Here is the work I have done so far: https://github.com/esm-tools/esm_tools/pull/1183/files

The error I get is:

 esm_master install-awicm3-v3.2.2
Traceback (most recent call last):
  File "/home/a/a270092/.local/bin/esm_master", line 33, in <module>
    sys.exit(load_entry_point('esm-tools', 'console_scripts', 'esm_master')())
  File "/home/a/a270092/esm_tools/src/esm_master/cli.py", line 103, in main
    main_flow(parsed_args, target)
  File "/home/a/a270092/esm_tools/src/esm_master/esm_master.py", line 55, in main_flow
    complete_setup = SimulationSetup(user_config=user_config)
  File "/home/a/a270092/esm_tools/src/esm_runscripts/sim_objects.py", line 105, in __init__
    self.config = prepare.run_job(self.config)
  File "/home/a/a270092/esm_tools/src/esm_runscripts/prepare.py", line 19, in run_job
    helpers.evaluate(config, "prepare", "prepare_recipe")
  File "/home/a/a270092/esm_tools/src/esm_runscripts/helpers.py", line 71, in evaluate
    config = esm_plugin_manager.work_through_recipe(
  File "/home/a/a270092/esm_tools/src/esm_plugin_manager/esm_plugin_manager.py", line 159, in work_through_recipe
    config = getattr(submodule, workitem)(config)
  File "/home/a/a270092/esm_tools/src/esm_runscripts/prepare.py", line 791, in finalize_config
    config.finalize()
  File "/home/a/a270092/esm_tools/src/esm_parser/esm_parser.py", line 3163, in finalize
    self.run_recursive_functions(self)
  File "/home/a/a270092/esm_tools/src/esm_parser/esm_parser.py", line 3170, in run_recursive_functions
    recursive_run_function(
  File "/home/a/a270092/esm_tools/src/esm_parser/esm_parser.py", line 1906, in recursive_run_function
    right[key] = recursive_run_function(
  File "/home/a/a270092/esm_tools/src/esm_parser/esm_parser.py", line 1906, in recursive_run_function
    right[key] = recursive_run_function(
  File "/home/a/a270092/esm_tools/src/esm_parser/esm_parser.py", line 1873, in recursive_run_function
    right = func(tree + [None], right, *args, **kwargs)
  File "/home/a/a270092/esm_tools/src/esm_parser/esm_parser.py", line 1979, in find_variable
    var_result = find_variable(
  File "/home/a/a270092/esm_tools/src/esm_parser/esm_parser.py", line 1979, in find_variable
    var_result = find_variable(
  File "/home/a/a270092/esm_tools/src/esm_parser/esm_parser.py", line 1979, in find_variable
    var_result = find_variable(
  [Previous line repeated 976 more times]
  File "/home/a/a270092/esm_tools/src/esm_parser/esm_parser.py", line 1975, in find_variable
    var_result, var_attrs = actually_find_variable(tree, var, full_config)
  File "/home/a/a270092/esm_tools/src/esm_parser/esm_parser.py", line 2050, in actually_find_variable
    var_result = recursive_get(full_config, config_elements)
  File "/home/a/a270092/esm_tools/src/esm_parser/esm_parser.py", line 1951, in recursive_get
    return recursive_get(result, my_config_elements)
  File "/home/a/a270092/esm_tools/src/esm_parser/esm_parser.py", line 1938, in recursive_get
    my_config_elements = copy.deepcopy(config_elements)
  File "/sw/spack-levante/mambaforge-4.11.0-0-Linux-x86_64-sobz6z/lib/python3.9/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/sw/spack-levante/mambaforge-4.11.0-0-Linux-x86_64-sobz6z/lib/python3.9/copy.py", line 205, in _deepcopy_list
    append(deepcopy(a, memo))
  File "/sw/spack-levante/mambaforge-4.11.0-0-Linux-x86_64-sobz6z/lib/python3.9/copy.py", line 137, in deepcopy
    d = id(x)
RecursionError: maximum recursion depth exceeded while calling a Python object
chrisdane commented 1 month ago

Doesn't the coupling file need indents?

JanStreffing commented 1 month ago

I don't think so. This one for awicm3-v3.2.1 works:

https://github.com/esm-tools/esm_tools/blob/release/configs/couplings/fesom-2.5-awicm-3.2%2Boifs-43r3-awicm-3.2.1%2Bxios-2.5-yac%2Boasis3mct6/fesom-2.5-awicm-3.2%2Boifs-43r3-awicm-3.2.1%2Bxios-2.5-yac%2Boasis3mct6.yaml

JanStreffing commented 1 month ago

@pgierz and I looked into this.

The problem is, that when one makes a component model version, like so

choose_version:
  "2.5":
    branch: "2.5"

  "2.5-paleodyn":
    branch: "2.5.1_paleo"
    destination: "fesom-2.5"
    git-repository:
    - https://github.com/FESOM/fesom2.git # LA: only temporarily
    wiso_code: true
    icb_code: true
    namelist_dir: "${model_dir}/config/"

  '2.5-awicm-3.2':
    branch: "AWI-CM3_v3.2"

everything before the - is used to find the name of the fesom-${version}.yaml file name. If one does not use a -, the whole name is used to find the yaml file name. If that yaml file name does not exist, esm_master falls back onto the default fesom.yaml. This does not contain a tidy recipe. Which causes the esm_parser called from the esm_plugin_manager to spew out the error above.

The workaround is the stick to the nameing convention that puts a - after the version that is used in the yaml filename. So no version 2.5.2, but 2.5-2 ;-)

JanStreffing commented 1 month ago

I suggest this issue should stay open until the behaviour is documented, and then closed. A fix does not look plausible without a major rewrite of esm_master.

mandresm commented 1 month ago

Even better than just documentation, a proper error on top of docs explaining what's going wrong.