# Review: A new declarative front-end based on field operations ###### tags: `review` `frontend` --- ## Review: A new declarative front-end based on field operations First 1/2 of cycle: Unification of ideas Second 1/2 of cycle: Implementation --- ## Unification of ideas --- ### Starting point - well-defined IR representation (Iterator IR) - several ideas and strong opinions for the frontend language, unclear which one to pick - pure field view (NumPy-like with domain specific syntax) - mixed view (some operations in field view, some in local view) - local view (e.g. "beautified" iterator view or positional) ```python= def diff(inp): # -> float or Field return inp(I+1) - inp(I-1) ``` --- ### Conclusions **Input from stakeholders:** - Let's focus on non-Cartesian to simplify discussion. - We don't need the perfect language, but one that is good enough for the next ~2 years, for the first iteration of dycores for ICON and FVM. **Technical:** - We can construct field view from iterator view -> no need to choose between local or field view, we can have both. - Not very important if we choose iterator view or positional, because they are compatible, too -> let's do beautify iterator view, because we already defined the semantics. --- **Plain iterator view** ```python= def diff(inp: iterator) -> float: return minus(deref(shift(I,1)(inp)), deref(shift(I,-1)(inp))) ``` --- **"Beautified" iterator view** ```python= def diff(inp: iterator) -> float: return inp(I+1) - inp(I-1) ``` - syntax sugar for iterator view: - offset sugar: `I+1` instead of `I, 1` - call operator on iterators does `deref(shift(...))` - `stencil[...]` expands to `lift(stencil)` --- **Constructing field view** ```python= def diff(inp: iterator) -> iterator: return lift(lambda inp: minus(deref(lift(lambda inp: deref(shift(I,1)(inp)))(inp)), deref(lift(lambda inp: deref(shift(I,-1)(inp)))(inp))))(inp) ``` - lift every expression --- **Field view** ```python= def diff(inp: field) -> field: return inp(I+1) - inp(I-1) ``` - make "lift everything" implicit - rename iterator to field --- ## Field Operator Frontend Implementation --- ### What's there - [x] understanding of use cases and limitations - [x] passes to simplify python AST - [x] FOAST, an eve-based subset of python AST which is simple to lower to Iterator IR - [x] passes to lower from AST to FOAST to an Iterator IR stencil - [x] helpful syntax errors for things allowed in python but not in Field Operators - [x] carry location information and point out the relevant code like python syntax errors --- ### What's missing - [ ] type information in FOAST - [ ] automatic derefing and lifting passes for FOAST, based on type info - [ ] handling of externals (symbols used in field operators that come from outside its scope) - [ ] automatic program generation <style> .reveal { font-size: 28px; } </style>
{"metaMigratedAt":"2023-06-16T14:35:52.888Z","metaMigratedFrom":"Content","title":"Review: A new declarative front-end based on field operations","breaks":false,"contributors":"[{\"id\":\"638479c6-a3a0-40db-a53b-aad8e4f7d122\",\"add\":32,\"del\":21},{\"id\":\"2e14e3c1-7b97-4fab-87e0-339b7c3a6055\",\"add\":2497,\"del\":284},{\"id\":\"4149f35d-a24b-45f3-b380-9333420521a1\",\"add\":750,\"del\":27}]"}
    220 views
   Owned this note