---
# System prepended metadata

title: Finalize Higher Dimensional Fields
tags: [cycle 4]

---

# Finalize Higher Dimensional Fields

###### tags: `cycle 4`
shaped by: Tobias, Eddie

## Appetite

Half a cycle (6 weeks) for 1-2 dev

---

## Problem
We are learning about more use-cases for higher dimensional fields and their importance to efficiently written model code in a fully GSRM. These use-cases are not only limited to the physical parameterizations but can also significantly affect how we write tracer-stencils in the dynamic part of the model.

#### Part 1: Missing numpy backend
Higher dimensional fields are implemented end-to-end for the `gtc:gt_` as well as the `gtc:cuda` backends but are still missing in the numpy backend.


#### Part 2: Missing support in functions
This stems from the fact that we assign each input field to a function to a temporary 3D variable when inlining and lose the additional dimension. 
A simple example of this would be:
```python
@gtscript.function
def foo(input_field):
    return input_field[0, 0, 0][1]


@stencil(backend, rebuild=True)
def test_stencil(input_field: Field[type], output_field: Field[type], value: int):
    with computation(PARALLEL), interval(...):
        output_field[0, 0, 0][0] = foo(input_field)
```


## Solution
#### Part 1
We already showed that higher dimensional fields work in the numpy backend. So the main task of Part 1 is to transfer this technology to the GTC side of the toolchain. 

- With the code generation of the traditional toolchain in mind, update the numpy-ir and the numpy code generation

#### Part 2
Since a solution that generates higher dimensional temporary variables for the function call inlining would be required, there is a certain amount of overlap with the ["typed temporaries"](https://hackmd.io/qz976j3XTuWR6aLYCdXz4w) project. The general outline is the following:

- Introduce the option for higher dimensional initialization to temporaries 
    - This means to change the inlining pass to modify the dimensionality of temporaries used based on the at that time known arguments shape


## Goals

The goal of this project is that the functionality of higher dimensional storages should be fully covered in the `gtc:numpy` backend.
Additionally we want to be enable the usage of higher dimensional fields in functions in the `gtc:gt:cpu_*`, `gtc:gt:gpu`,  `gtc:gt:cuda` and `gtc:numpy` backends.



## Potential Rabbit Holes
- This should not become a generic handler for differently shaped temporaries
- If we go the route of strongly typing functions this might become a much more significant undertaking


## No-Goals
- We are not targeting the dace backend for now
- Allowing the user to specify / use differently shaped temporaries is not foreseen in this project
- Also resolving lower dimensional fields in function calls is not a priority of this project