Skip to content

Fix UnboundLocalError in explicit-cycledef path (parse COLDSTART_CYCS) - #1699

Open
ywangwof wants to merge 1 commit into
NOAA-EMC:rrfs-mpas-jedifrom
ywangwof:fix/explicit-cycledef-coldstart-cycs
Open

Fix UnboundLocalError in explicit-cycledef path (parse COLDSTART_CYCS)#1699
ywangwof wants to merge 1 commit into
NOAA-EMC:rrfs-mpas-jedifrom
ywangwof:fix/explicit-cycledef-coldstart-cycs

Conversation

@ywangwof

@ywangwof ywangwof commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes an UnboundLocalError that makes the explicit-cycledef path unusable for DA experiments.

When a user sets CYCLEDEF_* variables explicitly in the experiment file, smart_cycledefs() takes the explicit-override branch and never parses COLDSTART_CYCS into cold_cycs. The later da_nocold block — built whenever DO_JEDI=true (or DO_NONVAR_CLOUD_ANA=true) and COLDSTART_CYCS_DO_DA=false — references cold_cycs and raises:

UnboundLocalError: local variable 'cold_cycs' referenced before assignment
  File "workflow/rocoto_funcs/smart_cycledefs.py", line ~102, in smart_cycledefs
    exclude_cycs.extend(list(map(int, cold_cycs)))

That configuration (DA, skipping DA at the cold-start cycles) is common, so explicit cycledefs currently cannot be used with it.

Fix

Parse COLDSTART_CYCS in the explicit-override branch too, using the same default ('03 15') as the auto-compute branch, so da_nocold can exclude the cold-start cycles.

Impact

  • Experiments using the auto-compute path (no CYCLEDEF_* set) never enter the modified branch → all existing XML output is unchanged.
  • Experiments using explicit cycledefs with DA now generate correctly instead of crashing.

Reproducer / verification

Append to workflow/exp/exp.conus12km (which has DO_JEDI=true, COLDSTART_CYCS_DO_DA=false, COLDSTART_CYCS="00 12"):

export CYCLEDEF_IC="202405270000 202405270000 24:00:00"
export CYCLEDEF_LBC="202405270000 202405280000 12:00:00"
export CYCLEDEF_PROD="202405270000 202405270300 01:00:00"
  • Before: ./setup_rocoto.py aborts with the UnboundLocalError above.
  • After: generation succeeds and emits the expected da_nocold cycledef, e.g.:
<cycledef group="da_nocold" exclude_hours="0 12">202405270000 202405270300 01:00:00</cycledef>

py_compile clean.

When users set CYCLEDEF_* explicitly in the experiment file,
smart_cycledefs() takes the explicit-override branch and never parses
COLDSTART_CYCS into `cold_cycs`. The later `da_nocold` block (built when
DO_JEDI=true or DO_NONVAR_CLOUD_ANA=true, and COLDSTART_CYCS_DO_DA=false)
references `cold_cycs`, raising:

    UnboundLocalError: local variable 'cold_cycs' referenced before assignment

This makes explicit cycledefs unusable for DA experiments that skip DA at
the cold-start cycles (a common configuration).

Parse COLDSTART_CYCS in the explicit branch too, using the same default
('03 15') as the auto-compute branch, so `da_nocold` can exclude the
cold-start cycles. Experiments using the auto-compute path (no CYCLEDEF_*
set) are unaffected, so all existing XML output is unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
# cycles from DA. The auto-compute branch parses this too; the explicit
# branch must as well, otherwise cold_cycs is undefined whenever
# (DO_JEDI or DO_NONVAR_CLOUD_ANA) and COLDSTART_CYCS_DO_DA=false.
cold_cycs = os.getenv('COLDSTART_CYCS', '03 15').strip().split()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ywangwof Thanks for fixing this! 👍
WE can safely remove comment lines 18-21. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants