Skip to content

Fix mypy warnings for DiffusionConfig#1086

Merged
msimberg merged 2 commits intoC2SM:mainfrom
msimberg:fix-diffusion-config-typing
Mar 2, 2026
Merged

Fix mypy warnings for DiffusionConfig#1086
msimberg merged 2 commits intoC2SM:mainfrom
msimberg:fix-diffusion-config-typing

Conversation

@msimberg
Copy link
Contributor

@msimberg msimberg commented Mar 2, 2026

#1079 introduced stricter type checks for DiffusionConfig parameters. Two parameters were still being passed as plain ints which mypy complained about.

I've also renamed HETEROGENOUS to HETEROGENEOUS (added an E) for consistency with HOMOGENEOUS. Also see https://en.wikipedia.org/wiki/Homogeneity_and_heterogeneity#Etymology_and_spelling.

@msimberg
Copy link
Contributor Author

msimberg commented Mar 2, 2026

cscs-ci run default

@msimberg
Copy link
Contributor Author

msimberg commented Mar 2, 2026

cscs-ci run distributed

@github-actions
Copy link

github-actions bot commented Mar 2, 2026

Mandatory Tests

Please make sure you run these tests via comment before you merge!

  • cscs-ci run default
  • cscs-ci run distributed

Optional Tests

To run benchmarks you can use:

  • cscs-ci run benchmark-bencher

To run tests and benchmarks with the DaCe backend you can use:

  • cscs-ci run dace

To run test levels ignored by the default test suite (mostly simple datatest for static fields computations) you can use:

  • cscs-ci run extra

For more detailed information please look at CI in the EXCLAIM universe.

@msimberg msimberg requested a review from OngChia March 2, 2026 15:21
Comment on lines 128 to 146
ValidDiffusionType = Literal[
DiffusionType.NO_DIFFUSION,
DiffusionType.LINEAR_2ND_ORDER,
DiffusionType.SMAGORINSKY_NO_BACKGROUND,
DiffusionType.LINEAR_4TH_ORDER,
DiffusionType.SMAGORINSKY_4TH_ORDER,
]
ValidSmagorinskyStencilType = Literal[
SmagorinskyStencilType.DIAMOND_VERTICES, SmagorinskyStencilType.CELLS_AND_VERTICES
]
ValidTemperatureDiscretizationType = Literal[
TemperatureDiscretizationType.HOMOGENEOUS, TemperatureDiscretizationType.HETEROGENOUS
TemperatureDiscretizationType.HOMOGENEOUS, TemperatureDiscretizationType.HETEROGENEOUS
]
ValidTurbulenceShearForcingType = Literal[
TurbulenceShearForcingType.VERTICAL_OF_HORIZONTAL_WIND,
TurbulenceShearForcingType.VERTICAL_HORIZONTAL_OF_HORIZONTAL_WIND,
TurbulenceShearForcingType.VERTICAL_HORIZONTAL_OF_HORIZONTAL_VERTICAL_WIND,
TurbulenceShearForcingType.VERTICAL_HORIZONTAL_OF_HORIZONTAL_WIND_LTHESH,
]
Copy link
Contributor

Choose a reason for hiding this comment

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

A bit off-topic, but why are those aliases needed?? They seem to be just duplicating the content of the Enums defined above, aren't they? If they are actually needed, I would add the TypeAlias hint (e.g. ValidDiffusionType: TypeAlias = Literal[...])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That comes from #1086 so I think @OngChia is best able to answer that.

Copy link
Contributor

Choose a reason for hiding this comment

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

@OngChia can you explain why those Literal aliases are needed?

Copy link
Contributor

@OngChia OngChia Mar 3, 2026

Choose a reason for hiding this comment

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

Sorry, it is my mistake. I did not notice they are all Enum not FrozenNamespace[int]
I was having an issue with mypy in my another PR#1075. mypy complained about wrong type

liquid_autoconversion_option=mphys_options.LiquidAutoConversionType.SEIFERT_BEHENG,

So, I decided to use Literal[...] for the type hint...
Related question: I am still confused about why mypy complains if I use FrozenNamespace[int] instead of Enum and what is the correct usage of FrozenNamespace[int]

I have opened another small PR#1088 to remove these unnecessary Literal statements and fix further places where type_t_diffu and type_vn_diffu are stilled passed as int not TemperatureDiscretizationType and SmagorinskyStencilType. Why didn't the pre-commit git action catch them after I push my commit to my PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why didn't the pre-commit git action catch them after I push my commit to my PR?

I think this because we still exclude a lot of files from mypy checks...

@msimberg msimberg merged commit c43e09c into C2SM:main Mar 2, 2026
48 checks passed
@msimberg msimberg deleted the fix-diffusion-config-typing branch March 2, 2026 15:54
OngChia added a commit that referenced this pull request Mar 3, 2026
Remove Valid** type Literal declaration for the config parameters
`DiffusionType`, `SmagorinskyStencilType`,
`TemperatureDiscretizationType`, and `TurbulenceShearForcingType` in
DiffusionConfig after this
[PR#1079](#1079) was merged. They
are unnecessary because they are all Enum type (refer to comments in
this [PR#1086](#1086)).
Moreover, this PR fixes some additional places where `type_t_diffu`
(`TemperatureDiscretizationType`) and `type_vn_diffu`
(`SmagorinskyStencilType`) are still passed as int.
jcanton added a commit that referenced this pull request Mar 3, 2026
* main:
  Remove `vct_b` bindings only (#1082)
  Replace `pg_edgeidx_dsl` mask by multiplying with 0.0 (#1053)
  Replace `mask_hdiff` by multiplying with 0.0 (#1056)
  fix type hint in DiffusionConfig and remove Literal (#1088)
  muphys: graupel py2fgen bindings (#1073)
  Fix mypy warnings for DiffusionConfig (#1086)
  Add tracer advection to standalone driver [cycle 34] (#1039)
  Reject namelist parameters not supported (#1079)
  Update to gt4py v1.1.6 (#1081)
  Merge bdy halo stencils (#1066)
  Enable gauss3d experiment for distributed tests (#1013)
  Reenable MPS in CI (#1057)
  Don't compute RBF coefficients over whole domain to avoid non-positive definite matrices (#1077)
  muphys: Only write the surface level of the fluxes (#995)
  Update to gt4py v1.1.5 (#1072)
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.

4 participants