# [GT4Py] GTIR: avoid accidental promotion of 1D to 2D fields. ###### tags: `cycle 25 - 09/24` <!-- Change to the current cycle number --> - Shaped by: @tehrengruber - Appetite (FTEs, weeks): - Developers: <!-- Filled in at the betting table unless someone is specifically required here --> ## Problem ```python output_domain = unstructured_domain({Vertex: (0, num_vertices), K: (0, num_levels)}) v_field = as_fieldop(lambda it: 2*deref(it))(inp_v_field) set_at( expr=as_fieldop(lambda it1, it2: deref(it1) + deref(it2))( v_field, inp_vk_field ), domain=output_domain, target=output_vk_field ) ``` The domain inference will transform this into ```python v_field = as_fieldop(lambda it: 2*deref(it), output_domain)(inp_v_field) set_at( expr=as_fieldop(lambda it1, it2: deref(it1) + deref(it2), output_domain)( v_field, inp_vk_field ), domain=output_domain, target=output_vk_field ) ``` which means `v_field` is unnecessarily computed on the entire `Vertex, K` domain, while it only needs to be defined on `Vertex`. <!-- The raw idea, a use case, or something we’ve seen that motivates us to work on this --> ## Appetite <!-- Explain how much time we want to spend and how that constrains the solution --> ## Solution - Change the lowering to specify for each `as_fieldop` the dimensions the field is defined on. This would as a side-effect also fix the issue that the type inference requires the domain inference pass to run before. Maybe something like this: - `as_fieldop(stencil, auto_domain(Vertex))(fields...)` - or this `as_fieldop(stencil, unstructured_domain(Vertex: (-Inf, Inf))(fields...)` - Adopt the domain inference to only propagate the subset of the domain that is "required" <!-- The core elements we came up with, presented in a form that’s easy for people to immediately understand --> ## Rabbit holes <!-- Details about the solution worth calling out to avoid problems --> ## No-gos <!-- Anything specifically excluded from the concept: functionality or use cases we intentionally aren’t covering to fit the ## appetite or make the problem tractable -->