Skip to content

Feat: add upper limit to nlayer to avoid run crashes#1206

Merged
sunt05 merged 4 commits intomasterfrom
dayantur/feat/validator/nlayer-upper-limit
Mar 9, 2026
Merged

Feat: add upper limit to nlayer to avoid run crashes#1206
sunt05 merged 4 commits intomasterfrom
dayantur/feat/validator/nlayer-upper-limit

Conversation

@dayantur
Copy link
Copy Markdown

At the moment, SPARTACUS has hardcoded dimension 15 for nlayer, and so that should be reflected in a upper limit in the nlayer input Pydantic class. This PR adds le to Field of nlayer in surface.py to prevent run crashes.

@dayantur dayantur self-assigned this Feb 13, 2026
@dayantur dayantur changed the title Feat: add upper limit to nlayer avoid crashes Feat: add upper limit to nlayer to avoid run crashes Feb 13, 2026
@dayantur dayantur changed the title Feat: add upper limit to nlayer to avoid run crashes Feat: add upper limit to nlayer to avoid run crashes Feb 13, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 13, 2026

CI Build Plan

Changed Files

Python source (2 files)

  • src/supy/data_model/core/surface.py
  • src/supy/data_model/validation/pipeline/phase_a.py

Documentation (2 files)

  • src/supy/data_model/core/surface.py
  • src/supy/data_model/validation/pipeline/phase_a.py

Build Configuration

Configuration
Platforms Linux x86_64
Python 3.9, 3.14
Test tier standard (all except slow)
UMEP build Skipped (no ABI changes)
PR status Ready (standard matrix)

Rationale

  • Python source changed -> single-platform build
  • No compiled extension changes -> UMEP build skipped (nightly provides coverage)

Updated by CI on each push. See path-filters.yml for category definitions.

@github-actions
Copy link
Copy Markdown

Preview Deployed

Content Preview URL
Site https://suews.io/preview/pr-1206/
Docs https://suews.io/preview/pr-1206/docs/

Note

This preview is ephemeral. It will be lost when:

  • Another PR with site/ or docs/ changes is pushed
  • Changes are merged to master
  • A manual workflow dispatch runs

To restore, push any commit to this PR.

@dayantur dayantur marked this pull request as ready for review February 13, 2026 11:21
@dayantur
Copy link
Copy Markdown
Author

hi @sunt05 - I discovered this last week while discussing with other users that are doing dev and runs with SPARTACUS. I checked again this week while working on SPARTACUS veg and we actually have a limit in fortran code at 15 - so I added that to Pydantic. Minimal change but still let me know if this sounds good to you! I will add the CHANGELOG after approval.

@dayantur dayantur requested a review from sunt05 February 13, 2026 11:21
@suegrimmond
Copy link
Copy Markdown

This should tell the user they will need to change the Fortran if > 15.

Copy link
Copy Markdown

@sunt05 sunt05 left a comment

Choose a reason for hiding this comment

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

Thanks for this @dayantur — one small addition needed, see inline comment.

Comment thread src/supy/data_model/core/surface.py
Co-authored-by: Ting Sun <ting.sun@ucl.ac.uk>
@dayantur
Copy link
Copy Markdown
Author

hi @sunt05 @suegrimmond

  • I've added the ge=1 to the Pydantic Field
  • I've added a guard in phase_a.py that warns user if entered nlayer>15

let me know if we are happy with the changes!

@dayantur dayantur requested a review from sunt05 February 14, 2026 00:20
value_display = f" (value={nlayer_value})" if nlayer_value is not None else ""
report_lines.append(f"-- {path}{value_display}: {message}")
report_lines.append(
"Note: If you need nlayer>15 for your run, consider to change SPARTACUS Fortran code and Pydantic nlayer Field constraints to allow more layers."
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We should probably frame this as a constraint rather than expecting the user to change the Fortran code, which doesn’t seem reasonable at this point, right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I agree. But shall we leave this as a NO ACTION NEEDED warning or enforce a proper stop/ACTION NEEDED?

I would suggest the first one, warning the user that the model will not run otherwise (as we also have an hard stop with the guard in Pydantic)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sounds good. Also please rephrase the warning message.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We should probably frame this as a constraint rather than expecting the user to change the Fortran code, which doesn’t seem reasonable at this point, right?

  • 15 stops the model - but if needed - as we have for some key tests - this can be adjusted in the FORTRAN - so we are not asking the user to do it - but is scientifically possible

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@sunt05 @suegrimmond what about something like:
nlayer={nlayer} exceeds the supported range [1, 15]. SUEWS will not run with this setting. Reduce nlayer to 15 or fewer layers; higher values are possible but need changes in the code.

Not sure if this phrasing would work. Otherwise, we can discuss this on Tue meeting :)

sunt05
sunt05 previously approved these changes Feb 14, 2026
Copy link
Copy Markdown

@sunt05 sunt05 left a comment

Choose a reason for hiding this comment

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

Thanks, @dayantur. Just one minor comment on wording; otherwise, it looks good to me.

@sunt05
Copy link
Copy Markdown

sunt05 commented Mar 9, 2026

Thanks @dayantur for this - I've updated the warning message to be clearer - merging this now.

@sunt05 sunt05 enabled auto-merge March 9, 2026 10:14
@sunt05 sunt05 added this pull request to the merge queue Mar 9, 2026
Merged via the queue into master with commit b38a70d Mar 9, 2026
13 checks passed
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.

3 participants