GridTools / gt4py

Python library for generating high-performance implementations of stencil kernels for weather and climate modeling from a domain-specific language (DSL).
https://GridTools.github.io/gt4py
BSD 3-Clause "New" or "Revised" License
112 stars 49 forks source link

next: how to do domain inference for dynamic shift #1676

Open havogt opened 2 months ago

havogt commented 2 months ago
@field_operator
def foo(..., k_offset):
    return compute_k_field(...)(as_offset(Koff, k_offset))

lowers to

return as_fieldop(lambda k_offset, k_field: deref(shift(Koff, deref(k_offset))), out_domain)(k_offset, compute_k_field(...))

How can we compute the domain that is needed for compute_k_field?

a) take the out_domain: probably wrong in some cases (e.g. between k and khalf) b) take the domain of k_offset (this is the same as a), as the domain of k_offset is taken from out_domain c) user has to annotate the domain explicitly (either explicit (requires to pass in the domain bounds -> ugly) or relative to a domain or field; both introduce slicing-like syntax and requires clear concept definition) d) inline everything below for now and find a better way to express the pattern

Note: in icon4py all as_offsets are in the vertical

havogt commented 1 month ago

Does a) work in icon4py?

Probably broken in https://github.com/C2SM/icon4py/blob/1acfb78134f09d254457ea97ae81423da54c28bb/model/atmosphere/dycore/src/icon4py/model/atmosphere/dycore/compute_hydrostatic_correction_term.py#L38 where we compute a single output level, but access multiple levels with an as_offset shift.

tehrengruber commented 3 weeks ago

Sketch for domain inference: