Skip to content

Removing ndsl.Namelist from PyFV3#88

Merged
jjuyeonkim merged 26 commits into
NOAA-GFDL:developfrom
jjuyeonkim:20250925_namelist_helper
Oct 21, 2025
Merged

Removing ndsl.Namelist from PyFV3#88
jjuyeonkim merged 26 commits into
NOAA-GFDL:developfrom
jjuyeonkim:20250925_namelist_helper

Conversation

@jjuyeonkim
Copy link
Copy Markdown
Collaborator

@jjuyeonkim jjuyeonkim commented Oct 9, 2025

Description
This follows from NDSL PR #246 and is part of NDSL Issue # 64.

This PR attempts to remove ndsl.Namelist from PyFV3 by doing the following:

  • ModifiesDynamicalCoreConfig.from_f90nml() to use only f90nml.Namelist via NDSL helper functions
  • Removes DynamicalCoreConfig.from_namelist()
  • Modifies the translate tests to shed its reliance on ndsl.Namelist in favor the DynamicalCoreConfig
  • Adds --no_legacy_namelist to the github workflow translate.yaml

Partial work on NDSL Issue # 64

How Has This Been Tested?

  • Existing unit tests
  • One new simple unit test that checks out creating the DynamicalCoreConfig from a nml file with a "namelist_override"

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 - There is a related Pace PR that needs to be checked in first for the pace tests to pass: Temporary Dycore dacite Config + Dycore Config Type Check Tweak [see: PyFV3 PR #88] pace#152
  • New check tests, if applicable, are included
  • Targeted model if this changed was triggered by a model need/shortcoming

@jjuyeonkim jjuyeonkim marked this pull request as ready for review October 10, 2025 00:47
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.

Thanks, Janice. That looks like a step in the right direction to me. I agree that DynamicalCoreConfig.from_namelist() should go away. And I think it's smart to store the dycore config in test classes as self.config.

I'm curious to hear why you decided to have dycore_config_from_f90nml as a standalone function instead of updating DynamicalCoreConfig.from_f90nml(). It seems to me that what ever is done in dycore_config_from_f90nml() could just move into DynamicalCoreConfig.from_f90nml(), no? Maybe I'm missing something.

Removing utils/namelist.py
Using DynamicalCoreConfig.from_f90nml in translate tests
Tweaking override unit test
@jjuyeonkim
Copy link
Copy Markdown
Collaborator Author

jjuyeonkim commented Oct 10, 2025

I'm curious to hear why you decided to have dycore_config_from_f90nml as a standalone function instead of updating DynamicalCoreConfig.from_f90nml(). It seems to me that what ever is done in dycore_config_from_f90nml() could just move into DynamicalCoreConfig.from_f90nml(), no? Maybe I'm missing something.

You bring up a good point on keeping DynamicalCoreConfig.from_f90nml(). This was likely a misunderstanding on my part. I added it back.

There's also the fact that DynamicalCoreConfig.from_yaml() exists as well. So, keeping the from_f90nml() would just keep following that convention.

Comment thread tests/main/test_config_from_f90nml.py Outdated
return [main_file_path, override_file_path]


def test_config_from_f90nml_with_override():
Copy link
Copy Markdown
Collaborator Author

@jjuyeonkim jjuyeonkim Oct 10, 2025

Choose a reason for hiding this comment

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

This is a really simple test for trying out the override_namelist. I didn't see one that tested it out, so I didn't think it would hurt.

However:

  1. I don't know if it goes here or in the Pace unit tests. It's not currently being run during the CI because there's another test in the same directory that also isn't being run and may be outdated.
  2. I'm hoping I got the functionality of the test right -- that the namelist_override completely overrides the previous namelist?

If no one knows, I'll just remove the test.

Edit: Ultimately, i just removed the unit test for now.

@jjuyeonkim
Copy link
Copy Markdown
Collaborator Author

jjuyeonkim commented Oct 16, 2025

I changed a few things:

  • I added a member variable to the DynamicalCoreConfig to keep track of the namelist groups for a particular instance:
    target_nml_groups: Optional[Tuple[str, ...]] = DEFAULT_DYCORE_NML_GROUPS
    i don't know if it's overkill. I added it to keep track of the namelist groups of a particular instance. The handling of the namelist_override happens in the post init, so in theory it could be initialized from a yaml or from dict or anywhere like that.
  • I added a new from_dict function that's used through from_f90nml. I figured this would be useful in the pace driver eventually, when initializing the dycore config from the driver config. I added some additional parameters. There's a dacite config that I'm using to work with the tuples. Right now, I'm making it strict=False because we're basically just flattening namelists from certain groups, so there's a chance that additional parameters from those particular namelist groups will be passed on to the dycore config.
  • There's a current work-around in pace related to one of the unit tests as a result of my changes: Pace PR #152 . I believe the pace CI test that's failing now will pass with this work-around.

@jjuyeonkim jjuyeonkim requested a review from romanc October 16, 2025 19:33
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.

Thanks, Janice! I think we are moving the right direction. A couple of smaller things inline.

I think some tests will break because the don't automatically get self.config added. The class hierarchy for translate tests is a mess (and I'm not sure we get to clean it up anytime soon).

And while we're at it, I'd suggest to take TranslateDycoreFortranData2Py out of translate_fvdynamics.py because the class isn't used there. I'd suggest to put it in a separate file in the same folder and then adjust the path in the __init__.py such that imports like "from pyfv3.testing import TranslateDycoreFortranData2Py" don't need any change.

Comment thread tests/savepoint/translate/translate_fvsubgridz.py
Comment thread tests/savepoint/translate/translate_cubedtolatlon.py
Comment thread pyfv3/_config.py Outdated
def from_dict(
cls,
data: dict,
) -> "DynamicalCoreConfig":
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.

Suggested change
) -> "DynamicalCoreConfig":
) -> DynamicalCoreConfig:

You can add from __future__ import annotations at the top of the file and then you don't need to add quotes around types any more that the old type resolver couldn't resolve

Copy link
Copy Markdown
Collaborator Author

@jjuyeonkim jjuyeonkim Oct 17, 2025

Choose a reason for hiding this comment

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

I'll update this.

Edit -- NOTE: I made a slight tweak to Pace's tests/main/fv3core/test_config.py::test_types_match test to account for this change.

Comment thread pyfv3/_config.py Outdated
Comment thread pyfv3/_config.py Outdated
Comment thread pyfv3/_config.py
@jjuyeonkim
Copy link
Copy Markdown
Collaborator Author

Okay, I tried to move TranslateDycoreFortranData2Py into its own translate_data.py

@jjuyeonkim jjuyeonkim requested a review from romanc October 20, 2025 17:23
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.

Thanks, Janice. From my point of view, this is good to go 🚀

@jjuyeonkim jjuyeonkim added this pull request to the merge queue Oct 21, 2025
Merged via the queue into NOAA-GFDL:develop with commit 329f126 Oct 21, 2025
4 of 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.

2 participants