---
# System prepended metadata

title: Field Offsets aka dusk `IndexField`
tags: [functional cycle 13]

---

# Field Offsets aka dusk `IndexField`

###### tags: `functional cycle 13`

shaped by: Hannes

## Goals

Three stencils of the ICON dycore are not ported to the field view frontend. The missing feature is to allow dynamic offset, with different offset on each gridpoint. The iterator IR and the C++ backend already support this in the following form.

```python
@fundef
def foo(field, offset_field):
    return deref(shift(DimTag, deref(offset_field))(field))
```

The down-side of such a formulation is that arbitrary large offsets would be allowed, limiting optimization opportunities. Therefore, we propose this feature as an experimental feature, to highlight that this might change or might imply optimization limitations.

## Solution

The frontend (parser, type deduction, lowering) needs, to be extended to support fields as offsets.

We propose the following experimental syntax. 
Solution for now: create a new builtin called `as_offset(dimension over which to offset, field of offsets)`. 
Put builtin in experimental module. If module is too difficult to make it, then re-discuss.

```python
@field_operator
def foo(field: Field[[Dim0, Dim1], float], offset_field: Field[[Dim1], int]):
    return field(experimental.as_offset(DimOff,offset_field))
```

This proposal is experimental for 2 reasons:
- The above mentioned performance limitation. Maybe an extension to support a max offset could be introduced, which would allow unrolling.
- We could evolve the language to support typed dimension indices, then the above example could look like

```python
@field_operator
def foo(field: Field[[Dim0, Dim1], float], offset_field: Field[[Dim1], Dim0]):
    return field(offset_field)
```

## Port the ICON stencils which use this feature

Port and integrate the 3 ICON dycore stencils.

## Rabbit holes

- Since the implementation of the ICON stencils with this pattern in iterator does not validate yet, there might be problems on the backend side. This is not part of this project.