Skip to content

Scalar values from factory#871

Merged
halungge merged 25 commits intomainfrom
scalar_values_from_factory
Sep 19, 2025
Merged

Scalar values from factory#871
halungge merged 25 commits intomainfrom
scalar_values_from_factory

Conversation

@halungge
Copy link
Copy Markdown
Contributor

@halungge halungge commented Sep 12, 2025

Adds the ability to produce scalar values from the factories.
We need this in the metrics factory for the computation of nflat_gradp for the dynamical core and will need it as well for the computation of some mean properties for the grid (mean_cell_area...) as discussed in PR-848

(Additional fixes): fixes a lot of typing issues in all three factory implementations.

Magdalena Luz added 8 commits September 12, 2025 09:45
# Conflicts:
#	model/common/src/icon4py/model/common/states/factory.py
#	model/common/src/icon4py/model/common/states/utils.py
#	model/common/tests/common/metrics/unit_tests/test_metrics_factory.py
@halungge halungge force-pushed the scalar_values_from_factory branch from 5408509 to 1066793 Compare September 12, 2025 11:51
@yiluchen1066 yiluchen1066 marked this pull request as ready for review September 16, 2025 12:07
@halungge halungge requested a review from msimberg September 18, 2025 08:12
@yiluchen1066
Copy link
Copy Markdown
Contributor

cscs-ci run default

Copy link
Copy Markdown
Contributor

@msimberg msimberg left a comment

Choose a reason for hiding this comment

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

Mostly questions/minor cleanup comments from my side. I think you'll unfortunately need to fix my RBF computations (the return types).

def _as_field(
self, backend: gtx_typing.Backend | None, value: data_alloc.NDArray
) -> state_utils.GTXFieldType:
return gtx.as_field(tuple(self._dims), value, allocator=backend)
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.

Are the RBF tests failing perhaps because I made them (at least the cell and vertex; edge is only one field) return lists instead of tuples (as the type hints would indicate)...? Or should lists of fields as return values be allowed? NB. I'm not asking for it to be allowed, I think restricting it to tuples and single arrays is sufficient.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

maybe. I dont know whether it matters at runtime. I never thougth about because we return tuples in gt4py and if you just do a

def foo():
    ...
    return a, b, c

that will be a tuple.

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.

BTW, I'm referring to

rbf_vec_coeff = [array_ns.asarray(x) for x in rbf_vec_coeff_np]
which should probably have () instead of [].

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did a tuple([...]). The (...) will return a generator expression, not a tuple...

Magdalena Luz added 2 commits September 19, 2025 11:22
# Conflicts:
#	model/common/src/icon4py/model/common/metrics/metrics_factory.py
Copy link
Copy Markdown
Contributor

@msimberg msimberg left a comment

Choose a reason for hiding this comment

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

Looks good to me modulo the RBF test failure.

@halungge
Copy link
Copy Markdown
Contributor Author

cscs-ci run default

@halungge
Copy link
Copy Markdown
Contributor Author

cscs-ci run default

@github-actions
Copy link
Copy Markdown

Mandatory Tests

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

  • cscs-ci run default

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.

@halungge
Copy link
Copy Markdown
Contributor Author

cscs-ci run default

@halungge halungge merged commit 5f922e4 into main Sep 19, 2025
47 checks passed
msimberg added a commit that referenced this pull request Oct 10, 2025
#871 made a partial fix, but the
types still ended up slightly inconsistent. The generic
`_compute_rbf_interpolation_coeffs` returns a dynamically sized list of
ndarrays, as it depends on a dynamically sized list as input. The return
type was incorrectly specified as a two-element tuple (it can be one or
two elements long). #871 correctly made sure the cell/vertex-specific
functions return a tuple, but with `_compute_rbf_interpolation_coeffs`
returning a list, the return values should be explicitly converted in
those functions instead. This PR changes all uses of lists to tuples
instead.
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