Skip to content

Commit

Permalink
Merge branch 'main' into python311
Browse files Browse the repository at this point in the history
  • Loading branch information
egparedes committed Jan 19, 2024
2 parents 83c13ac + b900b47 commit b474e25
Show file tree
Hide file tree
Showing 52 changed files with 1,319 additions and 513 deletions.
38 changes: 19 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ repos:
## version = re.search('black==([0-9\.]*)', open("constraints.txt").read())[1]
## print(f"rev: '{version}' # version from constraints.txt")
##]]]
rev: '23.9.1' # version from constraints.txt
rev: '23.11.0' # version from constraints.txt
##[[[end]]]
hooks:
- id: black
Expand All @@ -73,7 +73,7 @@ repos:
## version = re.search('isort==([0-9\.]*)', open("constraints.txt").read())[1]
## print(f"rev: '{version}' # version from constraints.txt")
##]]]
rev: '5.12.0' # version from constraints.txt
rev: '5.13.0' # version from constraints.txt
##[[[end]]]
hooks:
- id: isort
Expand All @@ -97,14 +97,14 @@ repos:
## print(f"- {pkg}==" + str(re.search(f'\n{pkg}==([0-9\.]*)', constraints)[1]))
##]]]
- darglint==1.8.1
- flake8-bugbear==23.9.16
- flake8-builtins==2.1.0
- flake8-bugbear==23.12.2
- flake8-builtins==2.2.0
- flake8-debugger==4.1.2
- flake8-docstrings==1.7.0
- flake8-eradicate==1.5.0
- flake8-mutable==1.2.0
- flake8-pyproject==1.2.3
- pygments==2.16.1
- pygments==2.17.2
##[[[end]]]
# - flake8-rst-docstrings # Disabled for now due to random false positives
exclude: |
Expand Down Expand Up @@ -146,9 +146,9 @@ repos:
## version = re.search('mypy==([0-9\.]*)', open("constraints.txt").read())[1]
## print(f"#========= FROM constraints.txt: v{version} =========")
##]]]
#========= FROM constraints.txt: v1.5.1 =========
#========= FROM constraints.txt: v1.7.1 =========
##[[[end]]]
rev: v1.5.1 # MUST match version ^^^^ in constraints.txt (if the mirror is up-to-date)
rev: v1.7.1 # MUST match version ^^^^ in constraints.txt (if the mirror is up-to-date)
hooks:
- id: mypy
additional_dependencies: # versions from constraints.txt
Expand All @@ -162,26 +162,26 @@ repos:
##]]]
- astunparse==1.6.3
- attrs==23.1.0
- black==23.9.1
- boltons==23.0.0
- black==23.11.0
- boltons==23.1.1
- cached-property==1.5.2
- click==8.1.7
- cmake==3.27.5
- cmake==3.27.9
- cytoolz==0.12.2
- deepdiff==6.5.0
- deepdiff==6.7.1
- devtools==0.12.2
- frozendict==2.3.8
- frozendict==2.3.10
- gridtools-cpp==2.3.1
- importlib-resources==6.0.1
- importlib-resources==6.1.1
- jinja2==3.1.2
- lark==1.1.7
- mako==1.2.4
- nanobind==1.5.2
- ninja==1.11.1
- lark==1.1.8
- mako==1.3.0
- nanobind==1.8.0
- ninja==1.11.1.1
- numpy==1.24.4
- packaging==23.1
- packaging==23.2
- pybind11==2.11.1
- setuptools==68.2.2
- setuptools==69.0.2
- tabulate==0.9.0
- typing-extensions==4.5.0
- xxhash==3.0.0
Expand Down
191 changes: 102 additions & 89 deletions constraints.txt

Large diffs are not rendered by default.

189 changes: 189 additions & 0 deletions examples/lap_cartesian_vs_next.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"GT4Py - GridTools for Python\n",
"\n",
"Copyright (c) 2014-2023, ETH Zurich\n",
"All rights reserved.\n",
"\n",
"This file is part the GT4Py project and the GridTools framework.\n",
"GT4Py is free software: you can redistribute it and/or modify it under\n",
"the terms of the GNU General Public License as published by the\n",
"Free Software Foundation, either version 3 of the License, or any later\n",
"version. See the LICENSE.txt file at the top-level directory of this\n",
"distribution for a copy of the license or check <https://www.gnu.org/licenses/>.\n",
"\n",
"SPDX-License-Identifier: GPL-3.0-or-later"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Demonstrates gt4py.cartesian with gt4py.next compatibility"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Imports"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"nx = 32\n",
"ny = 32\n",
"nz = 1\n",
"dtype = np.float64"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Storages\n",
"--\n",
"\n",
"We create fields using the gt4py.next constructors. These fields are compatible with gt4py.cartesian when we use \"I\", \"J\", \"K\" as the dimension names."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<link href=\"https://fonts.googleapis.com/icon?family=Material+Icons\" rel=\"stylesheet\"><script src=\"https://spcl.github.io/dace/webclient2/dist/sdfv.js\"></script>\n",
"<link href=\"https://spcl.github.io/dace/webclient2/sdfv.css\" rel=\"stylesheet\">\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import gt4py.next as gtx\n",
"\n",
"allocator = gtx.itir_embedded # should match the executor\n",
"# allocator = gtx.gtfn_cpu\n",
"# allocator = gtx.gtfn_gpu\n",
"\n",
"# Note: for gt4py.next, names don't matter, for gt4py.cartesian they have to be \"I\", \"J\", \"K\"\n",
"I = gtx.Dimension(\"I\")\n",
"J = gtx.Dimension(\"J\")\n",
"K = gtx.Dimension(\"K\", kind=gtx.DimensionKind.VERTICAL)\n",
"\n",
"domain = gtx.domain({I: nx, J: ny, K: nz})\n",
"\n",
"inp = gtx.as_field(domain, np.fromfunction(lambda x, y, z: x**2+y**2, shape=(nx, ny, nz)), dtype, allocator=allocator)\n",
"out_cartesian = gtx.zeros(domain, dtype, allocator=allocator)\n",
"out_next = gtx.zeros(domain, dtype, allocator=allocator)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"gt4py.cartesian\n",
"--"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import gt4py.cartesian.gtscript as gtscript\n",
"\n",
"cartesian_backend = \"numpy\"\n",
"# cartesian_backend = \"gt:cpu_ifirst\"\n",
"# cartesian_backend = \"gt:gpu\"\n",
"\n",
"@gtscript.stencil(backend=cartesian_backend)\n",
"def lap_cartesian(\n",
" inp: gtscript.Field[dtype],\n",
" out: gtscript.Field[dtype],\n",
"):\n",
" with computation(PARALLEL), interval(...):\n",
" out = -4.0 * inp[0, 0, 0] + inp[-1, 0, 0] + inp[1, 0, 0] + inp[0, -1, 0] + inp[0, 1, 0]\n",
"\n",
"lap_cartesian(inp=inp, out=out_cartesian, origin=(1, 1, 0), domain=(nx-2, ny-2, nz))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"from gt4py.next import Field\n",
"\n",
"next_backend = gtx.itir_embedded\n",
"# next_backend = gtx.gtfn_cpu\n",
"# next_backend = gtx.gtfn_gpu\n",
"\n",
"Ioff = gtx.FieldOffset(\"I\", source=I, target=(I,))\n",
"Joff = gtx.FieldOffset(\"J\", source=J, target=(J,))\n",
"\n",
"@gtx.field_operator\n",
"def lap_next(inp: Field[[I, J, K], dtype]) -> Field[[I, J, K], dtype]:\n",
" return -4.0 * inp + inp(Ioff[-1]) + inp(Ioff[1]) + inp(Joff[-1]) + inp(Joff[1])\n",
"\n",
"@gtx.program(backend=next_backend)\n",
"def lap_next_program(inp: Field[[I, J, K], dtype], out: Field[[I, J, K], dtype]):\n",
" lap_next(inp, out=out[1:-1, 1:-1, :])\n",
"\n",
"lap_next_program(inp, out_next, offset_provider={\"Ioff\": I, \"Joff\": J})"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"assert np.allclose(out_cartesian.asnumpy(), out_next.asnumpy())"
]
}
],
"metadata": {
"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.13"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
4 changes: 2 additions & 2 deletions min-extra-requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ cmake==3.22
cogapp==3.3
coverage[toml]==5.0
cytoolz==0.12.0
dace==0.14.2
dace==0.15.1
darglint==1.6
deepdiff==5.6.0
devtools==0.6
Expand Down Expand Up @@ -70,7 +70,7 @@ scipy==1.7.2
setuptools==65.5.0
sphinx==4.4
sphinx_rtd_theme==1.0
sympy==1.7
sympy==1.9
tabulate==0.8.10
tomli==2.0.1
tox==3.2.0
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ requires-python = '>=3.8'
cuda = ['cupy>=12.0']
cuda11x = ['cupy-cuda11x>=12.0']
cuda12x = ['cupy-cuda12x>=12.0']
dace = ['dace>=0.14.2,<0.15', 'sympy>=1.7']
dace = ['dace>=0.15.1,<0.16', 'sympy>=1.9']
formatting = ['clang-format>=9.0']
# Always add all extra packages to 'full' for a simple full gt4py installation
full = [
'clang-format>=9.0',
'dace>=0.14.2,<0.15',
'dace>=0.15.1,<0.16',
'hypothesis>=6.0.0',
'pytest>=7.0',
'sympy>=1.7',
'sympy>=1.9',
'scipy>=1.7.2',
'jax[cpu]>=0.4.13'
]
Expand Down
Loading

0 comments on commit b474e25

Please sign in to comment.