Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat[next]: workshop material and docs field Dims type hint update #1489

Merged
merged 250 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
250 commits
Select commit Hold shift + click to select a range
35b7f7e
Install instructions for workshop
leuty Nov 15, 2022
8dceefb
empty markup file
leuty Nov 15, 2022
6535a71
extend install instructions
leuty Nov 15, 2022
837762c
Extend
leuty Nov 15, 2022
09569f5
first version of scan excercise
leuty Nov 15, 2022
6f30a18
Merge remote-tracking branch 'upstream/functional' into gt4py-workshop
havogt Nov 16, 2022
970e23d
Gitpod
havogt Nov 16, 2022
5d14ea8
gitpod additions
havogt Nov 16, 2022
a407f38
add some connectivities
havogt Nov 16, 2022
6e8ff87
add simplified neighbor access example
havogt Nov 16, 2022
fa21532
[workshop]: Finalize scan example (#1052)
leuty Nov 17, 2022
c917966
Added pointwise and reduction examples (#1054)
muellch Nov 17, 2022
3cbb65b
partial solution, will move later
havogt Nov 17, 2022
8102e83
Solution to Ex_4
leuty Nov 17, 2022
4f8b023
save state
havogt Nov 17, 2022
41f1352
finish example 3, moved solutions
havogt Nov 17, 2022
5a3f0e0
add mesh description
havogt Nov 17, 2022
a713f46
add a slide as intro
havogt Nov 17, 2022
930b826
Update example 1
muellch Nov 17, 2022
fbd1ea1
Update examples 1 and 2
muellch Nov 18, 2022
eed7ff4
minor cosmetics
havogt Nov 18, 2022
78fcc6d
add agenda and remove some connectivities
havogt Nov 18, 2022
77db27b
implement feedback from workship in Ex. 4
leuty Nov 18, 2022
040a2b5
fix typo
leuty Nov 21, 2022
c633c37
add a simple example for the scan oeprator
leuty Nov 21, 2022
7da7f64
Expand explanation for scan operator
leuty Dec 1, 2022
a3a27a9
end subroutine
leuty Dec 1, 2022
5e008e9
Remove _wp
leuty Dec 1, 2022
de94077
Provide local constants (feedback from Daniel Hupp)
leuty Dec 8, 2022
a6269f7
Add definitions and placeholders for basic embedded field view concepts
egparedes Jul 24, 2023
006093f
Fixes
egparedes Jul 24, 2023
c4f9443
make it pass tests
havogt Jul 24, 2023
bf649f0
save state
havogt Jul 25, 2023
c73c296
define DomainLike
havogt Jul 25, 2023
555e9f2
verify
havogt Jul 25, 2023
40a2d37
wip
havogt Jul 25, 2023
0afad47
refactor type translation
havogt Jul 25, 2023
0122863
small fixes
havogt Jul 26, 2023
80c9c12
finish refactoring builtins
havogt Jul 26, 2023
1475f17
cleanup
havogt Jul 26, 2023
5ab9a54
builtin tests
havogt Jul 26, 2023
5df8d9d
more tests
havogt Jul 26, 2023
1993f32
comments
havogt Jul 26, 2023
4f749ca
cleanup
havogt Jul 26, 2023
5555ad7
fix and ignore
havogt Jul 26, 2023
6042750
some more qa fixes
havogt Jul 26, 2023
87f0975
a few more mypy errors
havogt Jul 26, 2023
cc32ed2
typing
havogt Jul 27, 2023
0e4ba03
more cleanup, non-dispatch test
havogt Jul 27, 2023
007a8d7
remove debug print
havogt Jul 27, 2023
b6e91b6
reenable test
havogt Jul 27, 2023
b3fc186
more typing fixes
havogt Jul 27, 2023
aa4c94c
Suggestions and fixes
egparedes Jul 27, 2023
b8279ae
More fixes
egparedes Jul 27, 2023
c20b610
Missing changes from previous commit
egparedes Jul 27, 2023
cfcb927
Add docs to FieldABC
egparedes Jul 28, 2023
c1444f5
fix some more typing problems
havogt Jul 28, 2023
85b4eca
fix remaining typing problems, move back registry
havogt Jul 28, 2023
8ead6d2
more typing
havogt Jul 28, 2023
e414e18
fix test matrix
havogt Jul 31, 2023
0543b85
fix builtin params
havogt Jul 31, 2023
33bdc76
move ndarray_field to embedded
havogt Jul 31, 2023
59c1962
fix check
havogt Jul 31, 2023
dadfe18
cartesian connectivity wip
havogt Aug 2, 2023
81f4bae
Merge remote-tracking branch 'origin/main' into embedded-field-view-impl
havogt Aug 2, 2023
d45ba0c
slightly cleaner
havogt Aug 2, 2023
45b8151
minor
havogt Aug 2, 2023
34a1391
improve implementation, basic program test
havogt Aug 2, 2023
c6fc23e
Merge remote-tracking branch 'origin/main' into embedded-field-view-impl
havogt Aug 3, 2023
27aad55
Merge remote-tracking branch 'origin/embedded-field-view-impl' into c…
havogt Aug 3, 2023
0c8ee0f
improve typing
havogt Aug 3, 2023
a8a0324
Introduce Fieldview Domain (#1310)
samkellerhals Aug 8, 2023
d3a7e44
Apply suggestions from code review
havogt Aug 8, 2023
aab3436
fix test
havogt Aug 8, 2023
202fc3b
fix imports
havogt Aug 8, 2023
60b2534
fix import
havogt Aug 8, 2023
4fbf5f6
fix import
havogt Aug 8, 2023
8bc332a
Merge remote-tracking branch 'origin/main' into embedded-field-view-impl
havogt Aug 9, 2023
9038dd1
Merge remote-tracking branch 'upstream/embedded-field-view-impl' into…
havogt Aug 9, 2023
c63b927
fix bug in Domain broadcast
havogt Aug 9, 2023
483dc17
undo unrelated changes
havogt Aug 9, 2023
3868dd3
Merge remote-tracking branch 'upstream/embedded-field-view-impl' into…
havogt Aug 10, 2023
de0a534
Merge remote-tracking branch 'upstream/main' into cartesian_connectivity
havogt Aug 10, 2023
a5718ef
Merge remote-tracking branch 'upstream/main' into cartesian_connectivity
havogt Aug 22, 2023
dc06e52
Merge branch 'main' into gt4py-workshop
muellch Nov 10, 2023
9c674d4
Fixed imports
muellch Nov 10, 2023
32f3549
Update Workshop_solution.md
nfarabullini Nov 14, 2023
2e5bcad
Merge branch 'main' of https://github.com/gridtools/gt4py into gt4py-…
nfarabullini Nov 16, 2023
6be2db7
Merge branch 'main' into cartesian_connectivity
egparedes Nov 16, 2023
0b39199
Minor fixes after merge
egparedes Nov 16, 2023
bf378d0
Fix style
egparedes Nov 16, 2023
807359d
presentation slides
nfarabullini Nov 16, 2023
7ac1fe3
small edits
nfarabullini Nov 16, 2023
f8b7bc7
More fixes after the merge
egparedes Nov 16, 2023
3b16173
Fixes
egparedes Nov 16, 2023
f7c996b
Fix style
egparedes Nov 16, 2023
182b254
Fix tests
egparedes Nov 16, 2023
08ba6fe
Fix value_type leftovers
egparedes Nov 17, 2023
16a983c
Fix general inverse image (WIP remap and tests, partially broken even…
egparedes Nov 17, 2023
346f6f0
First working version of the general remap (cartesian still WIP)
egparedes Nov 17, 2023
713e26a
Merge remote-tracking branch 'origin/main' into gt4py-workshop
havogt Nov 17, 2023
1fce1d0
update gitpod file
havogt Nov 17, 2023
a65b58c
First working version of refactored cartesian remap
egparedes Nov 17, 2023
6e007d2
Merge branch 'main' into cartesian_connectivity
egparedes Nov 18, 2023
08802c9
Fix merge issues
egparedes Nov 18, 2023
7a6053f
Add higher level connectivity constructors
egparedes Nov 18, 2023
c79b1c1
add sketch of scan
havogt Nov 18, 2023
a68ab85
prototyping a bit more
havogt Nov 19, 2023
643cfb1
refactor
havogt Nov 20, 2023
7d3d57c
make indirect call work
havogt Nov 20, 2023
ffc75e7
remove levftover
havogt Nov 20, 2023
5b1c813
additions for presentation
nfarabullini Nov 20, 2023
4de1f7e
Merge branch 'gt4py-workshop' of https://github.com/gridtools/gt4py i…
nfarabullini Nov 20, 2023
875ffdf
Added logos and other minors
nfarabullini Nov 20, 2023
23bec64
Fixes for most of cartesian shift tests
egparedes Nov 20, 2023
58209f7
Format fixes
egparedes Nov 20, 2023
f141408
fix test cases
havogt Nov 20, 2023
28b2620
fix intersect_domains
havogt Nov 20, 2023
01dcf72
fix last test
havogt Nov 20, 2023
68dec86
cleanups and typing
havogt Nov 20, 2023
e46e0f6
First embedded unstructured shift test working
egparedes Nov 20, 2023
c899c2c
Merge remote-tracking branch 'havogt/cartesian_connectivity' into car…
egparedes Nov 20, 2023
417165d
Added differentiation exercises
muellch Nov 21, 2023
447d8c8
Fix test cases definitions
egparedes Nov 21, 2023
3b4b222
WIP adding neighbor sums
egparedes Nov 21, 2023
253e936
Updated imports and functions in exercises
nfarabullini Nov 21, 2023
257a6b7
add reduction builtins
havogt Nov 21, 2023
e946f15
Merge branch 'main' of https://github.com/gridtools/gt4py into gt4py-…
nfarabullini Nov 21, 2023
22c2592
restructuring and otehr edits
nfarabullini Nov 21, 2023
cb8d6f0
Additional restructuring
nfarabullini Nov 21, 2023
22ca726
some typing
havogt Nov 21, 2023
7dbcc36
more typing
havogt Nov 21, 2023
bf6299c
more typing
havogt Nov 21, 2023
5183ac6
more
havogt Nov 21, 2023
af9bcb6
even more typing
havogt Nov 21, 2023
334bed0
last type problem
havogt Nov 21, 2023
d0e03a6
Split and edits of slides and scan exercise
nfarabullini Nov 21, 2023
f7399dd
fix bug
havogt Nov 21, 2023
2583a4d
Merge remote-tracking branch 'upstream/main' into cartesian_connectivity
havogt Nov 21, 2023
920455d
Apply suggestions from code review
havogt Nov 21, 2023
31ba6be
format and typing
havogt Nov 21, 2023
1d20945
Changed backend, put common code in helpers.py
muellch Nov 21, 2023
bbfa0d9
Enhance Domain with review suggestions
egparedes Nov 21, 2023
f0abba2
Fixes to domain changes
egparedes Nov 21, 2023
581cece
tiny tests and comment cleanup
havogt Nov 21, 2023
ac802d7
Merge remote-tracking branch 'origin/cartesian_connectivity' into emb…
havogt Nov 21, 2023
c342ad4
Merge remote-tracking branch 'upstream/main' into embedded_field_scan
havogt Nov 21, 2023
f7beac9
update column_range to NamedRange
havogt Nov 21, 2023
6cad860
refactor with context vars
havogt Nov 21, 2023
87303be
address review comments
havogt Nov 21, 2023
f5f022e
refactor tuple assigns
havogt Nov 21, 2023
1d4b4e1
delete combine_pos
havogt Nov 21, 2023
31c5902
add docstring
havogt Nov 21, 2023
c1d6629
fix strange test
havogt Nov 22, 2023
fb7f6b5
isolate embedded from decorators module
havogt Nov 22, 2023
552d86f
Updated exercises with explanations/introductions
muellch Nov 22, 2023
df161b6
Fixed typo
muellch Nov 22, 2023
1afa4ac
Fix field operator annotation
muellch Nov 22, 2023
b90c318
Added helpers.py
muellch Nov 22, 2023
aabe340
Merge remote-tracking branch 'origin/main' into gt4py-workshop
havogt Nov 22, 2023
ca0cef0
Merge remote-tracking branch 'havogt/embedded_field_scan' into gt4py-…
havogt Nov 22, 2023
219e51d
Create solution and non-solution versions of exercises
muellch Nov 22, 2023
9c70c78
exercise 7
nfarabullini Nov 22, 2023
4c31a9d
Merge branch 'gt4py-workshop' of https://github.com/gridtools/gt4py i…
nfarabullini Nov 22, 2023
ee33f7a
Merge branch 'main' of https://github.com/gridtools/gt4py into gt4py-…
nfarabullini Nov 22, 2023
6903897
update to embedded
havogt Nov 22, 2023
1debf08
Merge branch 'gt4py-workshop' of https://github.com/GridTools/gt4py i…
havogt Nov 22, 2023
69a67ee
Merge branch 'gt4py-workshop' of https://github.com/gridtools/gt4py i…
nfarabullini Nov 22, 2023
0857f44
Edits to exercise 7
nfarabullini Nov 22, 2023
7f51972
Fix for exercise 7
nfarabullini Nov 22, 2023
ba3b646
Further edits to exercise 7
nfarabullini Nov 22, 2023
13f1c2c
Final edits to solutions 7
nfarabullini Nov 22, 2023
467ddab
re-added slides_3.md
nfarabullini Nov 22, 2023
32bd37a
update exercises
havogt Nov 22, 2023
24e78e7
only solution files
havogt Nov 22, 2023
0801536
use allocators
havogt Nov 22, 2023
a8d2165
ex 2 allocators
havogt Nov 22, 2023
579ae79
edge_orientation with random sign
havogt Nov 22, 2023
15c127b
update ex1 to remove all helpers
havogt Nov 22, 2023
b2d2a68
Edit to offset slide
nfarabullini Nov 22, 2023
43d539a
Merge branch 'gt4py-workshop' of https://github.com/gridtools/gt4py i…
nfarabullini Nov 22, 2023
7603c53
Edit to slide_2
nfarabullini Nov 22, 2023
d9f9d02
move backend around
havogt Nov 22, 2023
c6ca371
Merge branch 'gt4py-workshop' of https://github.com/GridTools/gt4py i…
havogt Nov 22, 2023
f5225e4
Edits to exercises
nfarabullini Nov 22, 2023
e2679dd
Edits to exercises
nfarabullini Nov 22, 2023
6e606fc
to ipynb
havogt Nov 22, 2023
4d772ee
updates to slides3
havogt Nov 22, 2023
3e7e48b
slide 4
havogt Nov 22, 2023
e625937
A few small edits for the slides
nfarabullini Nov 22, 2023
315e6b6
Add plots to exercise 1
egparedes Nov 22, 2023
88d4aef
Merge remote-tracking branch 'origin/gt4py-workshop' into gt4py-workshop
egparedes Nov 22, 2023
83fe852
removed ipynb files
nfarabullini Nov 22, 2023
b499735
Remove non-solution exercise 1
egparedes Nov 22, 2023
94d36c1
Merge remote-tracking branch 'origin/gt4py-workshop' into gt4py-workshop
egparedes Nov 22, 2023
af0056c
Add ripple_field helper
egparedes Nov 22, 2023
ec7c8cb
updates to slide 1
havogt Nov 22, 2023
74f7ac5
updates to slide2
havogt Nov 22, 2023
2590b68
slides 3+4
havogt Nov 22, 2023
8fe3585
a lost space
havogt Nov 22, 2023
aa3be56
prepare ex 6
havogt Nov 22, 2023
0eaf7a6
prep exercise 7
havogt Nov 22, 2023
ae6d736
remove _new from random_field
havogt Nov 22, 2023
7168da1
Update slides and fix quickstart guide to use images in the proper fo…
egparedes Nov 22, 2023
01a5232
Merge remote-tracking branch 'origin/gt4py-workshop' into gt4py-workshop
egparedes Nov 22, 2023
a1e69c6
Add image files
egparedes Nov 22, 2023
b4071b4
Update exercise 5, back to vector laplacian
muellch Nov 23, 2023
4082cc8
Fix bug in embedded error message
egparedes Nov 23, 2023
5424815
add link to accounts
havogt Nov 23, 2023
d65c129
Expand slide 2
egparedes Nov 23, 2023
cbf01bf
Merge remote-tracking branch 'origin/gt4py-workshop' into gt4py-workshop
egparedes Nov 23, 2023
2a8c90e
Add ipynb versions of the slides
egparedes Nov 23, 2023
626b1bd
exercise 1
havogt Nov 23, 2023
b04f05b
Merge branch 'gt4py-workshop' of https://github.com/GridTools/gt4py i…
havogt Nov 23, 2023
56e9d72
fix path to images folder
muellch Nov 23, 2023
f80182f
Create exercise 2, 3, 4
muellch Nov 23, 2023
9af9c01
Edits to exercise 5
nfarabullini Nov 23, 2023
ded994f
Add jupyter intro notebook
muellch Nov 23, 2023
7146f73
Delete images in base folder
muellch Nov 23, 2023
75d4db3
exercise 5 separate from solutions
nfarabullini Nov 23, 2023
915c720
merge with upstream
nfarabullini Mar 13, 2024
7999a93
ran pre-commit
nfarabullini Mar 13, 2024
1f46c2d
Merge branch 'main' of https://github.com/nfarabullini/gt4py into doc…
nfarabullini Mar 13, 2024
243f830
Edits to slides_1
nfarabullini Mar 13, 2024
601bb8e
Added Dims to exercises
nfarabullini Mar 13, 2024
cb8c344
Removed md files
nfarabullini Mar 13, 2024
478835a
.
nfarabullini Mar 13, 2024
81bb432
small fix from merge
nfarabullini Mar 13, 2024
7157d61
edits to slides
nfarabullini Mar 13, 2024
bca3ea4
Merge branch 'docs_type_update' of https://github.com/nfarabullini/gt…
nfarabullini Mar 13, 2024
55beabb
folder restruct
nfarabullini Mar 14, 2024
077179d
folder restruct
nfarabullini Mar 14, 2024
c8ebc6e
edits
nfarabullini Mar 14, 2024
aa21c02
edits
nfarabullini Mar 14, 2024
eb6c463
ran pre-commit
nfarabullini Mar 14, 2024
1a68d7f
as pointed out by Mikael Stellio
nfarabullini Mar 15, 2024
bdeaae5
Merge branch 'main' of https://github.com/nfarabullini/gt4py into doc…
nfarabullini Mar 26, 2024
56e8c9e
edits following review
nfarabullini Mar 26, 2024
7e4880b
edits to tox.ini
nfarabullini Mar 26, 2024
be5fd27
edits to tox.ini
nfarabullini Mar 26, 2024
e78c9c4
edits to tox.ini
nfarabullini Mar 26, 2024
d91020b
error on purpose
nfarabullini Mar 26, 2024
973c328
edits to tox
nfarabullini Mar 26, 2024
5f4c11f
edits to tox
nfarabullini Mar 26, 2024
41db4d8
edits
nfarabullini Mar 26, 2024
f5fca3c
Edits to exercise file
nfarabullini Mar 26, 2024
5e5b74b
Merge branch 'docs_type_update' of https://github.com/nfarabullini/gt…
nfarabullini Mar 26, 2024
873a6b4
edits and pre-commit
nfarabullini Mar 26, 2024
f2ca38c
edit to slide_2
nfarabullini Mar 26, 2024
6eb4a2e
edits to quickstart
nfarabullini Mar 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/user/next/.gitignore

This file was deleted.

104 changes: 53 additions & 51 deletions docs/user/next/QuickstartGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.14.0
jupytext_version: 1.16.1
kernelspec:
display_name: Python 3 (ipykernel)
language: python
Expand Down Expand Up @@ -70,19 +70,17 @@ b = gtx.as_field([CellDim, KDim], np.full(shape=grid_shape, fill_value=b_value,
Additional numpy-equivalent constructors are available, namely `ones`, `zeros`, `empty`, `full`. These require domain, dtype, and allocator (e.g. a backend) specifications.

```{code-cell} ipython3
from gt4py._core import definitions as core_defs
I = gtx.Dimension("I")
J = gtx.Dimension("J")

array_of_ones_numpy = np.ones((grid_shape[0], grid_shape[1]))
field_of_ones = gtx.constructors.ones(
field_of_ones = gtx.ones(
domain={I: range(grid_shape[0]), J: range(grid_shape[0])},
dtype=core_defs.dtype(np.float64),
dtype=np.float64,
allocator=gtx.program_processors.runners.roundtrip.backend
)
```

_Note: The interface to construct fields is provisional only and will change soon._

+++

#### Field operators

Field operators perform operations on a set of fields, for example, elementwise addition or reduction along a dimension. You can write field operators as Python functions by using the `@field_operator` decorator. Field operators cannot have side effects, therefore you cannot modify its arguments within their body. Only a subset of the Python syntax is allowed inside field operators—the library checks for correctness.
Expand All @@ -91,8 +89,8 @@ Let's see an example for a field operator that adds two fields elementwise:

```{code-cell} ipython3
@gtx.field_operator
def add(a: gtx.Field[gtx.Dims[CellDim, KDim], float64],
b: gtx.Field[gtx.Dims[CellDim, KDim], float64]) -> gtx.Field[gtx.Dims[CellDim, KDim], float64]:
def add(a: gtx.Field[Dims[CellDim, KDim], float64],
b: gtx.Field[Dims[CellDim, KDim], float64]) -> gtx.Field[Dims[CellDim, KDim], float64]:
return a + b
```

Expand All @@ -116,9 +114,9 @@ This example program below calls the above elementwise addition field operator t

```{code-cell} ipython3
@gtx.program
def run_add(a : gtx.Field[gtx.Dims[CellDim, KDim], float64],
b : gtx.Field[gtx.Dims[CellDim, KDim], float64],
result : gtx.Field[gtx.Dims[CellDim, KDim], float64]):
def run_add(a : gtx.Field[Dims[CellDim, KDim], float64],
b : gtx.Field[Dims[CellDim, KDim], float64],
result : gtx.Field[Dims[CellDim, KDim], float64]):
add(a, b, out=result)
add(b, result, out=result)
```
Expand Down Expand Up @@ -163,9 +161,9 @@ This section approaches the pseudo-laplacian by introducing the required APIs pr

The examples related to unstructured meshes use the mesh below. The edges (in blue) and the cells (in red) are numbered with zero-based indices.

| ![grid_topo](connectivity_numbered_grid.svg) |
| :------------------------------------------: |
| _The mesh with the indices_ |
| ![grid_topo](workshop/images/connectivity_numbered_grid.svg) |
| :----------------------------------------------------------: |
| _The mesh with the indices_ |

+++

Expand Down Expand Up @@ -217,9 +215,9 @@ cell_values = gtx.as_field([CellDim], np.array([1.0, 1.0, 2.0, 3.0, 5.0, 8.0]))
edge_values = gtx.as_field([EdgeDim], np.zeros((12,)))
```

| ![cell_values](connectivity_cell_field.svg) |
| :-----------------------------------------: |
| _Cell values_ |
| ![cell_values](workshop/images/connectivity_cell_field.svg) |
| :---------------------------------------------------------: |
| _Cell values_ |

+++

Expand Down Expand Up @@ -248,11 +246,11 @@ Pay attention to the syntax where the field offset `E2C` can be freely accessed

```{code-cell} ipython3
@gtx.field_operator
def nearest_cell_to_edge(cell_values: gtx.Field[gtx.Dims[CellDim], float64]) -> gtx.Field[gtx.Dims[EdgeDim], float64]:
def nearest_cell_to_edge(cell_values: gtx.Field[Dims[CellDim], float64]) -> gtx.Field[Dims[EdgeDim], float64]:
return cell_values(E2C[0])

@gtx.program
def run_nearest_cell_to_edge(cell_values: gtx.Field[gtx.Dims[CellDim], float64], out : gtx.Field[gtx.Dims[EdgeDim], float64]):
def run_nearest_cell_to_edge(cell_values: gtx.Field[Dims[CellDim], float64], out : gtx.Field[Dims[EdgeDim], float64]):
nearest_cell_to_edge(cell_values, out=out)

run_nearest_cell_to_edge(cell_values, edge_values, offset_provider={"E2C": E2C_offset_provider})
Expand All @@ -262,9 +260,9 @@ print("0th adjacent cell's value: {}".format(edge_values.asnumpy()))

Running the above snippet results in the following edge field:

| ![nearest_cell_values](connectivity_numbered_grid.svg) | $\mapsto$ | ![grid_topo](connectivity_edge_0th_cell.svg) |
| :----------------------------------------------------: | :-------: | :------------------------------------------: |
| _Domain (edges)_ | | _Edge values_ |
| ![nearest_cell_values](workshop/images/connectivity_numbered_grid.svg) | $\mapsto$ | ![grid_topo](workshop/images/connectivity_edge_0th_cell.svg) |
| :--------------------------------------------------------------------: | :-------: | :----------------------------------------------------------: |
| _Domain (edges)_ | | _Edge values_ |

+++

Expand All @@ -274,12 +272,12 @@ Similarly to the previous example, the output is once again a field on edges. Th

```{code-cell} ipython3
@gtx.field_operator
def sum_adjacent_cells(cells : gtx.Field[gtx.Dims[CellDim], float64]) -> gtx.Field[gtx.Dims[EdgeDim], float64]:
# type of cells(E2C) is gtx.Field[gtx.Dims[CellDim, E2CDim], float64]
def sum_adjacent_cells(cells : gtx.Field[Dims[CellDim], float64]) -> gtx.Field[Dims[EdgeDim], float64]:
# type of cells(E2C) is gtx.Field[Dims[EdgeDim, E2CDim], float64]
return neighbor_sum(cells(E2C), axis=E2CDim)

@gtx.program
def run_sum_adjacent_cells(cells : gtx.Field[gtx.Dims[CellDim], float64], out : gtx.Field[gtx.Dims[EdgeDim], float64]):
def run_sum_adjacent_cells(cells : gtx.Field[Dims[CellDim], float64], out : gtx.Field[Dims[EdgeDim], float64]):
sum_adjacent_cells(cells, out=out)

run_sum_adjacent_cells(cell_values, edge_values, offset_provider={"E2C": E2C_offset_provider})
Expand All @@ -289,9 +287,9 @@ print("sum of adjacent cells: {}".format(edge_values.asnumpy()))

For the border edges, the results are unchanged compared to the previous example, but the inner edges now contain the sum of the two adjacent cells:

| ![nearest_cell_values](connectivity_numbered_grid.svg) | $\mapsto$ | ![cell_values](connectivity_edge_cell_sum.svg) |
| :----------------------------------------------------: | :-------: | :--------------------------------------------: |
| _Domain (edges)_ | | _Edge values_ |
| ![nearest_cell_values](workshop/images/connectivity_numbered_grid.svg) | $\mapsto$ | ![cell_values](workshop/images/connectivity_edge_cell_sum.svg) |
| :--------------------------------------------------------------------: | :-------: | :------------------------------------------------------------: |
| _Domain (edges)_ | | _Edge values_ |

+++

Expand All @@ -303,7 +301,7 @@ This function takes 3 input arguments:
- mask: a field with dtype boolean
- true branch: a tuple, a field, or a scalar
- false branch: a tuple, a field, of a scalar
The mask can be directly a field of booleans (e.g. `gtx.Field[gtx.Dims[CellDim], bool]`) or an expression evaluating to this type (e.g. `gtx.Field[[CellDim], float64] > 3`).
The mask can be directly a field of booleans (e.g. `gtx.Field[Dims[CellDim], bool]`) or an expression evaluating to this type (e.g. `gtx.Field[[CellDim], float64] > 3`).
The `where` builtin loops over each entry of the mask and returns values corresponding to the same indexes of either the true or the false branch.
In the case where the true and false branches are either fields or scalars, the resulting output will be a field including all dimensions from all inputs. For example:

Expand All @@ -313,8 +311,8 @@ result_where = gtx.as_field([CellDim, KDim], np.zeros(shape=grid_shape))
b = 6.0

@gtx.field_operator
def conditional(mask: gtx.Field[gtx.Dims[CellDim, KDim], bool], a: gtx.Field[gtx.Dims[CellDim, KDim], float64], b: float
) -> gtx.Field[gtx.Dims[CellDim, KDim], float64]:
def conditional(mask: gtx.Field[Dims[CellDim, KDim], bool], a: gtx.Field[Dims[CellDim, KDim], float64], b: float
) -> gtx.Field[Dims[CellDim, KDim], float64]:
return where(mask, a, b)

conditional(mask, a, b, out=result_where, offset_provider={})
Expand All @@ -330,13 +328,13 @@ result_1 = gtx.as_field([CellDim, KDim], np.zeros(shape=grid_shape))
result_2 = gtx.as_field([CellDim, KDim], np.zeros(shape=grid_shape))

@gtx.field_operator
def _conditional_tuple(mask: gtx.Field[gtx.Dims[CellDim, KDim], bool], a: gtx.Field[gtx.Dims[CellDim, KDim], float64], b: float
) -> tuple[gtx.Field[gtx.Dims[CellDim, KDim], float64], gtx.Field[gtx.Dims[CellDim, KDim], float64]]:
def _conditional_tuple(mask: gtx.Field[Dims[CellDim, KDim], bool], a: gtx.Field[Dims[CellDim, KDim], float64], b: float
) -> tuple[gtx.Field[Dims[CellDim, KDim], float64], gtx.Field[Dims[CellDim, KDim], float64]]:
return where(mask, (a, b), (b, a))

@gtx.program
def conditional_tuple(mask: gtx.Field[gtx.Dims[CellDim, KDim], bool], a: gtx.Field[gtx.Dims[CellDim, KDim], float64], b: float,
result_1: gtx.Field[gtx.Dims[CellDim, KDim], float64], result_2: gtx.Field[gtx.Dims[CellDim, KDim], float64]
def conditional_tuple(mask: gtx.Field[Dims[CellDim, KDim], bool], a: gtx.Field[Dims[CellDim, KDim], float64], b: float,
result_1: gtx.Field[Dims[CellDim, KDim], float64], result_2: gtx.Field[Dims[CellDim, KDim], float64]
):
_conditional_tuple(mask, a, b, out=(result_1, result_2))

Expand All @@ -361,17 +359,17 @@ result_2 = gtx.as_field([CellDim, KDim], np.zeros(shape=grid_shape))

@gtx.field_operator
def _conditional_tuple_nested(
mask: gtx.Field[gtx.Dims[CellDim, KDim], bool], a: gtx.Field[gtx.Dims[CellDim, KDim], float64], b: gtx.Field[gtx.Dims[CellDim, KDim], float64], c: gtx.Field[gtx.Dims[CellDim, KDim], float64], d: gtx.Field[gtx.Dims[CellDim, KDim], float64]
mask: gtx.Field[Dims[CellDim, KDim], bool], a: gtx.Field[Dims[CellDim, KDim], float64], b: gtx.Field[Dims[CellDim, KDim], float64], c: gtx.Field[Dims[CellDim, KDim], float64], d: gtx.Field[Dims[CellDim, KDim], float64]
) -> tuple[
tuple[gtx.Field[gtx.Dims[CellDim, KDim], float64], gtx.Field[gtx.Dims[CellDim, KDim], float64]],
tuple[gtx.Field[gtx.Dims[CellDim, KDim], float64], gtx.Field[gtx.Dims[CellDim, KDim], float64]],
tuple[gtx.Field[Dims[CellDim, KDim], float64], gtx.Field[Dims[CellDim, KDim], float64]],
tuple[gtx.Field[Dims[CellDim, KDim], float64], gtx.Field[Dims[CellDim, KDim], float64]],
]:
return where(mask, ((a, b), (b, a)), ((c, d), (d, c)))

@gtx.program
def conditional_tuple_nested(
mask: gtx.Field[gtx.Dims[CellDim, KDim], bool], a: gtx.Field[gtx.Dims[CellDim, KDim], float64], b: gtx.Field[gtx.Dims[CellDim, KDim], float64], c: gtx.Field[gtx.Dims[CellDim, KDim], float64], d: gtx.Field[gtx.Dims[CellDim, KDim], float64],
result_1: gtx.Field[gtx.Dims[CellDim, KDim], float64], result_2: gtx.Field[gtx.Dims[CellDim, KDim], float64]
mask: gtx.Field[Dims[CellDim, KDim], bool], a: gtx.Field[Dims[CellDim, KDim], float64], b: gtx.Field[Dims[CellDim, KDim], float64], c: gtx.Field[Dims[CellDim, KDim], float64], d: gtx.Field[Dims[CellDim, KDim], float64],
result_1: gtx.Field[Dims[CellDim, KDim], float64], result_2: gtx.Field[Dims[CellDim, KDim], float64]
):
_conditional_tuple_nested(mask, a, b, c, d, out=((result_1, result_2), (result_2, result_1)))

Expand Down Expand Up @@ -426,19 +424,19 @@ The second lines first creates a temporary field using `edge_differences(C2E)`,

```{code-cell} ipython3
@gtx.field_operator
def pseudo_lap(cells : gtx.Field[gtx.Dims[CellDim], float64],
edge_weights : gtx.Field[gtx.Dims[CellDim, C2EDim], float64]) -> gtx.Field[gtx.Dims[CellDim], float64]:
edge_differences = cells(E2C[0]) - cells(E2C[1]) # type: gtx.Field[gtx.Dims[EdgeDim], float64]
return neighbor_sum(edge_differences(C2E) * edge_weights, axis=C2EDim)
def pseudo_lap(cells : gtx.Field[Dims[CellDim], float64],
edge_weights : gtx.Field[Dims[CellDim, C2EDim], float64]) -> gtx.Field[Dims[CellDim], float64]:
edges = cells(E2C[0]) # type: gtx.Field[Dims[EdgeDim], float64]
return neighbor_sum(edges(C2E) * edge_weights, axis=C2EDim)
```

The program itself is just a shallow wrapper over the `pseudo_lap` field operator. The significant part is how offset providers for both the edge-to-cell and cell-to-edge connectivities are supplied when the program is called:

```{code-cell} ipython3
@gtx.program
def run_pseudo_laplacian(cells : gtx.Field[gtx.Dims[CellDim], float64],
edge_weights : gtx.Field[gtx.Dims[CellDim, C2EDim], float64],
out : gtx.Field[gtx.Dims[CellDim], float64]):
def run_pseudo_laplacian(cells : gtx.Field[Dims[CellDim], float64],
edge_weights : gtx.Field[Dims[CellDim, C2EDim], float64],
out : gtx.Field[Dims[CellDim], float64]):
pseudo_lap(cells, edge_weights, out=out)

result_pseudo_lap = gtx.as_field([CellDim], np.zeros(shape=(6,)))
Expand All @@ -455,7 +453,11 @@ As a closure, here is an example of chaining field operators, which is very simp

```{code-cell} ipython3
@gtx.field_operator
def pseudo_laplap(cells : gtx.Field[gtx.Dims[CellDim], float64],
edge_weights : gtx.Field[gtx.Dims[CellDim, C2EDim], float64]) -> gtx.Field[gtx.Dims[CellDim], float64]:
def pseudo_laplap(cells : gtx.Field[Dims[CellDim], float64],
edge_weights : gtx.Field[Dims[CellDim, C2EDim], float64]) -> gtx.Field[Dims[CellDim], float64]:
return pseudo_lap(pseudo_lap(cells, edge_weights), edge_weights)
```

```{code-cell} ipython3

```
139 changes: 139 additions & 0 deletions docs/user/next/workshop/exercises/1_simple_addition.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "2ead8b70",
"metadata": {},
"source": [
"# 1. Simple Addition"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e7b501e0",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import gt4py.next as gtx"
]
},
{
"cell_type": "markdown",
"id": "06113a1f",
"metadata": {},
"source": [
"Next we implement the stencil and a numpy reference version, in order to verify them against each other."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4c9f3427",
"metadata": {},
"outputs": [],
"source": [
"I = gtx.Dimension(\"I\")\n",
"J = gtx.Dimension(\"J\")\n",
"size = 10"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8272b87c",
"metadata": {},
"outputs": [],
"source": [
"def addition_numpy(a: np.array, b: np.array) -> np.array:\n",
" c = a + b\n",
" return c"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "05f2d09d",
"metadata": {},
"outputs": [],
"source": [
"def addition ... # TODO fix this cell"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "db95ed00",
"metadata": {},
"outputs": [],
"source": [
"def test_addition(backend=None):\n",
" domain = gtx.domain({I: size, J: size})\n",
"\n",
" a_data = np.fromfunction(lambda xx, yy: xx, domain.shape, dtype=float)\n",
" a = gtx.as_field(domain, a_data, allocator=backend)\n",
" b_data = np.fromfunction(lambda xx, yy: yy, domain.shape, dtype=float)\n",
" b = gtx.as_field(domain, b_data, allocator=backend)\n",
"\n",
" c_numpy = addition_numpy(a.asnumpy(), b.asnumpy())\n",
"\n",
" c = gtx.zeros(domain, allocator=backend)\n",
"\n",
" addition(a, b, out=c, offset_provider={})\n",
"\n",
" assert np.allclose(c.asnumpy(), c_numpy)\n",
"\n",
" print(\"Result:\")\n",
" print(c)\n",
" print(c.asnumpy())\n",
" \n",
" # Plots\n",
" fig, ax = plt.subplot_mosaic([\n",
" ['a', 'b', 'c']\n",
" ])\n",
" ax['a'].imshow(a.asnumpy())\n",
" ax['b'].imshow(b.asnumpy())\n",
" ax['c'].imshow(c.asnumpy())\n",
"\n",
" print(\"\\nTest successful!\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "08502c34",
"metadata": {},
"outputs": [],
"source": [
"test_addition()"
]
}
],
"metadata": {
"jupytext": {
"formats": "ipynb,md:myst"
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Loading