Skip to content

Namelist Refactor: Utility functions for namelist to dict + conftest --no_legacy_namelist#246

Merged
jjuyeonkim merged 8 commits into
NOAA-GFDL:developfrom
jjuyeonkim:20251002_namelist_helper
Oct 7, 2025
Merged

Namelist Refactor: Utility functions for namelist to dict + conftest --no_legacy_namelist#246
jjuyeonkim merged 8 commits into
NOAA-GFDL:developfrom
jjuyeonkim:20251002_namelist_helper

Conversation

@jjuyeonkim
Copy link
Copy Markdown
Collaborator

@jjuyeonkim jjuyeonkim commented Oct 3, 2025

Description

Partial work addressing issue #64

Adding helper functions for loading f90nml.Namelist from file and converting to dict.

There is a slight complication with the translate tests. We need to be able to turn on and off the usage of ndsl.Namelists. So, I'm proposing a new temporary flag --no_legacy_namelist in conftest.py to toggle between two options in the tests:

  1. Use only f90nml.Namelist (Long-term desired goal) within the translate tests
  2. Continue using f90nml.Namelist and the soon-to-be legacy ndsl.Namelist (Interim solution to facilitate checking in changes one submodule at a time)

Also, I'm modifying ParallelTranslate's layout() to rely more on f90nml.Namelist or ndsl.Namelist temporarily as we work on this issue.

These changes will facilitate the eventual removal of ndsl.Namelist in PyFV3 and PySHiELD in subsequent PRs.

Fixes #64 (partially)

How has this been tested?

Existing unit tests still pass and translate tests pass as expected when compared to the develop branch.

(I have also a proposed set of changes in PyFV3 that use these modifications to get rid of ndsl.Namelist, where the tests all pass as expected. I can hopefully put together a PR relatively quickly if this PR's changes look good.)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules
  • New check tests, if applicable, are included

- Adding helper functions for loading f90nml.Namelist
  from file and converting to dict.
- Modifying conftest.py and ParallelTranslate layout()
  to rely more on f90nml.Namelist.
- Adding temporary 'f90nml_namelist_only' flag to
  conftest.py to toggle testing using
  1. only f90nml.Namelist, or
  2. f90nml.Namelist and ndsl.Namelist
(Changes will eventually facilitate removal of current
ndsl.Namelist class)
@jjuyeonkim jjuyeonkim marked this pull request as ready for review October 3, 2025 13:36
Copy link
Copy Markdown
Collaborator

@FlorianDeconinck FlorianDeconinck left a comment

Choose a reason for hiding this comment

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

Looking good - I'll have a deeper look later, for now some small comments on tracking temporary changes

Comment thread ndsl/stencils/testing/conftest.py Outdated
Comment thread ndsl/stencils/testing/conftest.py Outdated
Comment thread ndsl/stencils/testing/conftest.py Outdated
Comment thread ndsl/utils.py
Comment thread ndsl/utils.py Outdated
@jjuyeonkim jjuyeonkim requested a review from fmalatino October 3, 2025 17:10
Copy link
Copy Markdown
Collaborator

@FlorianDeconinck FlorianDeconinck left a comment

Choose a reason for hiding this comment

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

Parts of me would like to hide f90nml behind a "universal" configuration loader. But this is a good first step in any case.

Thanks for the pathlib cleanup.

@jjuyeonkim
Copy link
Copy Markdown
Collaborator Author

jjuyeonkim commented Oct 6, 2025

Parts of me would like to hide f90nml behind a "universal" configuration loader. But this is a good first step in any case.

I think I understand and agree with this sentiment regarding a more universal loader in the future (without the f90nml explicitly being there). I personally don't know exactly what that looks like yet, so I thought that getting rid of the ndsl Namelist and NamelistDefault would be a good place to help untangle things and get us closer.

For a future PR, having something like a 'load_config' that handles both yaml and namelist sounds like a good goal. Maybe pursuing that idea of mapping from f90nml to yaml at that point.

@jjuyeonkim jjuyeonkim added this pull request to the merge queue Oct 6, 2025
@FlorianDeconinck
Copy link
Copy Markdown
Collaborator

Parts of me would like to hide f90nml behind a "universal" configuration loader. But this is a good first step in any case.

I think I understand and agree with this sentiment regarding a more universal loader in the future (without the f90nml explicitly being there). I personally don't know exactly what that looks like yet, so I thought that getting rid of the ndsl Namelist and NamelistDefault would be a good place to help untangle things and get us closer.

For a future PR, having something like a 'load_config' that handles both yaml and namelist sounds like a good goal. Maybe pursuing that idea of mapping from f90nml to yaml at that point.

Arguably we should wait to encounter a third file schema we need to carry to generalize for good in order to not pre-engineer code. I am sure someone will come along with some RC file format from outer hell for us :D

Copy link
Copy Markdown
Collaborator

@romanc romanc left a comment

Choose a reason for hiding this comment

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

This looks like a good start to me. Something bigger is definitely bubbling up here, but let's take it step by step. I love the push towards pathlib, it's a nice addition to this cleanup.

I'd like to discuss / change the new pytest flag and avoid putting an explicit reference to f90nml in there. I think the format of the config file should really be an implementation detail. The proposed name --legacy_namelist_support is up for debate. I'm happy to hear different opinions.

Comment thread ndsl/stencils/testing/conftest.py
Comment on lines +252 to +253
namelist = load_f90nml(namelist_filename)
grid_params = grid_params_from_f90nml(namelist)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It seems to me like these "grid params" could be a type (instead of an un-typed, general dict). Maybe that's a good follow-up PR or just something to think about. Might be out of scope for this PR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this is full on config dataclass in a follow up PR. E.g. something like:

class CartesianGridParameters
    nx: int,
    ny: int,
    nz: int,
    
class CubeSphereGridParameters:
   layout: tuple[int, int]
   cartesian_dims: CartesianGridParameters

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sounds like a good follow-up. I'll put in a TODO. Also, if this PR gets approved, I'll create an issue to keep track.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Comment thread ndsl/stencils/testing/parallel_translate.py Outdated
Comment thread ndsl/utils.py Outdated
Comment thread ndsl/utils.py Outdated
Comment thread ndsl/utils.py Outdated
@romanc romanc removed this pull request from the merge queue due to a manual request Oct 6, 2025
@romanc
Copy link
Copy Markdown
Collaborator

romanc commented Oct 6, 2025

Sorry for being late and for pulling this out of the queue. I'd really like to talk about the name of the new pytest flag.

Copy link
Copy Markdown
Collaborator

@romanc romanc left a comment

Choose a reason for hiding this comment

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

Looking good now 🚀

@romanc romanc changed the title Namelist Refactor: Utility functions for namelist to dict + conftest --f90nml_namelist_only Namelist Refactor: Utility functions for namelist to dict + conftest --no_legacy_namelist Oct 7, 2025
@jjuyeonkim jjuyeonkim added this pull request to the merge queue Oct 7, 2025
Merged via the queue into NOAA-GFDL:develop with commit ebc4f96 Oct 7, 2025
5 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.

NDSL should provide a framweork for physics namelists instead of specifying the namlist members and default values for specific physics models

4 participants