From e4fb8025cbb117fd28bbf75dc506eb40b7f92d02 Mon Sep 17 00:00:00 2001 From: Roman Cattaneo Date: Tue, 3 Sep 2024 14:47:47 +0200 Subject: [PATCH] refactor: Remove stale references to flake8 (#1625) In PR https://github.com/GridTools/gt4py/pull/1466, `flake8`, `black`, and `isort` were replaced with the [ruff](https://astral.sh/ruff) linter and formatter. It seems there are a few leftovers of this transition. In this PR, I did a quick search for flake8 and deleted / replaced all instances found. Removing `flake8` means rebuilding the requirements (to propagate the changes to the frozen `requirements-*` files), which updates a couple of dependencies. We also decided to remove the `linter-*` tasks of `tox` since they have been replaced by `pre-commit`. --- .pre-commit-config.yaml | 20 +- AUTHORS.md | 1 + CODING_GUIDELINES.md | 3 - CONTRIBUTING.md | 20 +- constraints.txt | 77 +++---- docs/development/tools/ci-infrastructure.md | 2 +- .../exercises/1_simple_addition.ipynb | 14 +- .../1_simple_addition_solution.ipynb | 12 +- .../exercises/2_divergence_exercise.ipynb | 15 +- .../2_divergence_exercise_solution.ipynb | 15 +- .../exercises/3_gradient_exercise.ipynb | 10 +- .../3_gradient_exercise_solution.ipynb | 10 +- .../workshop/exercises/4_curl_exercise.ipynb | 20 +- .../exercises/4_curl_exercise_solution.ipynb | 20 +- .../exercises/5_vector_laplace_exercise.ipynb | 59 ++--- .../5_vector_laplace_exercise_solution.ipynb | 64 +++--- .../workshop/exercises/6_where_domain.ipynb | 19 +- .../exercises/6_where_domain_solutions.ipynb | 26 ++- .../workshop/exercises/7_scan_operator.ipynb | 13 +- .../exercises/7_scan_operator_solutions.ipynb | 7 +- .../8_diffusion_exercise_solution.ipynb | 62 +++--- docs/user/next/workshop/jupyter_intro.ipynb | 2 +- docs/user/next/workshop/slides/slides_1.ipynb | 18 +- docs/user/next/workshop/slides/slides_2.ipynb | 81 ++++--- docs/user/next/workshop/slides/slides_3.ipynb | 30 ++- docs/user/next/workshop/slides/slides_4.ipynb | 11 +- examples/cartesian/demo_burgers.ipynb | 207 +++++++++++------- .../cartesian/demo_horizontal_diffusion.ipynb | 27 +-- .../demo_isentropic_diagnostics.ipynb | 87 ++++---- examples/lap_cartesian_vs_next.ipynb | 16 +- min-extra-requirements-test.txt | 9 - min-requirements-test.txt | 9 - requirements-dev.in | 9 - requirements-dev.txt | 77 +++---- src/gt4py/eve/extended_typing.py | 2 +- .../backend_tests/test_module_generator.py | 1 - tox.ini | 7 - 37 files changed, 530 insertions(+), 552 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d43b04716c..0e47535a46 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -49,7 +49,7 @@ repos: ## version = re.search('ruff==([0-9\.]*)', open("constraints.txt").read())[1] ## print(f"rev: v{version}") ##]]] - rev: v0.5.6 + rev: v0.6.3 ##[[[end]]] hooks: # Run the linter. @@ -66,9 +66,9 @@ repos: ## version = re.search('mypy==([0-9\.]*)', open("constraints.txt").read())[1] ## print(f"#========= FROM constraints.txt: v{version} =========") ##]]] - #========= FROM constraints.txt: v1.11.1 ========= + #========= FROM constraints.txt: v1.11.2 ========= ##[[[end]]] - rev: v1.11.1 # MUST match version ^^^^ in constraints.txt (if the mirror is up-to-date) + rev: v1.11.2 # MUST match version ^^^^ in constraints.txt (if the mirror is up-to-date) hooks: - id: mypy additional_dependencies: # versions from constraints.txt @@ -92,21 +92,21 @@ repos: - click==8.1.7 - cmake==3.30.2 - cytoolz==0.12.3 - - deepdiff==7.0.1 + - deepdiff==8.0.1 - devtools==0.12.2 - - factory-boy==3.3.0 + - factory-boy==3.3.1 - frozendict==2.4.4 - gridtools-cpp==2.3.4 - - importlib-resources==6.4.0 + - importlib-resources==6.4.4 - jinja2==3.1.4 - - lark==1.1.9 + - lark==1.2.2 - mako==1.3.5 - - nanobind==2.0.0 + - nanobind==2.1.0 - ninja==1.11.1.1 - numpy==1.24.4 - packaging==24.1 - - pybind11==2.13.1 - - setuptools==72.1.0 + - pybind11==2.13.5 + - setuptools==74.0.0 - tabulate==0.9.0 - typing-extensions==4.12.2 - xxhash==3.0.0 diff --git a/AUTHORS.md b/AUTHORS.md index 1aea538625..1bcdd266b8 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -3,6 +3,7 @@ - Benedicic, Lucas. ETH Zurich - CSCS +- Cattaneo, Roman. SSAI/NASA-GSFC - Cruz, Felipe. ETH Zurich - CSCS - Dahm, Johann. Allen Institute for AI - Davis, Eddie. Allen Institute for AI diff --git a/CODING_GUIDELINES.md b/CODING_GUIDELINES.md index cdcad0f4b8..3f23e23f34 100644 --- a/CODING_GUIDELINES.md +++ b/CODING_GUIDELINES.md @@ -222,9 +222,7 @@ https://testandcode.com/116 [doctest]: https://docs.python.org/3/library/doctest.html [google-style-guide]: https://google.github.io/styleguide/pyguide.html -[mypy]: https://mypy.readthedocs.io/ [mypy-error-codes]: https://mypy.readthedocs.io/en/stable/error_code_list.html -[pre-commit]: https://pre-commit.com/ [pylint]: https://pylint.pycqa.org/ [ruff-formatter]: https://docs.astral.sh/ruff/formatter/ [ruff-linter]: https://docs.astral.sh/ruff/linter/ @@ -233,4 +231,3 @@ https://testandcode.com/116 [sphinx-autodoc]: https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html [sphinx-napoleon]: https://sphinxcontrib-napoleon.readthedocs.io/en/latest/index.html# [sphinx-rest]: https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html -[ci-docs]: docs/development/CI/infrastructure.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4b4edd3f52..15e139a53e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -106,8 +106,8 @@ pre-commit run # Check all the files in the repository: -a / --all-files pre-commit run -a -# Run only some of the tools (e.g. flake8) -pre-commit run -a flake8 +# Run only some of the tools (e.g. ruff) +pre-commit run -a ruff ``` ### Unit and Regression Tests @@ -175,9 +175,7 @@ Before submitting a pull request, check that it meets the following criteria: As mentioned above, we use several tools to help us write high-quality code. New tools could be added in the future, especially if they do not add a large overhead to our workflow and they bring extra benefits to keep our codebase in shape. The most important ones which we currently rely on are: -- [Black][black] for autoformatting source code. -- [isort][isort] for autoformatting import statements. -- [Flake8][flake8] for style enforcement and code linting. +- [ruff][ruff] for style enforcement and code linting. - [pre-commit][pre-commit] for automating the execution of QA tools. - [pytest][pytest] for writing readable tests, extended with: - [Coverage.py][coverage] and [pytest-cov][pytest-cov] for test coverage reports. @@ -189,21 +187,15 @@ As mentioned above, we use several tools to help us write high-quality code. New -[black]: https://black.readthedocs.io/en/stable/ -[commitizen]: https://commitizen-tools.github.io/commitizen/ [conventional-commits]: https://www.conventionalcommits.org/en/v1.0.0/#summary [coverage]: https://coverage.readthedocs.io/ -[flake8]: https://flake8.pycqa.org/ -[google-style-guide]: https://google.github.io/styleguide/pyguide.html -[isort]: https://pycqa.github.io/isort/ +[ruff]: https://astral.sh/ruff [jupytext]: https://jupytext.readthedocs.io/ [pre-commit]: https://pre-commit.com/ -[pylint]: https://pylint.pycqa.org/ [pytest]: https://docs.pytest.org/ [pytest-cov]: https://pypi.org/project/pytest-cov/ [pytest-xdist]: https://pytest-xdist.readthedocs.io/en/latest/ [sphinx]: https://www.sphinx-doc.org [sphinx-autodoc]: https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html -[sphinx-napoleon]: https://sphinxcontrib-napoleon.readthedocs.io/en/latest/index.html# -[sphinx-rest]: https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html -[tox]: https://tox.wiki/en/latest/# +[sphinx-napoleon]: https://sphinxcontrib-napoleon.readthedocs.io/en/latest/index.html +[tox]: https://tox.wiki/en/latest/ diff --git a/constraints.txt b/constraints.txt index e5027a922a..1a8971fbdb 100644 --- a/constraints.txt +++ b/constraints.txt @@ -9,17 +9,17 @@ alabaster==0.7.13 # via sphinx annotated-types==0.7.0 # via pydantic asttokens==2.4.1 # via devtools, stack-data astunparse==1.6.3 ; python_version < "3.9" # via dace, gt4py (pyproject.toml) -attrs==24.2.0 # via flake8-bugbear, flake8-eradicate, gt4py (pyproject.toml), hypothesis, jsonschema, referencing -babel==2.15.0 # via sphinx +attrs==24.2.0 # via gt4py (pyproject.toml), hypothesis, jsonschema, referencing +babel==2.16.0 # via sphinx backcall==0.2.0 # via ipython black==24.8.0 # via gt4py (pyproject.toml) boltons==24.0.0 # via gt4py (pyproject.toml) bracex==2.5 # via wcmatch build==1.2.1 # via pip-tools -bump-my-version==0.25.0 # via -r requirements-dev.in +bump-my-version==0.26.0 # via -r requirements-dev.in cached-property==1.5.2 # via gt4py (pyproject.toml) -cachetools==5.4.0 # via tox -certifi==2024.7.4 # via requests +cachetools==5.5.0 # via tox +certifi==2024.8.30 # via requests cfgv==3.4.0 # via pre-commit chardet==5.2.0 # via tox charset-normalizer==3.3.2 # via requests @@ -37,38 +37,28 @@ dace==0.16.1 # via gt4py (pyproject.toml) darglint==1.8.1 # via -r requirements-dev.in debugpy==1.8.5 # via ipykernel decorator==5.1.1 # via ipython -deepdiff==7.0.1 # via gt4py (pyproject.toml) +deepdiff==8.0.1 # via gt4py (pyproject.toml) devtools==0.12.2 # via gt4py (pyproject.toml) dill==0.3.8 # via dace distlib==0.3.8 # via virtualenv -docutils==0.20.1 # via restructuredtext-lint, sphinx, sphinx-rtd-theme -eradicate==2.3.0 # via flake8-eradicate +docutils==0.20.1 # via sphinx, sphinx-rtd-theme exceptiongroup==1.2.2 # via hypothesis, pytest execnet==2.1.1 # via pytest-cache, pytest-xdist -executing==2.0.1 # via devtools, stack-data -factory-boy==3.3.0 # via gt4py (pyproject.toml), pytest-factoryboy -faker==26.2.0 # via factory-boy +executing==2.1.0 # via devtools, stack-data +factory-boy==3.3.1 # via gt4py (pyproject.toml), pytest-factoryboy +faker==28.1.0 # via factory-boy fastjsonschema==2.20.0 # via nbformat filelock==3.15.4 # via tox, virtualenv -flake8==7.1.1 # via -r requirements-dev.in, flake8-bugbear, flake8-builtins, flake8-debugger, flake8-docstrings, flake8-eradicate, flake8-mutable, flake8-pyproject, flake8-rst-docstrings -flake8-bugbear==24.4.26 # via -r requirements-dev.in -flake8-builtins==2.5.0 # via -r requirements-dev.in -flake8-debugger==4.1.2 # via -r requirements-dev.in -flake8-docstrings==1.7.0 # via -r requirements-dev.in -flake8-eradicate==1.5.0 # via -r requirements-dev.in -flake8-mutable==1.2.0 # via -r requirements-dev.in -flake8-pyproject==1.2.3 # via -r requirements-dev.in -flake8-rst-docstrings==0.3.0 # via -r requirements-dev.in fonttools==4.53.1 # via matplotlib fparser==0.1.4 # via dace frozendict==2.4.4 # via gt4py (pyproject.toml) gridtools-cpp==2.3.4 # via gt4py (pyproject.toml) -hypothesis==6.109.0 # via -r requirements-dev.in, gt4py (pyproject.toml) +hypothesis==6.111.2 # via -r requirements-dev.in, gt4py (pyproject.toml) identify==2.6.0 # via pre-commit -idna==3.7 # via requests +idna==3.8 # via requests imagesize==1.4.1 # via sphinx -importlib-metadata==8.2.0 # via build, jupyter-client, sphinx -importlib-resources==6.4.0 ; python_version < "3.9" # via gt4py (pyproject.toml), jsonschema, jsonschema-specifications, matplotlib +importlib-metadata==8.4.0 # via build, jupyter-client, sphinx +importlib-resources==6.4.4 ; python_version < "3.9" # via gt4py (pyproject.toml), jsonschema, jsonschema-specifications, matplotlib inflection==0.5.1 # via pytest-factoryboy iniconfig==2.0.0 # via pytest ipykernel==6.29.5 # via nbmake @@ -82,19 +72,18 @@ jupyter-client==8.6.2 # via ipykernel, nbclient jupyter-core==5.7.2 # via ipykernel, jupyter-client, nbformat jupytext==1.16.4 # via -r requirements-dev.in kiwisolver==1.4.5 # via matplotlib -lark==1.1.9 # via gt4py (pyproject.toml) +lark==1.2.2 # via gt4py (pyproject.toml) mako==1.3.5 # via gt4py (pyproject.toml) markdown-it-py==3.0.0 # via jupytext, mdit-py-plugins, rich markupsafe==2.1.5 # via jinja2, mako matplotlib==3.7.5 # via -r requirements-dev.in matplotlib-inline==0.1.7 # via ipykernel, ipython -mccabe==0.7.0 # via flake8 mdit-py-plugins==0.4.1 # via jupytext mdurl==0.1.2 # via markdown-it-py mpmath==1.3.0 # via sympy -mypy==1.11.1 # via -r requirements-dev.in +mypy==1.11.2 # via -r requirements-dev.in mypy-extensions==1.0.0 # via black, mypy -nanobind==2.0.0 # via gt4py (pyproject.toml) +nanobind==2.1.0 # via gt4py (pyproject.toml) nbclient==0.6.8 # via nbmake nbformat==5.10.4 # via jupytext, nbclient, nbmake nbmake==1.5.4 # via -r requirements-dev.in @@ -103,7 +92,7 @@ networkx==3.1 # via dace ninja==1.11.1.1 # via gt4py (pyproject.toml) nodeenv==1.9.1 # via pre-commit numpy==1.24.4 # via contourpy, dace, gt4py (pyproject.toml), matplotlib, scipy -ordered-set==4.1.0 # via deepdiff +orderly-set==5.2.2 # via deepdiff packaging==24.1 # via black, build, gt4py (pyproject.toml), ipykernel, jupytext, matplotlib, pipdeptree, pyproject-api, pytest, pytest-factoryboy, setuptools-scm, sphinx, tox parso==0.8.4 # via jedi pathspec==0.12.1 # via black @@ -121,15 +110,12 @@ prompt-toolkit==3.0.36 # via ipython, questionary psutil==6.0.0 # via -r requirements-dev.in, ipykernel, pytest-xdist ptyprocess==0.7.0 # via pexpect pure-eval==0.2.3 # via stack-data -pybind11==2.13.1 # via gt4py (pyproject.toml) -pycodestyle==2.12.1 # via flake8, flake8-debugger +pybind11==2.13.5 # via gt4py (pyproject.toml) pydantic==2.8.2 # via bump-my-version, pydantic-settings pydantic-core==2.20.1 # via pydantic pydantic-settings==2.4.0 # via bump-my-version -pydocstyle==6.3.0 # via flake8-docstrings -pyflakes==3.2.0 # via flake8 -pygments==2.18.0 # via -r requirements-dev.in, devtools, flake8-rst-docstrings, ipython, nbmake, rich, sphinx -pyparsing==3.1.2 # via matplotlib +pygments==2.18.0 # via -r requirements-dev.in, devtools, ipython, nbmake, rich, sphinx +pyparsing==3.1.4 # via matplotlib pyproject-api==1.7.1 # via tox pyproject-hooks==1.1.0 # via build, pip-tools pytest==8.3.2 # via -r requirements-dev.in, gt4py (pyproject.toml), nbmake, pytest-cache, pytest-cov, pytest-factoryboy, pytest-instafail, pytest-xdist @@ -142,19 +128,18 @@ python-dateutil==2.9.0.post0 # via faker, jupyter-client, matplotlib python-dotenv==1.0.1 # via pydantic-settings pytz==2024.1 # via babel pyyaml==6.0.2 # via dace, jupytext, pre-commit -pyzmq==26.1.0 # via ipykernel, jupyter-client +pyzmq==26.2.0 # via ipykernel, jupyter-client questionary==2.0.1 # via bump-my-version referencing==0.35.1 # via jsonschema, jsonschema-specifications requests==2.32.3 # via sphinx -restructuredtext-lint==1.4.0 # via flake8-rst-docstrings -rich==13.7.1 # via bump-my-version, rich-click +rich==13.8.0 # via bump-my-version, rich-click rich-click==1.8.3 # via bump-my-version rpds-py==0.20.0 # via jsonschema, referencing -ruff==0.5.6 # via -r requirements-dev.in +ruff==0.6.3 # via -r requirements-dev.in scipy==1.10.1 # via gt4py (pyproject.toml) setuptools-scm==8.1.0 # via fparser six==1.16.0 # via asttokens, astunparse, python-dateutil -snowballstemmer==2.2.0 # via pydocstyle, sphinx +snowballstemmer==2.2.0 # via sphinx sortedcontainers==2.4.0 # via hypothesis sphinx==7.1.2 # via -r requirements-dev.in, sphinx-rtd-theme, sphinxcontrib-jquery sphinx-rtd-theme==2.0.0 # via -r requirements-dev.in @@ -168,11 +153,11 @@ sphinxcontrib-serializinghtml==1.1.5 # via sphinx stack-data==0.6.3 # via ipython sympy==1.12.1 # via dace, gt4py (pyproject.toml) tabulate==0.9.0 # via gt4py (pyproject.toml) -tomli==2.0.1 ; python_version < "3.11" # via -r requirements-dev.in, black, build, coverage, flake8-pyproject, jupytext, mypy, pip-tools, pyproject-api, pytest, setuptools-scm, tox -tomlkit==0.13.0 # via bump-my-version +tomli==2.0.1 ; python_version < "3.11" # via -r requirements-dev.in, black, build, coverage, jupytext, mypy, pip-tools, pyproject-api, pytest, setuptools-scm, tox +tomlkit==0.13.2 # via bump-my-version toolz==0.12.1 # via cytoolz tornado==6.4.1 # via ipykernel, jupyter-client -tox==4.17.0 # via -r requirements-dev.in +tox==4.18.0 # via -r requirements-dev.in traitlets==5.14.3 # via comm, ipykernel, ipython, jupyter-client, jupyter-core, matplotlib-inline, nbclient, nbformat types-tabulate==0.9.0.20240106 # via -r requirements-dev.in typing-extensions==4.12.2 # via annotated-types, black, gt4py (pyproject.toml), ipython, mypy, pydantic, pydantic-core, pytest-factoryboy, rich, rich-click, setuptools-scm @@ -180,11 +165,11 @@ urllib3==2.2.2 # via requests virtualenv==20.26.3 # via pre-commit, tox wcmatch==9.0 # via bump-my-version wcwidth==0.2.13 # via prompt-toolkit -websockets==12.0 # via dace +websockets==13.0.1 # via dace wheel==0.44.0 # via astunparse, pip-tools xxhash==3.0.0 # via gt4py (pyproject.toml) -zipp==3.19.2 # via importlib-metadata, importlib-resources +zipp==3.20.1 # via importlib-metadata, importlib-resources # The following packages are considered to be unsafe in a requirements file: pip==24.2 # via pip-tools, pipdeptree -setuptools==72.1.0 # via gt4py (pyproject.toml), pip-tools, setuptools-scm +setuptools==74.0.0 # via gt4py (pyproject.toml), pip-tools, setuptools-scm diff --git a/docs/development/tools/ci-infrastructure.md b/docs/development/tools/ci-infrastructure.md index 0870e532e2..1a4786e6e6 100644 --- a/docs/development/tools/ci-infrastructure.md +++ b/docs/development/tools/ci-infrastructure.md @@ -85,7 +85,7 @@ flowchart LR The `Test Eve`, `Test Storage (CPU)`, `Test Cartesian (CPU)`, and `Test Next (CPU)` workflows run the automated tests for the respective subpackages. In all cases only tests are run that do not require the presence of a GPU. -The `Code Quality` workflow runs pre-commit to check code quality requirements through tools like **mypy** or **flake8**. +The `Code Quality` workflow runs pre-commit to check code quality requirements through tools like **mypy** or **ruff**. Code coverage workflows are currently disabled. diff --git a/docs/user/next/workshop/exercises/1_simple_addition.ipynb b/docs/user/next/workshop/exercises/1_simple_addition.ipynb index 918e72b084..7f42f2b9d8 100644 --- a/docs/user/next/workshop/exercises/1_simple_addition.ipynb +++ b/docs/user/next/workshop/exercises/1_simple_addition.ipynb @@ -60,7 +60,7 @@ "metadata": {}, "outputs": [], "source": [ - "def addition ... # TODO fix this cell" + "def addition(): ... # TODO fix this cell" ] }, { @@ -89,14 +89,12 @@ " print(\"Result:\")\n", " print(c)\n", " print(c.asnumpy())\n", - " \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", + " fig, ax = plt.subplot_mosaic([[\"a\", \"b\", \"c\"]])\n", + " ax[\"a\"].imshow(a.asnumpy())\n", + " ax[\"b\"].imshow(b.asnumpy())\n", + " ax[\"c\"].imshow(c.asnumpy())\n", "\n", " print(\"\\nTest successful!\")" ] diff --git a/docs/user/next/workshop/exercises/1_simple_addition_solution.ipynb b/docs/user/next/workshop/exercises/1_simple_addition_solution.ipynb index 59505f142a..dd1a30cc6b 100644 --- a/docs/user/next/workshop/exercises/1_simple_addition_solution.ipynb +++ b/docs/user/next/workshop/exercises/1_simple_addition_solution.ipynb @@ -120,14 +120,12 @@ " print(\"Result:\")\n", " print(c)\n", " print(c.asnumpy())\n", - " \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", + " fig, ax = plt.subplot_mosaic([[\"a\", \"b\", \"c\"]])\n", + " ax[\"a\"].imshow(a.asnumpy())\n", + " ax[\"b\"].imshow(b.asnumpy())\n", + " ax[\"c\"].imshow(c.asnumpy())\n", "\n", " print(\"\\nTest successful!\")" ] diff --git a/docs/user/next/workshop/exercises/2_divergence_exercise.ipynb b/docs/user/next/workshop/exercises/2_divergence_exercise.ipynb index 86baf90901..50349e52b0 100644 --- a/docs/user/next/workshop/exercises/2_divergence_exercise.ipynb +++ b/docs/user/next/workshop/exercises/2_divergence_exercise.ipynb @@ -53,12 +53,7 @@ " A: np.array,\n", " edge_orientation: np.array,\n", ") -> np.array:\n", - " uv_div = (\n", - " np.sum(\n", - " (u[c2e] * nx[c2e] + v[c2e] * ny[c2e]) * L[c2e] * edge_orientation, axis=1\n", - " )\n", - " / A\n", - " )\n", + " uv_div = np.sum((u[c2e] * nx[c2e] + v[c2e] * ny[c2e]) * L[c2e] * edge_orientation, axis=1) / A\n", " return uv_div" ] }, @@ -105,9 +100,7 @@ " ny = random_field(edge_domain, allocator=backend)\n", " L = random_field(edge_domain, allocator=backend)\n", " A = random_field(cell_domain, allocator=backend)\n", - " edge_orientation = random_sign(\n", - " gtx.domain({C: n_cells, C2EDim: 3}), allocator=backend\n", - " )\n", + " edge_orientation = random_sign(gtx.domain({C: n_cells, C2EDim: 3}), allocator=backend)\n", "\n", " divergence_ref = divergence_numpy(\n", " c2e_table,\n", @@ -120,9 +113,7 @@ " edge_orientation.asnumpy(),\n", " )\n", "\n", - " c2e_connectivity = gtx.NeighborTableOffsetProvider(\n", - " c2e_table, C, E, 3, has_skip_values=False\n", - " )\n", + " c2e_connectivity = gtx.NeighborTableOffsetProvider(c2e_table, C, E, 3, has_skip_values=False)\n", "\n", " divergence_gt4py = gtx.zeros(cell_domain, allocator=backend)\n", "\n", diff --git a/docs/user/next/workshop/exercises/2_divergence_exercise_solution.ipynb b/docs/user/next/workshop/exercises/2_divergence_exercise_solution.ipynb index eda22846eb..6baac2b8c0 100644 --- a/docs/user/next/workshop/exercises/2_divergence_exercise_solution.ipynb +++ b/docs/user/next/workshop/exercises/2_divergence_exercise_solution.ipynb @@ -53,12 +53,7 @@ " A: np.array,\n", " edge_orientation: np.array,\n", ") -> np.array:\n", - " uv_div = (\n", - " np.sum(\n", - " (u[c2e] * nx[c2e] + v[c2e] * ny[c2e]) * L[c2e] * edge_orientation, axis=1\n", - " )\n", - " / A\n", - " )\n", + " uv_div = np.sum((u[c2e] * nx[c2e] + v[c2e] * ny[c2e]) * L[c2e] * edge_orientation, axis=1) / A\n", " return uv_div" ] }, @@ -110,9 +105,7 @@ " ny = random_field(edge_domain, allocator=backend)\n", " L = random_field(edge_domain, allocator=backend)\n", " A = random_field(cell_domain, allocator=backend)\n", - " edge_orientation = random_sign(\n", - " gtx.domain({C: n_cells, C2EDim: 3}), allocator=backend\n", - " )\n", + " edge_orientation = random_sign(gtx.domain({C: n_cells, C2EDim: 3}), allocator=backend)\n", "\n", " divergence_ref = divergence_numpy(\n", " c2e_table,\n", @@ -125,9 +118,7 @@ " edge_orientation.asnumpy(),\n", " )\n", "\n", - " c2e_connectivity = gtx.NeighborTableOffsetProvider(\n", - " c2e_table, C, E, 3, has_skip_values=False\n", - " )\n", + " c2e_connectivity = gtx.NeighborTableOffsetProvider(c2e_table, C, E, 3, has_skip_values=False)\n", "\n", " divergence_gt4py = gtx.zeros(cell_domain, allocator=backend)\n", "\n", diff --git a/docs/user/next/workshop/exercises/3_gradient_exercise.ipynb b/docs/user/next/workshop/exercises/3_gradient_exercise.ipynb index a0e5580eb6..c8914120d3 100644 --- a/docs/user/next/workshop/exercises/3_gradient_exercise.ipynb +++ b/docs/user/next/workshop/exercises/3_gradient_exercise.ipynb @@ -92,15 +92,13 @@ "\n", " cell_domain = gtx.domain({C: n_cells})\n", " edge_domain = gtx.domain({E: n_edges})\n", - " \n", + "\n", " f = random_field(edge_domain, allocator=backend)\n", " nx = random_field(edge_domain, allocator=backend)\n", " ny = random_field(edge_domain, allocator=backend)\n", " L = random_field(edge_domain, allocator=backend)\n", " A = random_field(cell_domain, allocator=backend)\n", - " edge_orientation = random_sign(\n", - " gtx.domain({C: n_cells, C2EDim: 3}), allocator=backend\n", - " )\n", + " edge_orientation = random_sign(gtx.domain({C: n_cells, C2EDim: 3}), allocator=backend)\n", "\n", " gradient_numpy_x, gradient_numpy_y = gradient_numpy(\n", " c2e_table,\n", @@ -114,8 +112,8 @@ "\n", " c2e_connectivity = gtx.NeighborTableOffsetProvider(c2e_table, C, E, 3, has_skip_values=False)\n", "\n", - " gradient_gt4py_x = gtx.zeros(cell_domain, allocator=backend) \n", - " gradient_gt4py_y = gtx.zeros(cell_domain, allocator=backend) \n", + " gradient_gt4py_x = gtx.zeros(cell_domain, allocator=backend)\n", + " gradient_gt4py_y = gtx.zeros(cell_domain, allocator=backend)\n", "\n", " gradient(\n", " f,\n", diff --git a/docs/user/next/workshop/exercises/3_gradient_exercise_solution.ipynb b/docs/user/next/workshop/exercises/3_gradient_exercise_solution.ipynb index 64550d9b58..5e940a4b71 100644 --- a/docs/user/next/workshop/exercises/3_gradient_exercise_solution.ipynb +++ b/docs/user/next/workshop/exercises/3_gradient_exercise_solution.ipynb @@ -105,15 +105,13 @@ "\n", " cell_domain = gtx.domain({C: n_cells})\n", " edge_domain = gtx.domain({E: n_edges})\n", - " \n", + "\n", " f = random_field(edge_domain, allocator=backend)\n", " nx = random_field(edge_domain, allocator=backend)\n", " ny = random_field(edge_domain, allocator=backend)\n", " L = random_field(edge_domain, allocator=backend)\n", " A = random_field(cell_domain, allocator=backend)\n", - " edge_orientation = random_sign(\n", - " gtx.domain({C: n_cells, C2EDim: 3}), allocator=backend\n", - " )\n", + " edge_orientation = random_sign(gtx.domain({C: n_cells, C2EDim: 3}), allocator=backend)\n", "\n", " gradient_numpy_x, gradient_numpy_y = gradient_numpy(\n", " c2e_table,\n", @@ -127,8 +125,8 @@ "\n", " c2e_connectivity = gtx.NeighborTableOffsetProvider(c2e_table, C, E, 3, has_skip_values=False)\n", "\n", - " gradient_gt4py_x = gtx.zeros(cell_domain, allocator=backend) \n", - " gradient_gt4py_y = gtx.zeros(cell_domain, allocator=backend) \n", + " gradient_gt4py_x = gtx.zeros(cell_domain, allocator=backend)\n", + " gradient_gt4py_y = gtx.zeros(cell_domain, allocator=backend)\n", "\n", " gradient(\n", " f,\n", diff --git a/docs/user/next/workshop/exercises/4_curl_exercise.ipynb b/docs/user/next/workshop/exercises/4_curl_exercise.ipynb index 54806b4a3a..4a6b37baf7 100644 --- a/docs/user/next/workshop/exercises/4_curl_exercise.ipynb +++ b/docs/user/next/workshop/exercises/4_curl_exercise.ipynb @@ -114,16 +114,14 @@ "\n", " edge_domain = gtx.domain({E: n_edges})\n", " vertex_domain = gtx.domain({V: n_vertices})\n", - " \n", + "\n", " u = random_field(edge_domain, allocator=backend)\n", " v = random_field(edge_domain, allocator=backend)\n", " nx = random_field(edge_domain, allocator=backend)\n", " ny = random_field(edge_domain, allocator=backend)\n", " dualL = random_field(edge_domain, allocator=backend)\n", " dualA = random_field(vertex_domain, allocator=backend)\n", - " edge_orientation = random_sign(\n", - " gtx.domain({V: n_vertices, V2EDim: 6}), allocator=backend\n", - " )\n", + " edge_orientation = random_sign(gtx.domain({V: n_vertices, V2EDim: 6}), allocator=backend)\n", "\n", " divergence_ref = curl_numpy(\n", " v2e_table,\n", @@ -138,12 +136,20 @@ "\n", " v2e_connectivity = gtx.NeighborTableOffsetProvider(v2e_table, V, E, 6, has_skip_values=False)\n", "\n", - " curl_gt4py = gtx.zeros(vertex_domain, allocator=backend) \n", + " curl_gt4py = gtx.zeros(vertex_domain, allocator=backend)\n", "\n", " curl(\n", - " u, v, nx, ny, dualL, dualA, edge_orientation, out = curl_gt4py, offset_provider = {V2E.value: v2e_connectivity}\n", + " u,\n", + " v,\n", + " nx,\n", + " ny,\n", + " dualL,\n", + " dualA,\n", + " edge_orientation,\n", + " out=curl_gt4py,\n", + " offset_provider={V2E.value: v2e_connectivity},\n", " )\n", - " \n", + "\n", " assert np.allclose(curl_gt4py.asnumpy(), divergence_ref)" ] }, diff --git a/docs/user/next/workshop/exercises/4_curl_exercise_solution.ipynb b/docs/user/next/workshop/exercises/4_curl_exercise_solution.ipynb index 2649c5e2cd..065cf02de7 100644 --- a/docs/user/next/workshop/exercises/4_curl_exercise_solution.ipynb +++ b/docs/user/next/workshop/exercises/4_curl_exercise_solution.ipynb @@ -119,16 +119,14 @@ "\n", " edge_domain = gtx.domain({E: n_edges})\n", " vertex_domain = gtx.domain({V: n_vertices})\n", - " \n", + "\n", " u = random_field(edge_domain, allocator=backend)\n", " v = random_field(edge_domain, allocator=backend)\n", " nx = random_field(edge_domain, allocator=backend)\n", " ny = random_field(edge_domain, allocator=backend)\n", " dualL = random_field(edge_domain, allocator=backend)\n", " dualA = random_field(vertex_domain, allocator=backend)\n", - " edge_orientation = random_sign(\n", - " gtx.domain({V: n_vertices, V2EDim: 6}), allocator=backend\n", - " )\n", + " edge_orientation = random_sign(gtx.domain({V: n_vertices, V2EDim: 6}), allocator=backend)\n", "\n", " divergence_ref = curl_numpy(\n", " v2e_table,\n", @@ -143,12 +141,20 @@ "\n", " v2e_connectivity = gtx.NeighborTableOffsetProvider(v2e_table, V, E, 6, has_skip_values=False)\n", "\n", - " curl_gt4py = gtx.zeros(vertex_domain, allocator=backend) \n", + " curl_gt4py = gtx.zeros(vertex_domain, allocator=backend)\n", "\n", " curl(\n", - " u, v, nx, ny, dualL, dualA, edge_orientation, out = curl_gt4py, offset_provider = {V2E.value: v2e_connectivity}\n", + " u,\n", + " v,\n", + " nx,\n", + " ny,\n", + " dualL,\n", + " dualA,\n", + " edge_orientation,\n", + " out=curl_gt4py,\n", + " offset_provider={V2E.value: v2e_connectivity},\n", " )\n", - " \n", + "\n", " assert np.allclose(curl_gt4py.asnumpy(), divergence_ref)" ] }, diff --git a/docs/user/next/workshop/exercises/5_vector_laplace_exercise.ipynb b/docs/user/next/workshop/exercises/5_vector_laplace_exercise.ipynb index b976b214c3..832375a86b 100644 --- a/docs/user/next/workshop/exercises/5_vector_laplace_exercise.ipynb +++ b/docs/user/next/workshop/exercises/5_vector_laplace_exercise.ipynb @@ -79,12 +79,7 @@ " A: np.array,\n", " edge_orientation: np.array,\n", ") -> np.array:\n", - " uv_div = (\n", - " np.sum(\n", - " (u[c2e] * nx[c2e] + v[c2e] * ny[c2e]) * L[c2e] * edge_orientation, axis=1\n", - " )\n", - " / A\n", - " )\n", + " uv_div = np.sum((u[c2e] * nx[c2e] + v[c2e] * ny[c2e]) * L[c2e] * edge_orientation, axis=1) / A\n", " return uv_div" ] }, @@ -140,22 +135,22 @@ " edge_orientation_vertex: np.array,\n", " edge_orientation_cell: np.array,\n", ") -> np.array:\n", - " # compute curl (on vertices)\n", - " uv_curl = curl_numpy(v2e, u, v, nx, ny, dualL, dualA, edge_orientation_vertex)\n", + " # compute curl (on vertices)\n", + " uv_curl = curl_numpy(v2e, u, v, nx, ny, dualL, dualA, edge_orientation_vertex)\n", "\n", - " # compute divergence (on cells)\n", - " uv_div = divergence_numpy(c2e, u, v, nx, ny, L, A, edge_orientation_cell)\n", - " \n", - " # first term of of nabla2 (gradient of curl)\n", - " grad_of_curl = (uv_curl[e2v[:, 1]] - uv_curl[e2v[:, 0]])*tangent_orientation/L\n", + " # compute divergence (on cells)\n", + " uv_div = divergence_numpy(c2e, u, v, nx, ny, L, A, edge_orientation_cell)\n", "\n", - " # second term of of nabla2 (gradient of divergence)\n", - " grad_of_div = (uv_div[e2c[:, 1]] - uv_div[e2c[:, 0]])/dualL \n", + " # first term of of nabla2 (gradient of curl)\n", + " grad_of_curl = (uv_curl[e2v[:, 1]] - uv_curl[e2v[:, 0]]) * tangent_orientation / L\n", "\n", - " # finalize nabla2 (difference between the two gradients)\n", - " uv_nabla2 = grad_of_div - grad_of_curl\n", + " # second term of of nabla2 (gradient of divergence)\n", + " grad_of_div = (uv_div[e2c[:, 1]] - uv_div[e2c[:, 0]]) / dualL\n", "\n", - " return uv_nabla2" + " # finalize nabla2 (difference between the two gradients)\n", + " uv_nabla2 = grad_of_div - grad_of_curl\n", + "\n", + " return uv_nabla2" ] }, { @@ -177,7 +172,7 @@ ") -> gtx.Field[Dims[C], float]:\n", " # compute divergence\n", " uv_div = A\n", - " \n", + "\n", " return uv_div" ] }, @@ -239,7 +234,6 @@ "outputs": [], "source": [ "def test_laplacian():\n", - "\n", " backend = None\n", " # backend = gtfn_cpu\n", " # backend = gtfn_gpu\n", @@ -248,7 +242,6 @@ " vertex_domain = gtx.domain({V: n_vertices})\n", " cell_domain = gtx.domain({C: n_cells})\n", "\n", - "\n", " u = random_field(edge_domain, allocator=backend)\n", " v = random_field(edge_domain, allocator=backend)\n", " nx = random_field(edge_domain, allocator=backend)\n", @@ -258,12 +251,8 @@ " tangent_orientation = random_field(edge_domain, allocator=backend)\n", " A = random_field(cell_domain, allocator=backend)\n", " dualA = random_field(vertex_domain, allocator=backend)\n", - " edge_orientation_vertex = random_sign(\n", - " gtx.domain({V: n_vertices, V2EDim: 6}), allocator=backend\n", - " )\n", - " edge_orientation_cell = random_sign(\n", - " gtx.domain({C: n_cells, C2EDim: 3}), allocator=backend\n", - " )\n", + " edge_orientation_vertex = random_sign(gtx.domain({V: n_vertices, V2EDim: 6}), allocator=backend)\n", + " edge_orientation_cell = random_sign(gtx.domain({C: n_cells, C2EDim: 3}), allocator=backend)\n", "\n", " laplacian_ref = laplacian_numpy(\n", " c2e_table,\n", @@ -288,7 +277,6 @@ " e2v_connectivity = gtx.NeighborTableOffsetProvider(e2v_table, E, V, 2, has_skip_values=False)\n", " e2c_connectivity = gtx.NeighborTableOffsetProvider(e2c_table, E, C, 2, has_skip_values=False)\n", "\n", - "\n", " laplacian_gt4py = gtx.zeros(edge_domain, allocator=backend)\n", "\n", " laplacian_fvm(\n", @@ -303,14 +291,15 @@ " dualA,\n", " edge_orientation_vertex,\n", " edge_orientation_cell,\n", - " out = laplacian_gt4py,\n", - " offset_provider = {C2E.value: c2e_connectivity,\n", - " V2E.value: v2e_connectivity,\n", - " E2V.value: e2v_connectivity,\n", - " E2C.value: e2c_connectivity,\n", - " },\n", + " out=laplacian_gt4py,\n", + " offset_provider={\n", + " C2E.value: c2e_connectivity,\n", + " V2E.value: v2e_connectivity,\n", + " E2V.value: e2v_connectivity,\n", + " E2C.value: e2c_connectivity,\n", + " },\n", " )\n", - " \n", + "\n", " assert np.allclose(laplacian_gt4py.asnumpy(), laplacian_ref)" ] }, diff --git a/docs/user/next/workshop/exercises/5_vector_laplace_exercise_solution.ipynb b/docs/user/next/workshop/exercises/5_vector_laplace_exercise_solution.ipynb index 927d56d639..be846d199d 100644 --- a/docs/user/next/workshop/exercises/5_vector_laplace_exercise_solution.ipynb +++ b/docs/user/next/workshop/exercises/5_vector_laplace_exercise_solution.ipynb @@ -79,12 +79,7 @@ " A: np.array,\n", " edge_orientation: np.array,\n", ") -> np.array:\n", - " uv_div = (\n", - " np.sum(\n", - " (u[c2e] * nx[c2e] + v[c2e] * ny[c2e]) * L[c2e] * edge_orientation, axis=1\n", - " )\n", - " / A\n", - " )\n", + " uv_div = np.sum((u[c2e] * nx[c2e] + v[c2e] * ny[c2e]) * L[c2e] * edge_orientation, axis=1) / A\n", " return uv_div" ] }, @@ -140,22 +135,22 @@ " edge_orientation_vertex: np.array,\n", " edge_orientation_cell: np.array,\n", ") -> np.array:\n", - " # compute curl (on vertices)\n", - " uv_curl = curl_numpy(v2e, u, v, nx, ny, dualL, dualA, edge_orientation_vertex)\n", + " # compute curl (on vertices)\n", + " uv_curl = curl_numpy(v2e, u, v, nx, ny, dualL, dualA, edge_orientation_vertex)\n", "\n", - " # compute divergence (on cells)\n", - " uv_div = divergence_numpy(c2e, u, v, nx, ny, L, A, edge_orientation_cell)\n", - " \n", - " # first term of of nabla2 (gradient of curl)\n", - " grad_of_curl = (uv_curl[e2v[:, 1]] - uv_curl[e2v[:, 0]])*tangent_orientation/L\n", + " # compute divergence (on cells)\n", + " uv_div = divergence_numpy(c2e, u, v, nx, ny, L, A, edge_orientation_cell)\n", "\n", - " # second term of of nabla2 (gradient of divergence)\n", - " grad_of_div = (uv_div[e2c[:, 1]] - uv_div[e2c[:, 0]])/dualL \n", + " # first term of of nabla2 (gradient of curl)\n", + " grad_of_curl = (uv_curl[e2v[:, 1]] - uv_curl[e2v[:, 0]]) * tangent_orientation / L\n", + "\n", + " # second term of of nabla2 (gradient of divergence)\n", + " grad_of_div = (uv_div[e2c[:, 1]] - uv_div[e2c[:, 0]]) / dualL\n", "\n", - " # finalize nabla2 (difference between the two gradients)\n", - " uv_nabla2 = grad_of_div - grad_of_curl\n", + " # finalize nabla2 (difference between the two gradients)\n", + " uv_nabla2 = grad_of_div - grad_of_curl\n", "\n", - " return uv_nabla2" + " return uv_nabla2" ] }, { @@ -234,18 +229,17 @@ " edge_orientation_vertex: gtx.Field[Dims[V, V2EDim], float],\n", " edge_orientation_cell: gtx.Field[Dims[C, C2EDim], float],\n", ") -> gtx.Field[Dims[E], float]:\n", - " \n", " # compute curl (on vertices)\n", " uv_curl = curl(u, v, nx, ny, dualL, dualA, edge_orientation_vertex)\n", "\n", " # compute divergence (on cells)\n", " uv_div = divergence(u, v, nx, ny, L, A, edge_orientation_cell)\n", - " \n", + "\n", " # first term of of nabla2 (gradient of curl)\n", - " grad_of_curl = (uv_curl(E2V[1]) - uv_curl(E2V[0]))*tangent_orientation/L\n", + " grad_of_curl = (uv_curl(E2V[1]) - uv_curl(E2V[0])) * tangent_orientation / L\n", "\n", " # second term of of nabla2 (gradient of divergence)\n", - " grad_of_div = (uv_div(E2C[1]) - uv_div(E2C[0]))/dualL \n", + " grad_of_div = (uv_div(E2C[1]) - uv_div(E2C[0])) / dualL\n", "\n", " # finalize nabla2 (difference between the two gradients)\n", " uv_nabla2 = grad_of_div - grad_of_curl\n", @@ -261,7 +255,6 @@ "outputs": [], "source": [ "def test_laplacian():\n", - "\n", " backend = None\n", " # backend = gtfn_cpu\n", " # backend = gtfn_gpu\n", @@ -270,7 +263,6 @@ " vertex_domain = gtx.domain({V: n_vertices})\n", " cell_domain = gtx.domain({C: n_cells})\n", "\n", - "\n", " u = random_field(edge_domain, allocator=backend)\n", " v = random_field(edge_domain, allocator=backend)\n", " nx = random_field(edge_domain, allocator=backend)\n", @@ -280,12 +272,8 @@ " tangent_orientation = random_field(edge_domain, allocator=backend)\n", " A = random_field(cell_domain, allocator=backend)\n", " dualA = random_field(vertex_domain, allocator=backend)\n", - " edge_orientation_vertex = random_sign(\n", - " gtx.domain({V: n_vertices, V2EDim: 6}), allocator=backend\n", - " )\n", - " edge_orientation_cell = random_sign(\n", - " gtx.domain({C: n_cells, C2EDim: 3}), allocator=backend\n", - " )\n", + " edge_orientation_vertex = random_sign(gtx.domain({V: n_vertices, V2EDim: 6}), allocator=backend)\n", + " edge_orientation_cell = random_sign(gtx.domain({C: n_cells, C2EDim: 3}), allocator=backend)\n", "\n", " laplacian_ref = laplacian_numpy(\n", " c2e_table,\n", @@ -310,7 +298,6 @@ " e2v_connectivity = gtx.NeighborTableOffsetProvider(e2v_table, E, V, 2, has_skip_values=False)\n", " e2c_connectivity = gtx.NeighborTableOffsetProvider(e2c_table, E, C, 2, has_skip_values=False)\n", "\n", - "\n", " laplacian_gt4py = gtx.zeros(edge_domain, allocator=backend)\n", "\n", " laplacian_fvm(\n", @@ -325,14 +312,15 @@ " dualA,\n", " edge_orientation_vertex,\n", " edge_orientation_cell,\n", - " out = laplacian_gt4py,\n", - " offset_provider = {C2E.value: c2e_connectivity,\n", - " V2E.value: v2e_connectivity,\n", - " E2V.value: e2v_connectivity,\n", - " E2C.value: e2c_connectivity,\n", - " },\n", + " out=laplacian_gt4py,\n", + " offset_provider={\n", + " C2E.value: c2e_connectivity,\n", + " V2E.value: v2e_connectivity,\n", + " E2V.value: e2v_connectivity,\n", + " E2C.value: e2c_connectivity,\n", + " },\n", " )\n", - " \n", + "\n", " assert np.allclose(laplacian_gt4py.asnumpy(), laplacian_ref)" ] }, diff --git a/docs/user/next/workshop/exercises/6_where_domain.ipynb b/docs/user/next/workshop/exercises/6_where_domain.ipynb index c23e8c121a..3c50da2245 100644 --- a/docs/user/next/workshop/exercises/6_where_domain.ipynb +++ b/docs/user/next/workshop/exercises/6_where_domain.ipynb @@ -84,7 +84,7 @@ ], "source": [ "a_np = np.arange(10.0)\n", - "b_np = np.where(a_np < 6.0, a_np, a_np*10.0)\n", + "b_np = np.where(a_np < 6.0, a_np, a_np * 10.0)\n", "print(\"a_np array: {}\".format(a_np))\n", "print(\"b_np array: {}\".format(b_np))" ] @@ -153,7 +153,7 @@ " a = gtx.as_field([K], np.arange(10.0), allocator=backend)\n", " b = gtx.as_field([K], np.zeros(shape=10), allocator=backend)\n", " program_where(a, b, offset_provider={})\n", - " \n", + "\n", " assert np.allclose(b_np, b.asnumpy())" ] }, @@ -236,8 +236,9 @@ "\n", "\n", "@gtx.program(backend=backend)\n", - "def program_domain(a: gtx.Field[Dims[K], float], b: gtx.Field[Dims[K], float]):\n", - " ... # TODO write the call to fieldop_domain" + "def program_domain(\n", + " a: gtx.Field[Dims[K], float], b: gtx.Field[Dims[K], float]\n", + "): ... # TODO write the call to fieldop_domain" ] }, { @@ -366,11 +367,11 @@ "source": [ "@gtx.field_operator\n", "def fieldop_domain_where(a: gtx.Field[Dims[K], float]) -> gtx.Field[Dims[K], float]:\n", - " return # TODO\n", + " return # TODO\n", + "\n", "\n", "@gtx.program(backend=backend)\n", - "def program_domain_where(a: gtx.Field[Dims[K], float], b: gtx.Field[Dims[K], float]):\n", - " ... # TODO " + "def program_domain_where(a: gtx.Field[Dims[K], float], b: gtx.Field[Dims[K], float]): ... # TODO" ] }, { @@ -380,11 +381,11 @@ "metadata": {}, "outputs": [], "source": [ - "def test_domain_where(): \n", + "def test_domain_where():\n", " a = gtx.as_field([K], np.arange(10.0), allocator=backend)\n", " b = gtx.as_field([K], np.zeros(shape=10), allocator=backend)\n", " program_domain_where(a, b, offset_provider={\"Koff\": K})\n", - " \n", + "\n", " assert np.allclose(a_np_result, b.asnumpy())" ] }, diff --git a/docs/user/next/workshop/exercises/6_where_domain_solutions.ipynb b/docs/user/next/workshop/exercises/6_where_domain_solutions.ipynb index f42701473c..790e0d6cae 100644 --- a/docs/user/next/workshop/exercises/6_where_domain_solutions.ipynb +++ b/docs/user/next/workshop/exercises/6_where_domain_solutions.ipynb @@ -84,7 +84,7 @@ ], "source": [ "a_np = np.arange(10.0)\n", - "b_np = np.where(a_np < 6.0, a_np, a_np*10.0)\n", + "b_np = np.where(a_np < 6.0, a_np, a_np * 10.0)\n", "print(\"a_np array: {}\".format(a_np))\n", "print(\"b_np array: {}\".format(b_np))" ] @@ -106,11 +106,12 @@ "source": [ "@gtx.field_operator\n", "def fieldop_where(a: gtx.Field[Dims[K], float]) -> gtx.Field[Dims[K], float]:\n", - " return where(a < 6.0, a, a*10.0)\n", + " return where(a < 6.0, a, a * 10.0)\n", + "\n", "\n", "@gtx.program(backend=backend)\n", "def program_where(a: gtx.Field[Dims[K], float], b: gtx.Field[Dims[K], float]):\n", - " fieldop_where(a, out=b) " + " fieldop_where(a, out=b)" ] }, { @@ -124,7 +125,7 @@ " a = gtx.as_field([K], np.arange(10.0), allocator=backend)\n", " b = gtx.as_field([K], np.zeros(shape=10), allocator=backend)\n", " program_where(a, b, offset_provider={})\n", - " \n", + "\n", " assert np.allclose(b_np, b.asnumpy())" ] }, @@ -182,12 +183,12 @@ "source": [ "@gtx.field_operator\n", "def fieldop_domain(a: gtx.Field[Dims[K], float]) -> gtx.Field[Dims[K], float]:\n", - " return a*10.0\n", + " return a * 10.0\n", + "\n", "\n", "@gtx.program(backend=backend)\n", - "def program_domain(a: gtx.Field[Dims[K], float],\n", - " b: gtx.Field[Dims[K], float]):\n", - " fieldop_domain(a, out=b, domain={K: (6, 10)}) " + "def program_domain(a: gtx.Field[Dims[K], float], b: gtx.Field[Dims[K], float]):\n", + " fieldop_domain(a, out=b, domain={K: (6, 10)})" ] }, { @@ -297,11 +298,12 @@ "source": [ "@gtx.field_operator\n", "def fieldop_domain_where(a: gtx.Field[Dims[K], float]) -> gtx.Field[Dims[K], float]:\n", - " return where(a<8.0, a(Koff[1])+a, a)\n", + " return where(a < 8.0, a(Koff[1]) + a, a)\n", + "\n", "\n", "@gtx.program(backend=backend)\n", "def program_domain_where(a: gtx.Field[Dims[K], float], b: gtx.Field[Dims[K], float]):\n", - " fieldop_domain_where(a, out=b, domain={K: (0, 9)}) " + " fieldop_domain_where(a, out=b, domain={K: (0, 9)})" ] }, { @@ -311,11 +313,11 @@ "metadata": {}, "outputs": [], "source": [ - "def test_domain_where(): \n", + "def test_domain_where():\n", " a = gtx.as_field([K], np.arange(10.0), allocator=backend)\n", " b = gtx.as_field([K], np.zeros(shape=10), allocator=backend)\n", " program_domain_where(a, b, offset_provider={\"Koff\": K})\n", - " \n", + "\n", " assert np.allclose(a_np_result, b.asnumpy())" ] }, diff --git a/docs/user/next/workshop/exercises/7_scan_operator.ipynb b/docs/user/next/workshop/exercises/7_scan_operator.ipynb index 90982c352d..626fd4ecd9 100644 --- a/docs/user/next/workshop/exercises/7_scan_operator.ipynb +++ b/docs/user/next/workshop/exercises/7_scan_operator.ipynb @@ -183,17 +183,17 @@ "\n", " # unpack state of previous iteration\n", " # TODO\n", - " \n", + "\n", " # Autoconversion: Cloud Drops -> Rain Drops\n", " # TODO\n", - " \n", + "\n", " ## Add sedimentation flux from level above\n", " # TODO\n", "\n", " # Remove mass due to sedimentation flux\n", " # TODO\n", "\n", - " return # TODO" + " return # TODO" ] }, { @@ -243,10 +243,7 @@ "@gtx.field_operator(backend=backend)\n", "def graupel_toy_scan(\n", " qc: gtx.Field[Dims[C, K], float], qr: gtx.Field[Dims[C, K], float]\n", - ") -> tuple[\n", - " gtx.Field[Dims[C, K], float],\n", - " gtx.Field[Dims[C, K], float]\n", - "]:\n", + ") -> tuple[gtx.Field[Dims[C, K], float], gtx.Field[Dims[C, K], float]]:\n", " qc, qr, _ = _graupel_toy_scan(qc, qr)\n", "\n", " return qc, qr" @@ -261,7 +258,7 @@ "source": [ "def test_scan_operator():\n", " cell_k_domain = gtx.domain({C: n_cells, K: n_levels})\n", - " \n", + "\n", " qc = random_field(cell_k_domain, allocator=backend)\n", " qr = random_field(cell_k_domain, allocator=backend)\n", "\n", diff --git a/docs/user/next/workshop/exercises/7_scan_operator_solutions.ipynb b/docs/user/next/workshop/exercises/7_scan_operator_solutions.ipynb index e7831f3687..335c26a2a2 100644 --- a/docs/user/next/workshop/exercises/7_scan_operator_solutions.ipynb +++ b/docs/user/next/workshop/exercises/7_scan_operator_solutions.ipynb @@ -187,10 +187,7 @@ "@gtx.field_operator(backend=backend)\n", "def graupel_toy_scan(\n", " qc: gtx.Field[Dims[C, K], float], qr: gtx.Field[Dims[C, K], float]\n", - ") -> tuple[\n", - " gtx.Field[Dims[C, K], float],\n", - " gtx.Field[Dims[C, K], float]\n", - "]:\n", + ") -> tuple[gtx.Field[Dims[C, K], float], gtx.Field[Dims[C, K], float]]:\n", " qc, qr, _ = _graupel_toy_scan(qc, qr)\n", "\n", " return qc, qr" @@ -205,7 +202,7 @@ "source": [ "def test_scan_operator():\n", " cell_k_domain = gtx.domain({C: n_cells, K: n_levels})\n", - " \n", + "\n", " qc = random_field(cell_k_domain, allocator=backend)\n", " qr = random_field(cell_k_domain, allocator=backend)\n", "\n", diff --git a/docs/user/next/workshop/exercises/8_diffusion_exercise_solution.ipynb b/docs/user/next/workshop/exercises/8_diffusion_exercise_solution.ipynb index e12c51973a..d4bcdb33d5 100644 --- a/docs/user/next/workshop/exercises/8_diffusion_exercise_solution.ipynb +++ b/docs/user/next/workshop/exercises/8_diffusion_exercise_solution.ipynb @@ -31,39 +31,36 @@ " kappa: float,\n", " dt: float,\n", ") -> tuple[np.array, np.array]:\n", - "\n", " # initialize\n", " TEinit = TE\n", " inv_primal_edge_length = inv_primal_edge_length[:, np.newaxis]\n", " inv_vert_vert_length = inv_vert_vert_length[:, np.newaxis]\n", "\n", " # predict\n", - " TE = TEinit + 0.5*dt*TE_t\n", + " TE = TEinit + 0.5 * dt * TE_t\n", "\n", " # interpolate temperature from edges to vertices\n", " TV = np.sum(TE[v2e], axis=1) / nnbhV\n", "\n", " # compute nabla2 using the finite differences\n", " TEnabla2 = np.sum(\n", - " TV[e2c2v] * inv_primal_edge_length ** 2\n", - " + TV[e2c2v] * inv_vert_vert_length ** 2,\n", + " TV[e2c2v] * inv_primal_edge_length**2 + TV[e2c2v] * inv_vert_vert_length**2,\n", " axis=1,\n", " )\n", "\n", " TEnabla2 = TEnabla2 - (\n", - " (2.0 * TE * inv_primal_edge_length ** 2)\n", - " + (2.0 * TE * inv_vert_vert_length ** 2)\n", + " (2.0 * TE * inv_primal_edge_length**2) + (2.0 * TE * inv_vert_vert_length**2)\n", " )\n", "\n", " # build ODEs\n", " TE_t = np.where(\n", " boundary_edge,\n", - " 0.,\n", - " kappa*TEnabla2,\n", + " 0.0,\n", + " kappa * TEnabla2,\n", " )\n", "\n", " # correct\n", - " TE = TEinit + dt*TE_t\n", + " TE = TEinit + dt * TE_t\n", " return TE_t, TE" ] }, @@ -88,38 +85,34 @@ " gtx.Field[Dims[E], float],\n", " gtx.Field[Dims[E], float],\n", "]:\n", - "\n", " # initialize\n", " TEinit = TE\n", "\n", " # predict\n", - " TE = TEinit + 0.5*dt*TE_t\n", + " TE = TEinit + 0.5 * dt * TE_t\n", "\n", " # interpolate temperature from edges to vertices\n", " TV = neighbor_sum(TE(V2E), axis=V2EDim) / nnbhV\n", "\n", " # compute nabla2 using the finite differences\n", " TEnabla2 = neighbor_sum(\n", - " (TV(E2C2V) * inv_primal_edge_length ** 2\n", - " + TV(E2C2V) * inv_vert_vert_length ** 2),\n", - " axis=E2C2VDim\n", + " (TV(E2C2V) * inv_primal_edge_length**2 + TV(E2C2V) * inv_vert_vert_length**2), axis=E2C2VDim\n", " )\n", "\n", " TEnabla2 = TEnabla2 - (\n", - " (2.0 * TE * inv_primal_edge_length ** 2)\n", - " + (2.0 * TE * inv_vert_vert_length ** 2)\n", + " (2.0 * TE * inv_primal_edge_length**2) + (2.0 * TE * inv_vert_vert_length**2)\n", " )\n", "\n", " # build ODEs\n", " TE_t = where(\n", " boundary_edge,\n", - " 0.,\n", - " kappa*TEnabla2,\n", + " 0.0,\n", + " kappa * TEnabla2,\n", " )\n", "\n", " # correct\n", - " TE = TEinit + dt*TE_t\n", - " \n", + " TE = TEinit + dt * TE_t\n", + "\n", " return TE_t, TE" ] }, @@ -134,23 +127,23 @@ " backend = None\n", " # backend = gtfn_cpu\n", " # backend = gtfn_gpu\n", - " \n", + "\n", " cell_domain = gtx.domain({C: n_cells})\n", " edge_domain = gtx.domain({E: n_edges})\n", " vertex_domain = gtx.domain({V: n_vertices})\n", - " \n", + "\n", " u = random_field(edge_domain, allocator=backend)\n", " v = random_field(edge_domain, allocator=backend)\n", " nx = random_field(edge_domain, allocator=backend)\n", " ny = random_field(edge_domain, allocator=backend)\n", " L = random_field(edge_domain, allocator=backend)\n", " dualL = random_field(vertex_domain, allocator=backend)\n", - " divergence_gt4py_1 = gtx.zeros(edge_domain, allocator=backend)\n", - " divergence_gt4py_2 = gtx.zeros(edge_domain, allocator=backend)\n", + " divergence_gt4py_1 = gtx.zeros(edge_domain, allocator=backend)\n", + " divergence_gt4py_2 = gtx.zeros(edge_domain, allocator=backend)\n", " kappa = 1.0\n", " dt = 1.0\n", "\n", - " divergence_ref_1, divergence_ref_2 = diffusion_step_numpy( \n", + " divergence_ref_1, divergence_ref_2 = diffusion_step_numpy(\n", " e2c2v_table,\n", " v2e_table,\n", " u.asnumpy(),\n", @@ -160,16 +153,27 @@ " dualL.asnumpy(),\n", " L.asnumpy(),\n", " kappa,\n", - " dt\n", + " dt,\n", " )\n", "\n", - " e2c2v_connectivity = gtx.NeighborTableOffsetProvider(e2c2v_table, E, V, 4, has_skip_values=False)\n", + " e2c2v_connectivity = gtx.NeighborTableOffsetProvider(\n", + " e2c2v_table, E, V, 4, has_skip_values=False\n", + " )\n", " v2e_connectivity = gtx.NeighborTableOffsetProvider(v2e_table, V, E, 6, has_skip_values=False)\n", "\n", " diffusion_step(\n", - " u, v, nx, ny, dualL, L, kappa, dt, out=(divergence_gt4py_1, divergence_gt4py_2), offset_provider = {E2C2V.value: e2c2v_connectivity, V2E.value: v2e_connectivity}\n", + " u,\n", + " v,\n", + " nx,\n", + " ny,\n", + " dualL,\n", + " L,\n", + " kappa,\n", + " dt,\n", + " out=(divergence_gt4py_1, divergence_gt4py_2),\n", + " offset_provider={E2C2V.value: e2c2v_connectivity, V2E.value: v2e_connectivity},\n", " )\n", - " \n", + "\n", " assert np.allclose(divergence_gt4py_1.asnumpy(), divergence_ref_1)\n", " assert np.allclose(divergence_gt4py_2.asnumpy(), divergence_ref_2)" ] diff --git a/docs/user/next/workshop/jupyter_intro.ipynb b/docs/user/next/workshop/jupyter_intro.ipynb index c1100223a1..e63b750b67 100644 --- a/docs/user/next/workshop/jupyter_intro.ipynb +++ b/docs/user/next/workshop/jupyter_intro.ipynb @@ -73,7 +73,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(\"\".join(map(lambda c: chr(ord(c) - 2), \"Kv\\\"yqtmgf#\")))" + "print(\"\".join(map(lambda c: chr(ord(c) - 2), 'Kv\"yqtmgf#')))" ] }, { diff --git a/docs/user/next/workshop/slides/slides_1.ipynb b/docs/user/next/workshop/slides/slides_1.ipynb index ff3ca764e4..f1e0229d4f 100644 --- a/docs/user/next/workshop/slides/slides_1.ipynb +++ b/docs/user/next/workshop/slides/slides_1.ipynb @@ -96,7 +96,8 @@ "outputs": [], "source": [ "import warnings\n", - "warnings.filterwarnings('ignore')" + "\n", + "warnings.filterwarnings(\"ignore\")" ] }, { @@ -213,7 +214,7 @@ "\n", "a = gtx.zeros(domain, dtype=float64)\n", "b = gtx.full(domain, fill_value=3.0, dtype=float64)\n", - "c = gtx.as_field([Cell, K], np.fromfunction(lambda c, k: c*10+k, shape=domain.shape))\n", + "c = gtx.as_field([Cell, K], np.fromfunction(lambda c, k: c * 10 + k, shape=domain.shape))\n", "\n", "print(\"a definition: \\n {}\".format(a))\n", "print(\"a array: \\n {}\".format(a.asnumpy()))\n", @@ -241,8 +242,9 @@ "outputs": [], "source": [ "@gtx.field_operator\n", - "def add(a: gtx.Field[Dims[Cell, K], float64],\n", - " b: gtx.Field[Dims[Cell, K], float64]) -> gtx.Field[Dims[Cell, K], float64]:\n", + "def add(\n", + " a: gtx.Field[Dims[Cell, K], float64], b: gtx.Field[Dims[Cell, K], float64]\n", + ") -> gtx.Field[Dims[Cell, K], float64]:\n", " return a + b" ] }, @@ -311,9 +313,11 @@ "outputs": [], "source": [ "@gtx.program\n", - "def run_add(a : gtx.Field[Dims[Cell, K], float64],\n", - " b : gtx.Field[Dims[Cell, K], float64],\n", - " result : gtx.Field[Dims[Cell, K], float64]):\n", + "def run_add(\n", + " a: gtx.Field[Dims[Cell, K], float64],\n", + " b: gtx.Field[Dims[Cell, K], float64],\n", + " result: gtx.Field[Dims[Cell, K], float64],\n", + "):\n", " add(a, b, out=result)\n", " add(b, result, out=result)" ] diff --git a/docs/user/next/workshop/slides/slides_2.ipynb b/docs/user/next/workshop/slides/slides_2.ipynb index 903182b7bc..1e8925087f 100644 --- a/docs/user/next/workshop/slides/slides_2.ipynb +++ b/docs/user/next/workshop/slides/slides_2.ipynb @@ -17,7 +17,8 @@ "outputs": [], "source": [ "import warnings\n", - "warnings.filterwarnings('ignore')" + "\n", + "warnings.filterwarnings(\"ignore\")" ] }, { @@ -122,10 +123,12 @@ "source": [ "Koff = gtx.FieldOffset(\"Koff\", source=K, target=(K,))\n", "\n", + "\n", "@gtx.field_operator\n", "def a_offset(a_off: gtx.Field[Dims[K], float64]) -> gtx.Field[Dims[K], float64]:\n", " return a_off(Koff[1])\n", "\n", + "\n", "result = gtx.zeros(gtx.domain({K: 6}))\n", "\n", "a_offset(a_off, out=result[:-1], offset_provider={\"Koff\": K})\n", @@ -177,29 +180,33 @@ "metadata": {}, "outputs": [], "source": [ - "e2c_table = np.array([\n", - " [0, -1], # edge 0 (neighbours: cell 0)\n", - " [2, -1], # edge 1\n", - " [2, -1], # edge 2\n", - " [3, -1], # edge 3\n", - " [4, -1], # edge 4\n", - " [5, -1], # edge 5\n", - " [0, 5], # edge 6 (neighbours: cell 0, cell 5)\n", - " [0, 1], # edge 7\n", - " [1, 2], # edge 8\n", - " [1, 3], # edge 9\n", - " [3, 4], # edge 10\n", - " [4, 5] # edge 11\n", - "])\n", - "\n", - "c2e_table = np.array([\n", - " [0, 6, 7], # cell 0 (neighbors: edge 0, edge 6, edge 7)\n", - " [7, 8, 9], # cell 1\n", - " [1, 2, 8], # cell 2\n", - " [3, 9, 10], # cell 3\n", - " [4, 10, 11], # cell 4\n", - " [5, 6, 11], # cell 5\n", - "])" + "e2c_table = np.array(\n", + " [\n", + " [0, -1], # edge 0 (neighbours: cell 0)\n", + " [2, -1], # edge 1\n", + " [2, -1], # edge 2\n", + " [3, -1], # edge 3\n", + " [4, -1], # edge 4\n", + " [5, -1], # edge 5\n", + " [0, 5], # edge 6 (neighbours: cell 0, cell 5)\n", + " [0, 1], # edge 7\n", + " [1, 2], # edge 8\n", + " [1, 3], # edge 9\n", + " [3, 4], # edge 10\n", + " [4, 5], # edge 11\n", + " ]\n", + ")\n", + "\n", + "c2e_table = np.array(\n", + " [\n", + " [0, 6, 7], # cell 0 (neighbors: edge 0, edge 6, edge 7)\n", + " [7, 8, 9], # cell 1\n", + " [1, 2, 8], # cell 2\n", + " [3, 9, 10], # cell 3\n", + " [4, 10, 11], # cell 4\n", + " [5, 6, 11], # cell 5\n", + " ]\n", + ")" ] }, { @@ -298,13 +305,19 @@ ], "source": [ "@gtx.field_operator\n", - "def nearest_cell_to_edge(cell_field: gtx.Field[Dims[Cell], float64]) -> gtx.Field[Dims[Edge], float64]:\n", - " return cell_field(E2C[0]) # 0th index to isolate edge dimension\n", + "def nearest_cell_to_edge(\n", + " cell_field: gtx.Field[Dims[Cell], float64],\n", + ") -> gtx.Field[Dims[Edge], float64]:\n", + " return cell_field(E2C[0]) # 0th index to isolate edge dimension\n", "\n", - "@gtx.program # uses skip_values, therefore we cannot use embedded\n", - "def run_nearest_cell_to_edge(cell_field: gtx.Field[Dims[Cell], float64], edge_field: gtx.Field[Dims[Edge], float64]):\n", + "\n", + "@gtx.program # uses skip_values, therefore we cannot use embedded\n", + "def run_nearest_cell_to_edge(\n", + " cell_field: gtx.Field[Dims[Cell], float64], edge_field: gtx.Field[Dims[Edge], float64]\n", + "):\n", " nearest_cell_to_edge(cell_field, out=edge_field)\n", "\n", + "\n", "run_nearest_cell_to_edge(cell_field, edge_field, offset_provider={\"E2C\": E2C_offset_provider})\n", "\n", "print(\"0th adjacent cell's value: {}\".format(edge_field.asnumpy()))" @@ -367,13 +380,19 @@ ], "source": [ "@gtx.field_operator\n", - "def sum_adjacent_cells(cell_field : gtx.Field[Dims[Cell], float64]) -> gtx.Field[Dims[Edge], float64]:\n", + "def sum_adjacent_cells(\n", + " cell_field: gtx.Field[Dims[Cell], float64],\n", + ") -> gtx.Field[Dims[Edge], float64]:\n", " return neighbor_sum(cell_field(E2C), axis=E2CDim)\n", "\n", - "@gtx.program # uses skip_values, therefore we cannot use embedded\n", - "def run_sum_adjacent_cells(cell_field : gtx.Field[Dims[Cell], float64], edge_field: gtx.Field[Dims[Edge], float64]):\n", + "\n", + "@gtx.program # uses skip_values, therefore we cannot use embedded\n", + "def run_sum_adjacent_cells(\n", + " cell_field: gtx.Field[Dims[Cell], float64], edge_field: gtx.Field[Dims[Edge], float64]\n", + "):\n", " sum_adjacent_cells(cell_field, out=edge_field)\n", "\n", + "\n", "run_sum_adjacent_cells(cell_field, edge_field, offset_provider={\"E2C\": E2C_offset_provider})\n", "\n", "print(\"sum of adjacent cells: {}\".format(edge_field.asnumpy()))" diff --git a/docs/user/next/workshop/slides/slides_3.ipynb b/docs/user/next/workshop/slides/slides_3.ipynb index 362a169322..bd85f5027b 100644 --- a/docs/user/next/workshop/slides/slides_3.ipynb +++ b/docs/user/next/workshop/slides/slides_3.ipynb @@ -17,7 +17,8 @@ "outputs": [], "source": [ "import warnings\n", - "warnings.filterwarnings('ignore')" + "\n", + "warnings.filterwarnings(\"ignore\")" ] }, { @@ -95,13 +96,18 @@ "true_Field = gtx.as_field([Cell], np.asarray([11.0, 12.0, 13.0, 14.0, 15.0]))\n", "false_Field = gtx.as_field([Cell], np.asarray([21.0, 22.0, 23.0, 24.0, 25.0]))\n", "\n", - "result = gtx.zeros(gtx.domain({Cell:5}))\n", + "result = gtx.zeros(gtx.domain({Cell: 5}))\n", + "\n", "\n", "@gtx.field_operator\n", - "def conditional(mask: gtx.Field[Dims[Cell], bool], true_Field: gtx.Field[Dims[Cell], gtx.float64], false_Field: gtx.Field[Dims[Cell], gtx.float64]\n", + "def conditional(\n", + " mask: gtx.Field[Dims[Cell], bool],\n", + " true_Field: gtx.Field[Dims[Cell], gtx.float64],\n", + " false_Field: gtx.Field[Dims[Cell], gtx.float64],\n", ") -> gtx.Field[Dims[Cell], gtx.float64]:\n", " return where(mask, true_Field, false_Field)\n", "\n", + "\n", "conditional(mask, true_Field, false_Field, out=result, offset_provider={})\n", "print(\"mask array: {}\".format(mask.asnumpy()))\n", "print(\"true_Field array: {}\".format(true_Field.asnumpy()))\n", @@ -127,15 +133,19 @@ "outputs": [], "source": [ "@gtx.field_operator\n", - "def add(a: gtx.Field[Dims[Cell, K], gtx.float64],\n", - " b: gtx.Field[Dims[Cell, K], gtx.float64]) -> gtx.Field[Dims[Cell, K], gtx.float64]:\n", - " return a + b # 2.0 + 3.0\n", + "def add(\n", + " a: gtx.Field[Dims[Cell, K], gtx.float64], b: gtx.Field[Dims[Cell, K], gtx.float64]\n", + ") -> gtx.Field[Dims[Cell, K], gtx.float64]:\n", + " return a + b # 2.0 + 3.0\n", + "\n", "\n", "@gtx.program\n", - "def run_add_domain(a : gtx.Field[Dims[Cell, K], gtx.float64],\n", - " b : gtx.Field[Dims[Cell, K], gtx.float64],\n", - " result : gtx.Field[Dims[Cell, K], gtx.float64]):\n", - " add(a, b, out=result, domain={Cell: (1, 3), K: (1, 4)}) " + "def run_add_domain(\n", + " a: gtx.Field[Dims[Cell, K], gtx.float64],\n", + " b: gtx.Field[Dims[Cell, K], gtx.float64],\n", + " result: gtx.Field[Dims[Cell, K], gtx.float64],\n", + "):\n", + " add(a, b, out=result, domain={Cell: (1, 3), K: (1, 4)})" ] }, { diff --git a/docs/user/next/workshop/slides/slides_4.ipynb b/docs/user/next/workshop/slides/slides_4.ipynb index 324e30fe29..a5b8aaf78f 100644 --- a/docs/user/next/workshop/slides/slides_4.ipynb +++ b/docs/user/next/workshop/slides/slides_4.ipynb @@ -17,7 +17,8 @@ "outputs": [], "source": [ "import warnings\n", - "warnings.filterwarnings('ignore')" + "\n", + "warnings.filterwarnings(\"ignore\")" ] }, { @@ -85,12 +86,16 @@ ], "source": [ "x = np.asarray([1.0, 2.0, 4.0, 6.0, 0.0, 2.0, 5.0])\n", + "\n", + "\n", "def partial_sum(x):\n", " for i in range(len(x)):\n", " if i > 0:\n", - " x[i] = x[i-1] + x[i]\n", + " x[i] = x[i - 1] + x[i]\n", " return x\n", - "print(f\"input:\\n {x}\") \n", + "\n", + "\n", + "print(f\"input:\\n {x}\")\n", "print(f\"partial sum:\\n {partial_sum(x)}\")" ] }, diff --git a/examples/cartesian/demo_burgers.ipynb b/examples/cartesian/demo_burgers.ipynb index 5e1a698cad..3521a845ea 100644 --- a/examples/cartesian/demo_burgers.ipynb +++ b/examples/cartesian/demo_burgers.ipynb @@ -103,8 +103,8 @@ "ny = 10 * 2**factor + 1\n", "\n", "# time\n", - "cfl = 1.\n", - "timestep = cfl / (nx-1)**2\n", + "cfl = 1.0\n", + "timestep = cfl / (nx - 1) ** 2\n", "niter = 4**factor * 100\n", "\n", "# output\n", @@ -127,84 +127,90 @@ "source": [ "@gtscript.function\n", "def absolute_value(phi):\n", - " abs_phi = phi[0, 0, 0] * (phi[0, 0, 0] >= 0.) - phi[0, 0, 0] * (phi[0, 0, 0] < 0.)\n", + " abs_phi = phi[0, 0, 0] * (phi[0, 0, 0] >= 0.0) - phi[0, 0, 0] * (phi[0, 0, 0] < 0.0)\n", " return abs_phi\n", "\n", + "\n", "@gtscript.function\n", "def advection_x(dx, u, abs_u, phi):\n", - " adv_phi_x = u[0, 0, 0] / (60. * dx) * (\n", - " + 45. * (phi[1, 0, 0] - phi[-1, 0, 0])\n", - " - 9. * (phi[2, 0, 0] - phi[-2, 0, 0])\n", - " + (phi[3, 0, 0] - phi[-3, 0, 0])\n", - " ) - abs_u[0, 0, 0] / (60. * dx) * (\n", - " + (phi[3, 0, 0] + phi[-3, 0, 0])\n", - " - 6. * (phi[2, 0, 0] + phi[-2, 0, 0])\n", - " + 15. * (phi[1, 0, 0] + phi[-1, 0, 0])\n", - " - 20. * phi[0, 0, 0]\n", + " adv_phi_x = u[0, 0, 0] / (60.0 * dx) * (\n", + " +45.0 * (phi[1, 0, 0] - phi[-1, 0, 0])\n", + " - 9.0 * (phi[2, 0, 0] - phi[-2, 0, 0])\n", + " + (phi[3, 0, 0] - phi[-3, 0, 0])\n", + " ) - abs_u[0, 0, 0] / (60.0 * dx) * (\n", + " +(phi[3, 0, 0] + phi[-3, 0, 0])\n", + " - 6.0 * (phi[2, 0, 0] + phi[-2, 0, 0])\n", + " + 15.0 * (phi[1, 0, 0] + phi[-1, 0, 0])\n", + " - 20.0 * phi[0, 0, 0]\n", " )\n", " return adv_phi_x\n", "\n", + "\n", "@gtscript.function\n", "def advection_y(dy, v, abs_v, phi):\n", - " adv_phi_y = v[0, 0, 0] / (60. * dy) * (\n", - " + 45. * (phi[0, 1, 0] - phi[0, -1, 0])\n", - " - 9. * (phi[0, 2, 0] - phi[0, -2, 0])\n", - " + (phi[0, 3, 0] - phi[0, -3, 0])\n", - " ) - abs_v[0, 0, 0] / (60. * dy) * (\n", - " + (phi[0, 3, 0] + phi[0, -3, 0])\n", - " - 6. * (phi[0, 2, 0] + phi[0, -2, 0])\n", - " + 15. * (phi[0, 1, 0] + phi[0, -1, 0])\n", - " - 20. * phi[0, 0, 0]\n", + " adv_phi_y = v[0, 0, 0] / (60.0 * dy) * (\n", + " +45.0 * (phi[0, 1, 0] - phi[0, -1, 0])\n", + " - 9.0 * (phi[0, 2, 0] - phi[0, -2, 0])\n", + " + (phi[0, 3, 0] - phi[0, -3, 0])\n", + " ) - abs_v[0, 0, 0] / (60.0 * dy) * (\n", + " +(phi[0, 3, 0] + phi[0, -3, 0])\n", + " - 6.0 * (phi[0, 2, 0] + phi[0, -2, 0])\n", + " + 15.0 * (phi[0, 1, 0] + phi[0, -1, 0])\n", + " - 20.0 * phi[0, 0, 0]\n", " )\n", " return adv_phi_y\n", "\n", + "\n", "@gtscript.function\n", "def advection(dx, dy, u, v):\n", " abs_u = absolute_value(phi=u)\n", " abs_v = absolute_value(phi=v)\n", - " \n", + "\n", " adv_u_x = advection_x(dx=dx, u=u, abs_u=abs_u, phi=u)\n", " adv_u_y = advection_y(dy=dy, v=v, abs_v=abs_v, phi=u)\n", " adv_u = adv_u_x[0, 0, 0] + adv_u_y[0, 0, 0]\n", - " \n", + "\n", " adv_v_x = advection_x(dx=dx, u=u, abs_u=abs_u, phi=v)\n", " adv_v_y = advection_y(dy=dy, v=v, abs_v=abs_v, phi=v)\n", " adv_v = adv_v_x[0, 0, 0] + adv_v_y[0, 0, 0]\n", - " \n", + "\n", " return adv_u, adv_v\n", "\n", + "\n", "@gtscript.function\n", "def diffusion_x(dx, phi):\n", " diff_phi = (\n", - " - phi[-2, 0, 0]\n", - " + 16. * phi[-1, 0, 0]\n", - " - 30. * phi[0, 0, 0]\n", - " + 16. * phi[1, 0, 0]\n", - " - phi[2, 0, 0]\n", - " ) / (12. * dx**2)\n", + " -phi[-2, 0, 0]\n", + " + 16.0 * phi[-1, 0, 0]\n", + " - 30.0 * phi[0, 0, 0]\n", + " + 16.0 * phi[1, 0, 0]\n", + " - phi[2, 0, 0]\n", + " ) / (12.0 * dx**2)\n", " return diff_phi\n", "\n", + "\n", "@gtscript.function\n", "def diffusion_y(dy, phi):\n", " diff_phi = (\n", - " - phi[0, -2, 0]\n", - " + 16. * phi[0, -1, 0]\n", - " - 30. * phi[0, 0, 0]\n", - " + 16. * phi[0, 1, 0]\n", - " - phi[0, 2, 0]\n", - " ) / (12. * dy**2)\n", + " -phi[0, -2, 0]\n", + " + 16.0 * phi[0, -1, 0]\n", + " - 30.0 * phi[0, 0, 0]\n", + " + 16.0 * phi[0, 1, 0]\n", + " - phi[0, 2, 0]\n", + " ) / (12.0 * dy**2)\n", " return diff_phi\n", "\n", + "\n", "@gtscript.function\n", "def diffusion(dx, dy, u, v):\n", " diff_u_x = diffusion_x(dx=dx, phi=u)\n", " diff_u_y = diffusion_y(dy=dy, phi=u)\n", " diff_u = diff_u_x[0, 0, 0] + diff_u_y[0, 0, 0]\n", - " \n", + "\n", " diff_v_x = diffusion_x(dx=dx, phi=v)\n", " diff_v_y = diffusion_y(dy=dy, phi=v)\n", " diff_v = diff_v_x[0, 0, 0] + diff_v_y[0, 0, 0]\n", - " \n", + "\n", " return diff_u, diff_v" ] }, @@ -232,24 +238,27 @@ ], "source": [ "# gt4py settings\n", - "backend = \"numpy\" # options: \"numpy\", \"gt:cpu_ifirst\", \"gt:cpu_kfirst\", \"gt:gpu\", \"dace:cpu\", \"dace:gpu\"\n", + "backend = (\n", + " \"numpy\" # options: \"numpy\", \"gt:cpu_ifirst\", \"gt:cpu_kfirst\", \"gt:gpu\", \"dace:cpu\", \"dace:gpu\"\n", + ")\n", "backend_opts = {\"verbose\": True} if backend.startswith(\"gt\") else {}\n", "dtype = np.float64\n", "origin = (3, 3, 0)\n", "rebuild = False\n", "\n", - "externals={\n", + "externals = {\n", " \"absolute_value\": absolute_value,\n", " \"advection_x\": advection_x,\n", " \"advection_y\": advection_y,\n", " \"advection\": advection,\n", " \"diffusion_x\": diffusion_x,\n", " \"diffusion_y\": diffusion_y,\n", - " \"diffusion\": diffusion\n", + " \"diffusion\": diffusion,\n", "}\n", "\n", "start_time = time.time()\n", "\n", + "\n", "@gtscript.stencil(backend=backend, externals=externals, rebuild=rebuild, **backend_opts)\n", "def rk_stage(\n", " in_u_now: gtscript.Field[dtype],\n", @@ -262,21 +271,22 @@ " dt: float,\n", " dx: float,\n", " dy: float,\n", - " mu: float\n", + " mu: float,\n", "):\n", " with computation(PARALLEL), interval(...):\n", " adv_u, adv_v = advection(dx=dx, dy=dy, u=in_u_tmp, v=in_v_tmp)\n", " diff_u, diff_v = diffusion(dx=dx, dy=dy, u=in_u_tmp, v=in_v_tmp)\n", - " out_u = in_u_now[0, 0, 0] + dt * (- adv_u[0, 0, 0] + mu * diff_u[0, 0, 0])\n", - " out_v = in_v_now[0, 0, 0] + dt * (- adv_v[0, 0, 0] + mu * diff_v[0, 0, 0])\n", + " out_u = in_u_now[0, 0, 0] + dt * (-adv_u[0, 0, 0] + mu * diff_u[0, 0, 0])\n", + " out_v = in_v_now[0, 0, 0] + dt * (-adv_v[0, 0, 0] + mu * diff_v[0, 0, 0])\n", + "\n", "\n", - " \n", "@gtscript.stencil(backend=backend)\n", "def copy(in_phi: gtscript.Field[dtype], out_phi: gtscript.Field[dtype]):\n", " with computation(PARALLEL), interval(...):\n", " out_phi = in_phi[0, 0, 0]\n", - " \n", - "print(\"\\nCompilation time: \", time.time() - start_time )" + "\n", + "\n", + "print(\"\\nCompilation time: \", time.time() - start_time)" ] }, { @@ -295,49 +305,67 @@ "source": [ "def solution_factory(t, x, y, slice_x=None, slice_y=None):\n", " nx, ny = x.shape[0], y.shape[0]\n", - " \n", + "\n", " slice_x = slice_x or slice(0, nx)\n", " slice_y = slice_y or slice(0, ny)\n", - " \n", + "\n", " mi = slice_x.stop - slice_x.start\n", " mj = slice_y.stop - slice_y.start\n", - " \n", + "\n", " x2d = np.tile(x[slice_x, np.newaxis, np.newaxis], (1, mj, 1))\n", " y2d = np.tile(y[np.newaxis, slice_y, np.newaxis], (mi, 1, 1))\n", - " \n", + "\n", " if use_case == \"zhao\":\n", - " u = - 4. * mu * np.pi * np.exp(- 5. * np.pi**2 * mu * t) * \\\n", - " np.cos(2. * np.pi * x2d) * np.sin(np.pi * y2d) / \\\n", - " (2. + np.exp(- 5. * np.pi**2 * mu * t) * np.sin(2. * np.pi * x2d) * np.sin(np.pi * y2d))\n", - " v = - 2. * mu * np.pi * np.exp(- 5.0 * np.pi**2 * mu * t) * \\\n", - " np.sin(2. * np.pi * x2d) * np.cos(np.pi * y2d) / \\\n", - " (2. + np.exp(- 5. * np.pi**2 * mu * t) * np.sin(2. * np.pi * x2d) * np.sin(np.pi * y2d))\n", + " u = (\n", + " -4.0\n", + " * mu\n", + " * np.pi\n", + " * np.exp(-5.0 * np.pi**2 * mu * t)\n", + " * np.cos(2.0 * np.pi * x2d)\n", + " * np.sin(np.pi * y2d)\n", + " / (\n", + " 2.0\n", + " + np.exp(-5.0 * np.pi**2 * mu * t) * np.sin(2.0 * np.pi * x2d) * np.sin(np.pi * y2d)\n", + " )\n", + " )\n", + " v = (\n", + " -2.0\n", + " * mu\n", + " * np.pi\n", + " * np.exp(-5.0 * np.pi**2 * mu * t)\n", + " * np.sin(2.0 * np.pi * x2d)\n", + " * np.cos(np.pi * y2d)\n", + " / (\n", + " 2.0\n", + " + np.exp(-5.0 * np.pi**2 * mu * t) * np.sin(2.0 * np.pi * x2d) * np.sin(np.pi * y2d)\n", + " )\n", + " )\n", " elif use_case == \"hopf_cole\":\n", - " u = .75 - 1. / (4. * (1. + np.exp(- t - 4.*x2d + 4.*y2d) / (32.*mu)))\n", - " v = .75 + 1. / (4. * (1. + np.exp(- t - 4.*x2d + 4.*y2d) / (32.*mu)))\n", + " u = 0.75 - 1.0 / (4.0 * (1.0 + np.exp(-t - 4.0 * x2d + 4.0 * y2d) / (32.0 * mu)))\n", + " v = 0.75 + 1.0 / (4.0 * (1.0 + np.exp(-t - 4.0 * x2d + 4.0 * y2d) / (32.0 * mu)))\n", " else:\n", " raise NotImplementedError()\n", - " \n", + "\n", " return u, v\n", "\n", "\n", "def set_initial_solution(x, y, u, v):\n", - " u[...], v[...] = solution_factory(0., x, y)\n", - " \n", - " \n", + " u[...], v[...] = solution_factory(0.0, x, y)\n", + "\n", + "\n", "def enforce_boundary_conditions(t, x, y, u, v):\n", " nx, ny = x.shape[0], y.shape[0]\n", - " \n", + "\n", " slice_x, slice_y = slice(0, 3), slice(0, ny)\n", " u[slice_x, slice_y], v[slice_x, slice_y] = solution_factory(t, x, y, slice_x, slice_y)\n", - " \n", - " slice_x, slice_y = slice(nx-3, nx), slice(0, ny)\n", + "\n", + " slice_x, slice_y = slice(nx - 3, nx), slice(0, ny)\n", " u[slice_x, slice_y], v[slice_x, slice_y] = solution_factory(t, x, y, slice_x, slice_y)\n", - " \n", - " slice_x, slice_y = slice(3, nx-3), slice(0, 3)\n", + "\n", + " slice_x, slice_y = slice(3, nx - 3), slice(0, 3)\n", " u[slice_x, slice_y], v[slice_x, slice_y] = solution_factory(t, x, y, slice_x, slice_y)\n", - " \n", - " slice_x, slice_y = slice(3, nx-3), slice(ny-3, ny)\n", + "\n", + " slice_x, slice_y = slice(3, nx - 3), slice(ny - 3, ny)\n", " u[slice_x, slice_y], v[slice_x, slice_y] = solution_factory(t, x, y, slice_x, slice_y)" ] }, @@ -372,10 +400,10 @@ } ], "source": [ - "x = np.linspace(0., 1., nx)\n", - "dx = 1. / (nx - 1)\n", - "y = np.linspace(0., 1., ny)\n", - "dy = 1. / (ny - 1)\n", + "x = np.linspace(0.0, 1.0, nx)\n", + "dx = 1.0 / (nx - 1)\n", + "y = np.linspace(0.0, 1.0, ny)\n", + "dy = 1.0 / (ny - 1)\n", "\n", "u_now = gt4py.storage.zeros((nx, ny, 1), dtype, backend=backend, aligned_index=origin)\n", "v_now = gt4py.storage.zeros((nx, ny, 1), dtype, backend=backend, aligned_index=origin)\n", @@ -384,29 +412,38 @@ "\n", "set_initial_solution(x, y, u_new, v_new)\n", "\n", - "rk_fraction = (1./3., .5, 1.)\n", + "rk_fraction = (1.0 / 3.0, 0.5, 1.0)\n", "\n", - "t = 0.\n", + "t = 0.0\n", "\n", "start_time = time.time()\n", "\n", "for i in range(niter):\n", " copy(in_phi=u_new, out_phi=u_now, origin=(0, 0, 0), domain=(nx, ny, 1))\n", " copy(in_phi=v_new, out_phi=v_now, origin=(0, 0, 0), domain=(nx, ny, 1))\n", - " \n", + "\n", " for k in range(3):\n", " dt = rk_fraction[k] * timestep\n", - " \n", + "\n", " rk_stage(\n", - " in_u_now=u_now, in_v_now=v_now, in_u_tmp=u_new, in_v_tmp=v_new,\n", - " out_u=u_new, out_v=v_new, dt=dt, dx=dx, dy=dy, mu=mu,\n", - " origin=(3, 3, 0), domain=(nx-6, ny-6, 1)\n", + " in_u_now=u_now,\n", + " in_v_now=v_now,\n", + " in_u_tmp=u_new,\n", + " in_v_tmp=v_new,\n", + " out_u=u_new,\n", + " out_v=v_new,\n", + " dt=dt,\n", + " dx=dx,\n", + " dy=dy,\n", + " mu=mu,\n", + " origin=(3, 3, 0),\n", + " domain=(nx - 6, ny - 6, 1),\n", " )\n", - " \n", + "\n", " enforce_boundary_conditions(t + dt, x, y, u_new, v_new)\n", - " \n", + "\n", " t += timestep\n", - " if print_period > 0 and ((i+1) % print_period == 0 or i+1 == niter):\n", + " if print_period > 0 and ((i + 1) % print_period == 0 or i + 1 == niter):\n", " u_ex, v_ex = solution_factory(t, x, y)\n", " err_u = np.linalg.norm(u_new[3:-3, 3:-3] - u_ex[3:-3, 3:-3]) * np.sqrt(dx * dy)\n", " err_v = np.linalg.norm(v_new[3:-3, 3:-3] - v_ex[3:-3, 3:-3]) * np.sqrt(dx * dy)\n", @@ -416,7 +453,7 @@ " )\n", " )\n", "\n", - "print(\"\\n- Running time: \", time.time() - start_time )\n" + "print(\"\\n- Running time: \", time.time() - start_time)" ] }, { diff --git a/examples/cartesian/demo_horizontal_diffusion.ipynb b/examples/cartesian/demo_horizontal_diffusion.ipynb index 8e77614457..d1410da2db 100644 --- a/examples/cartesian/demo_horizontal_diffusion.ipynb +++ b/examples/cartesian/demo_horizontal_diffusion.ipynb @@ -67,7 +67,9 @@ "metadata": {}, "outputs": [], "source": [ - "backend = \"numpy\" # options: \"numpy\", \"gt:cpu_ifirst\", \"gt:cpu_kfirst\", \"gt:gpu\", \"dace:cpu\", \"dace:gpu\"\n", + "backend = (\n", + " \"numpy\" # options: \"numpy\", \"gt:cpu_ifirst\", \"gt:cpu_kfirst\", \"gt:gpu\", \"dace:cpu\", \"dace:gpu\"\n", + ")\n", "dtype = np.float64" ] }, @@ -84,8 +86,7 @@ "metadata": {}, "outputs": [], "source": [ - "\n", - "@gtscript.stencil(backend) # this decorator triggers compilation of the stencil\n", + "@gtscript.stencil(backend) # this decorator triggers compilation of the stencil\n", "def horizontal_diffusion(\n", " in_field: gtscript.Field[dtype],\n", " out_field: gtscript.Field[dtype],\n", @@ -101,7 +102,7 @@ " fly_field = 0 if (res * (in_field[0, 1, 0] - in_field[0, 0, 0])) > 0 else res\n", " out_field = in_field[0, 0, 0] - coeff[0, 0, 0] * (\n", " flx_field[0, 0, 0] - flx_field[-1, 0, 0] + fly_field[0, 0, 0] - fly_field[0, -1, 0]\n", - " )\n" + " )" ] }, { @@ -152,13 +153,15 @@ "yy = jj / N\n", "zz = kk / N\n", "\n", - "in_data = 5. + 8. * (2. + np.cos(np.pi * (xx + 1.5 * yy)) + np.sin(2 * np.pi * (xx + 1.5 * yy))) / 4.\n", + "in_data = (\n", + " 5.0 + 8.0 * (2.0 + np.cos(np.pi * (xx + 1.5 * yy)) + np.sin(2 * np.pi * (xx + 1.5 * yy))) / 4.0\n", + ")\n", "out_data = np.zeros(shape)\n", "coeff_data = 0.025 * np.ones(shape)\n", "\n", "# Plot initialization\n", "projection = np.array(np.sum(in_data, axis=2))\n", - "plt.imshow(projection)\n" + "plt.imshow(projection)" ] }, { @@ -174,15 +177,9 @@ "metadata": {}, "outputs": [], "source": [ - "in_storage = gt4py.storage.from_array(\n", - " in_data, dtype, backend=backend, aligned_index=origin\n", - ")\n", - "out_storage = gt4py.storage.from_array(\n", - " out_data, dtype, backend=backend, aligned_index=origin\n", - ")\n", - "coeff_storage = gt4py.storage.from_array(\n", - " coeff_data, dtype, backend=backend, aligned_index=origin\n", - ")" + "in_storage = gt4py.storage.from_array(in_data, dtype, backend=backend, aligned_index=origin)\n", + "out_storage = gt4py.storage.from_array(out_data, dtype, backend=backend, aligned_index=origin)\n", + "coeff_storage = gt4py.storage.from_array(coeff_data, dtype, backend=backend, aligned_index=origin)" ] }, { diff --git a/examples/cartesian/demo_isentropic_diagnostics.ipynb b/examples/cartesian/demo_isentropic_diagnostics.ipynb index 56bd483fe0..8c0cfc7aa9 100644 --- a/examples/cartesian/demo_isentropic_diagnostics.ipynb +++ b/examples/cartesian/demo_isentropic_diagnostics.ipynb @@ -94,13 +94,13 @@ "nz = 64\n", "\n", "# brunt-vaisala frequency\n", - "bv = .01\n", + "bv = 0.01\n", "\n", "# physical constants\n", "rd = 287.05\n", "g = 9.81\n", "p_ref = 1.0e5\n", - "cp = 1004." + "cp = 1004.0" ] }, { @@ -127,8 +127,10 @@ ], "source": [ "# gridtools4py settings\n", - "backend = \"numpy\" # options: \"numpy\", \"gt:cpu_ifirst\", \"gt:cpu_kfirst\", \"gt:gpu\", \"dace:cpu\", \"dace:gpu\"\n", - "backend_opts = {'verbose': True} if backend.startswith('gt') else {}\n", + "backend = (\n", + " \"numpy\" # options: \"numpy\", \"gt:cpu_ifirst\", \"gt:cpu_kfirst\", \"gt:gpu\", \"dace:cpu\", \"dace:gpu\"\n", + ")\n", + "backend_opts = {\"verbose\": True} if backend.startswith(\"gt\") else {}\n", "dtype = np.float64\n", "origin = (3, 3, 0)\n", "rebuild = True\n", @@ -137,6 +139,7 @@ "\n", "start_time = time.time()\n", "\n", + "\n", "@gtscript.stencil(backend=backend, externals=externals, **backend_opts)\n", "def diagnostic_step(\n", " in_theta: gtscript.Field[dtype],\n", @@ -148,10 +151,10 @@ " inout_h: gtscript.Field[dtype],\n", " *,\n", " dtheta: float,\n", - " pt: float\n", + " pt: float,\n", "):\n", " # retrieve the pressure\n", - " with computation(FORWARD), interval(0,1):\n", + " with computation(FORWARD), interval(0, 1):\n", " inout_p = pt\n", " with computation(FORWARD), interval(1, None):\n", " inout_p = inout_p[0, 0, -1] + g * dtheta * in_s[0, 0, -1]\n", @@ -161,10 +164,10 @@ " out_exn = cp * (inout_p[0, 0, 0] / p_ref) ** (rd / cp)\n", "\n", " # compute the Montgomery potential\n", - " with computation(BACKWARD), interval(-2,-1):\n", + " with computation(BACKWARD), interval(-2, -1):\n", " mtg_s = in_theta[0, 0, 1] * out_exn[0, 0, 1] + g * in_hs[0, 0, 1]\n", " inout_mtg = mtg_s + 0.5 * dtheta * out_exn[0, 0, 1]\n", - " with computation(BACKWARD), interval(0,-2):\n", + " with computation(BACKWARD), interval(0, -2):\n", " inout_mtg = inout_mtg[0, 0, 1] + dtheta * out_exn[0, 0, 1]\n", "\n", " # compute the geometric height of the isentropes\n", @@ -172,13 +175,11 @@ " inout_h = in_hs[0, 0, 0]\n", " with computation(BACKWARD), interval(0, -1):\n", " inout_h = inout_h[0, 0, 1] - rd * (\n", - " in_theta[0, 0, 0] * out_exn[0, 0, 0]\n", - " + in_theta[0, 0, 1] * out_exn[0, 0, 1]\n", - " ) * (inout_p[0, 0, 0] - inout_p[0, 0, 1]) / (\n", - " cp * g * (inout_p[0, 0, 0] + inout_p[0, 0, 1])\n", - " )\n", - " \n", - "print(\"\\n- Compilation time: \", time.time() - start_time ) " + " in_theta[0, 0, 0] * out_exn[0, 0, 0] + in_theta[0, 0, 1] * out_exn[0, 0, 1]\n", + " ) * (inout_p[0, 0, 0] - inout_p[0, 0, 1]) / (cp * g * (inout_p[0, 0, 0] + inout_p[0, 0, 1]))\n", + "\n", + "\n", + "print(\"\\n- Compilation time: \", time.time() - start_time)" ] }, { @@ -196,47 +197,53 @@ "outputs": [], "source": [ "# define the vertical grid\n", - "theta1d = np.linspace(340., 280., nz+1)\n", - "theta = gt4py.storage.zeros((nx, ny, nz+1), dtype, backend=backend, aligned_index=origin)\n", + "theta1d = np.linspace(340.0, 280.0, nz + 1)\n", + "theta = gt4py.storage.zeros((nx, ny, nz + 1), dtype, backend=backend, aligned_index=origin)\n", "theta[...] = theta1d[np.newaxis, np.newaxis, :]\n", "\n", "# the vertical grid spacing\n", - "dtheta = 60. / nz\n", + "dtheta = 60.0 / nz\n", "\n", "# let us assume the topography consists of a bell-shaped isolated mountain\n", - "hs = gt4py.storage.zeros((nx, ny, nz+1), dtype, backend=backend, aligned_index=origin)\n", + "hs = gt4py.storage.zeros((nx, ny, nz + 1), dtype, backend=backend, aligned_index=origin)\n", "x1d = np.linspace(-150e3, 150e3, nx)\n", "y1d = np.linspace(-150e3, 150e3, ny)\n", "x, y = np.meshgrid(x1d, y1d, indexing=\"ij\")\n", - "hs[:, :, -1] = 1000. * np.exp(- (x / 50e3)**2 - (y / 50e3)**2)\n", + "hs[:, :, -1] = 1000.0 * np.exp(-((x / 50e3) ** 2) - (y / 50e3) ** 2)\n", "\n", "# initialize the Exner function (needed to compute the isentropic density)\n", - "exn = np.zeros((nx, ny, nz+1), dtype=dtype)\n", + "exn = np.zeros((nx, ny, nz + 1), dtype=dtype)\n", "exn[:, :, -1] = cp\n", "for k in range(nz - 1, -1, -1):\n", - " exn[:, :, k] = exn[:, :, k + 1] - dtheta * (g ** 2) / (\n", - " (bv ** 2) * (theta[:, :, k] ** 2)\n", - " )\n", + " exn[:, :, k] = exn[:, :, k + 1] - dtheta * (g**2) / ((bv**2) * (theta[:, :, k] ** 2))\n", "\n", "# retrieve the air pressure (needed to compute the isentropic density)\n", "p = p_ref * ((exn / cp) ** (cp / rd))\n", "\n", "# diagnose the isentropic density\n", - "s = gt4py.storage.zeros((nx, ny, nz+1), dtype, backend=backend, aligned_index=origin)\n", + "s = gt4py.storage.zeros((nx, ny, nz + 1), dtype, backend=backend, aligned_index=origin)\n", "s[:, :, :-1] = -(p[:, :, :-1] - p[:, :, 1:]) / (g * dtheta)\n", "\n", "# allocate the output storages\n", - "out_p = gt4py.storage.zeros((nx, ny, nz+1), dtype, backend=backend, aligned_index=origin)\n", - "out_exn = gt4py.storage.zeros((nx, ny, nz+1), dtype, backend=backend, aligned_index=origin)\n", - "out_mtg = gt4py.storage.zeros((nx, ny, nz+1), dtype, backend=backend, aligned_index=origin)\n", - "out_h = gt4py.storage.zeros((nx, ny, nz+1), dtype, backend=backend, aligned_index=origin)\n", + "out_p = gt4py.storage.zeros((nx, ny, nz + 1), dtype, backend=backend, aligned_index=origin)\n", + "out_exn = gt4py.storage.zeros((nx, ny, nz + 1), dtype, backend=backend, aligned_index=origin)\n", + "out_mtg = gt4py.storage.zeros((nx, ny, nz + 1), dtype, backend=backend, aligned_index=origin)\n", + "out_h = gt4py.storage.zeros((nx, ny, nz + 1), dtype, backend=backend, aligned_index=origin)\n", "\n", "# compute all the diagnostic variables\n", "diagnostic_step(\n", - " in_theta=theta, in_hs=hs, in_s=s, inout_p=out_p, out_exn=out_exn, \n", - " inout_mtg=out_mtg, inout_h=out_h, dtheta=dtheta, pt=p[0, 0, 0],\n", - " origin=(0, 0, 0), domain=(nx, ny, nz+1)\n", - ")\n" + " in_theta=theta,\n", + " in_hs=hs,\n", + " in_s=s,\n", + " inout_p=out_p,\n", + " out_exn=out_exn,\n", + " inout_mtg=out_mtg,\n", + " inout_h=out_h,\n", + " dtheta=dtheta,\n", + " pt=p[0, 0, 0],\n", + " origin=(0, 0, 0),\n", + " domain=(nx, ny, nz + 1),\n", + ")" ] }, { @@ -264,18 +271,18 @@ } ], "source": [ - "out_p =np.asarray(out_p)\n", - "out_exn =np.asarray(out_exn)\n", - "out_mtg =np.asarray(out_mtg)\n", + "out_p = np.asarray(out_p)\n", + "out_exn = np.asarray(out_exn)\n", + "out_mtg = np.asarray(out_mtg)\n", "\n", "j = int(ny / 2)\n", - "xx = 1e-3 * np.repeat(x[:, j, np.newaxis], nz+1, axis=1)\n", + "xx = 1e-3 * np.repeat(x[:, j, np.newaxis], nz + 1, axis=1)\n", "yy = 1e-3 * np.asarray(out_h[:, j, :])\n", "\n", "fig = plt.figure(figsize=(10, 10))\n", "\n", "ax00 = fig.add_subplot(2, 2, 1)\n", - "surf = ax00.contourf(xx, yy, 1e-2*out_p[:, j, :], cmap=\"Blues\")\n", + "surf = ax00.contourf(xx, yy, 1e-2 * out_p[:, j, :], cmap=\"Blues\")\n", "plt.colorbar(surf, orientation=\"vertical\")\n", "ax00.plot(xx[:, -1], yy[:, -1], color=\"black\", linewidth=1.5)\n", "ax00.set_xlim((-100, 100))\n", @@ -295,7 +302,7 @@ "ax01.set_title(\"Exner function [J kg$^{-1}$ K$^{-1}$]\")\n", "\n", "ax10 = fig.add_subplot(2, 2, 3)\n", - "surf = ax10.contourf(xx, yy, 1e-3*out_mtg[:, j, :], cmap=\"Reds\")\n", + "surf = ax10.contourf(xx, yy, 1e-3 * out_mtg[:, j, :], cmap=\"Reds\")\n", "ax10.plot(xx[:, -1], yy[:, -1], color=\"black\", linewidth=1.5)\n", "plt.colorbar(surf, orientation=\"vertical\")\n", "ax10.set_xlim((-100, 100))\n", @@ -325,7 +332,7 @@ "outputs": [], "source": [ "# This cell only works in Jupyter Lab with itkwidgets extension.\n", - "# Installation commands: \n", + "# Installation commands:\n", "#!pip install jupyterlab itkwidgets\n", "#!jupyter labextension install @jupyter-widgets/jupyterlab-manager itkwidgets\n", "\n", diff --git a/examples/lap_cartesian_vs_next.ipynb b/examples/lap_cartesian_vs_next.ipynb index 28837c2154..f415e02f91 100644 --- a/examples/lap_cartesian_vs_next.ipynb +++ b/examples/lap_cartesian_vs_next.ipynb @@ -75,7 +75,7 @@ "source": [ "import gt4py.next as gtx\n", "\n", - "allocator = gtx.itir_python # should match the executor\n", + "allocator = gtx.itir_python # should match the executor\n", "# allocator = gtx.gtfn_cpu\n", "# allocator = gtx.gtfn_gpu\n", "\n", @@ -86,7 +86,12 @@ "\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", + "inp = gtx.as_field(\n", + " domain,\n", + " np.fromfunction(lambda x, y, z: x**2 + y**2, shape=(nx, ny, nz)),\n", + " dtype,\n", + " allocator=allocator,\n", + ")\n", "out_cartesian = gtx.zeros(domain, dtype, allocator=allocator)\n", "out_next = gtx.zeros(domain, dtype, allocator=allocator)" ] @@ -112,6 +117,7 @@ "# cartesian_backend = \"gt:cpu_ifirst\"\n", "# cartesian_backend = \"gt:gpu\"\n", "\n", + "\n", "@gtscript.stencil(backend=cartesian_backend)\n", "def lap_cartesian(\n", " inp: gtscript.Field[dtype],\n", @@ -120,7 +126,8 @@ " 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))" + "\n", + "lap_cartesian(inp=inp, out=out_cartesian, origin=(1, 1, 0), domain=(nx - 2, ny - 2, nz))" ] }, { @@ -138,14 +145,17 @@ "Ioff = gtx.FieldOffset(\"I\", source=I, target=(I,))\n", "Joff = gtx.FieldOffset(\"J\", source=J, target=(J,))\n", "\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", + "\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", + "\n", "lap_next_program(inp, out_next, offset_provider={\"Ioff\": I, \"Joff\": J})" ] }, diff --git a/min-extra-requirements-test.txt b/min-extra-requirements-test.txt index 44535bb890..5210f889c5 100644 --- a/min-extra-requirements-test.txt +++ b/min-extra-requirements-test.txt @@ -66,15 +66,6 @@ darglint==1.6 deepdiff==5.6.0 devtools==0.6 factory-boy==3.3.0 -flake8-bugbear==20.11.1 -flake8-builtins==1.5.3 -flake8-debugger==4.0.0 -flake8-docstrings==1.5.0 -flake8-eradicate==1.3.0 -flake8-mutable==1.2.0 -flake8-pyproject==1.2.2 -flake8-rst-docstrings==0.0.14 -flake8==5.0.4 frozendict==2.3 gridtools-cpp==2.3.4 hypothesis==6.0.0 diff --git a/min-requirements-test.txt b/min-requirements-test.txt index 17b07db9c9..dd2de61f11 100644 --- a/min-requirements-test.txt +++ b/min-requirements-test.txt @@ -62,15 +62,6 @@ darglint==1.6 deepdiff==5.6.0 devtools==0.6 factory-boy==3.3.0 -flake8-bugbear==20.11.1 -flake8-builtins==1.5.3 -flake8-debugger==4.0.0 -flake8-docstrings==1.5.0 -flake8-eradicate==1.3.0 -flake8-mutable==1.2.0 -flake8-pyproject==1.2.2 -flake8-rst-docstrings==0.0.14 -flake8==5.0.4 frozendict==2.3 gridtools-cpp==2.3.4 hypothesis==6.0.0 diff --git a/requirements-dev.in b/requirements-dev.in index a1530ee731..a6d6245e83 100644 --- a/requirements-dev.in +++ b/requirements-dev.in @@ -10,15 +10,6 @@ clang-format>=9.0 cogapp>=3.3 coverage[toml]>=5.0 darglint>=1.6 -flake8>=5.0.4 -flake8-bugbear>=20.11.1 -flake8-builtins>=1.5.3 -flake8-debugger>=4.0.0 -flake8-docstrings>=1.5.0 -flake8-eradicate>=1.3.0 -flake8-mutable>=1.2.0 -flake8-pyproject>=1.2.2 -flake8-rst-docstrings>=0.0.14 hypothesis # constraints in gt4py['testing'] isort>=5.10 jupytext>=1.14 diff --git a/requirements-dev.txt b/requirements-dev.txt index de42f3e24e..770de33c63 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -9,17 +9,17 @@ alabaster==0.7.13 # via -c constraints.txt, sphinx annotated-types==0.7.0 # via -c constraints.txt, pydantic asttokens==2.4.1 # via -c constraints.txt, devtools, stack-data astunparse==1.6.3 ; python_version < "3.9" # via -c constraints.txt, dace, gt4py (pyproject.toml) -attrs==24.2.0 # via -c constraints.txt, flake8-bugbear, flake8-eradicate, gt4py (pyproject.toml), hypothesis, jsonschema, referencing -babel==2.15.0 # via -c constraints.txt, sphinx +attrs==24.2.0 # via -c constraints.txt, gt4py (pyproject.toml), hypothesis, jsonschema, referencing +babel==2.16.0 # via -c constraints.txt, sphinx backcall==0.2.0 # via -c constraints.txt, ipython black==24.8.0 # via -c constraints.txt, gt4py (pyproject.toml) boltons==24.0.0 # via -c constraints.txt, gt4py (pyproject.toml) bracex==2.5 # via -c constraints.txt, wcmatch build==1.2.1 # via -c constraints.txt, pip-tools -bump-my-version==0.25.0 # via -c constraints.txt, -r requirements-dev.in +bump-my-version==0.26.0 # via -c constraints.txt, -r requirements-dev.in cached-property==1.5.2 # via -c constraints.txt, gt4py (pyproject.toml) -cachetools==5.4.0 # via -c constraints.txt, tox -certifi==2024.7.4 # via -c constraints.txt, requests +cachetools==5.5.0 # via -c constraints.txt, tox +certifi==2024.8.30 # via -c constraints.txt, requests cfgv==3.4.0 # via -c constraints.txt, pre-commit chardet==5.2.0 # via -c constraints.txt, tox charset-normalizer==3.3.2 # via -c constraints.txt, requests @@ -37,38 +37,28 @@ dace==0.16.1 # via -c constraints.txt, gt4py (pyproject.toml) darglint==1.8.1 # via -c constraints.txt, -r requirements-dev.in debugpy==1.8.5 # via -c constraints.txt, ipykernel decorator==5.1.1 # via -c constraints.txt, ipython -deepdiff==7.0.1 # via -c constraints.txt, gt4py (pyproject.toml) +deepdiff==8.0.1 # via -c constraints.txt, gt4py (pyproject.toml) devtools==0.12.2 # via -c constraints.txt, gt4py (pyproject.toml) dill==0.3.8 # via -c constraints.txt, dace distlib==0.3.8 # via -c constraints.txt, virtualenv -docutils==0.20.1 # via -c constraints.txt, restructuredtext-lint, sphinx, sphinx-rtd-theme -eradicate==2.3.0 # via -c constraints.txt, flake8-eradicate +docutils==0.20.1 # via -c constraints.txt, sphinx, sphinx-rtd-theme exceptiongroup==1.2.2 # via -c constraints.txt, hypothesis, pytest execnet==2.1.1 # via -c constraints.txt, pytest-cache, pytest-xdist -executing==2.0.1 # via -c constraints.txt, devtools, stack-data -factory-boy==3.3.0 # via -c constraints.txt, gt4py (pyproject.toml), pytest-factoryboy -faker==26.2.0 # via -c constraints.txt, factory-boy +executing==2.1.0 # via -c constraints.txt, devtools, stack-data +factory-boy==3.3.1 # via -c constraints.txt, gt4py (pyproject.toml), pytest-factoryboy +faker==28.1.0 # via -c constraints.txt, factory-boy fastjsonschema==2.20.0 # via -c constraints.txt, nbformat filelock==3.15.4 # via -c constraints.txt, tox, virtualenv -flake8==7.1.1 # via -c constraints.txt, -r requirements-dev.in, flake8-bugbear, flake8-builtins, flake8-debugger, flake8-docstrings, flake8-eradicate, flake8-mutable, flake8-pyproject, flake8-rst-docstrings -flake8-bugbear==24.4.26 # via -c constraints.txt, -r requirements-dev.in -flake8-builtins==2.5.0 # via -c constraints.txt, -r requirements-dev.in -flake8-debugger==4.1.2 # via -c constraints.txt, -r requirements-dev.in -flake8-docstrings==1.7.0 # via -c constraints.txt, -r requirements-dev.in -flake8-eradicate==1.5.0 # via -c constraints.txt, -r requirements-dev.in -flake8-mutable==1.2.0 # via -c constraints.txt, -r requirements-dev.in -flake8-pyproject==1.2.3 # via -c constraints.txt, -r requirements-dev.in -flake8-rst-docstrings==0.3.0 # via -c constraints.txt, -r requirements-dev.in fonttools==4.53.1 # via -c constraints.txt, matplotlib fparser==0.1.4 # via -c constraints.txt, dace frozendict==2.4.4 # via -c constraints.txt, gt4py (pyproject.toml) gridtools-cpp==2.3.4 # via -c constraints.txt, gt4py (pyproject.toml) -hypothesis==6.109.0 # via -c constraints.txt, -r requirements-dev.in, gt4py (pyproject.toml) +hypothesis==6.111.2 # via -c constraints.txt, -r requirements-dev.in, gt4py (pyproject.toml) identify==2.6.0 # via -c constraints.txt, pre-commit -idna==3.7 # via -c constraints.txt, requests +idna==3.8 # via -c constraints.txt, requests imagesize==1.4.1 # via -c constraints.txt, sphinx -importlib-metadata==8.2.0 # via -c constraints.txt, build, jupyter-client, sphinx -importlib-resources==6.4.0 ; python_version < "3.9" # via -c constraints.txt, gt4py (pyproject.toml), jsonschema, jsonschema-specifications, matplotlib +importlib-metadata==8.4.0 # via -c constraints.txt, build, jupyter-client, sphinx +importlib-resources==6.4.4 ; python_version < "3.9" # via -c constraints.txt, gt4py (pyproject.toml), jsonschema, jsonschema-specifications, matplotlib inflection==0.5.1 # via -c constraints.txt, pytest-factoryboy iniconfig==2.0.0 # via -c constraints.txt, pytest ipykernel==6.29.5 # via -c constraints.txt, nbmake @@ -82,19 +72,18 @@ jupyter-client==8.6.2 # via -c constraints.txt, ipykernel, nbclient jupyter-core==5.7.2 # via -c constraints.txt, ipykernel, jupyter-client, nbformat jupytext==1.16.4 # via -c constraints.txt, -r requirements-dev.in kiwisolver==1.4.5 # via -c constraints.txt, matplotlib -lark==1.1.9 # via -c constraints.txt, gt4py (pyproject.toml) +lark==1.2.2 # via -c constraints.txt, gt4py (pyproject.toml) mako==1.3.5 # via -c constraints.txt, gt4py (pyproject.toml) markdown-it-py==3.0.0 # via -c constraints.txt, jupytext, mdit-py-plugins, rich markupsafe==2.1.5 # via -c constraints.txt, jinja2, mako matplotlib==3.7.5 # via -c constraints.txt, -r requirements-dev.in matplotlib-inline==0.1.7 # via -c constraints.txt, ipykernel, ipython -mccabe==0.7.0 # via -c constraints.txt, flake8 mdit-py-plugins==0.4.1 # via -c constraints.txt, jupytext mdurl==0.1.2 # via -c constraints.txt, markdown-it-py mpmath==1.3.0 # via -c constraints.txt, sympy -mypy==1.11.1 # via -c constraints.txt, -r requirements-dev.in +mypy==1.11.2 # via -c constraints.txt, -r requirements-dev.in mypy-extensions==1.0.0 # via -c constraints.txt, black, mypy -nanobind==2.0.0 # via -c constraints.txt, gt4py (pyproject.toml) +nanobind==2.1.0 # via -c constraints.txt, gt4py (pyproject.toml) nbclient==0.6.8 # via -c constraints.txt, nbmake nbformat==5.10.4 # via -c constraints.txt, jupytext, nbclient, nbmake nbmake==1.5.4 # via -c constraints.txt, -r requirements-dev.in @@ -103,7 +92,7 @@ networkx==3.1 # via -c constraints.txt, dace ninja==1.11.1.1 # via -c constraints.txt, gt4py (pyproject.toml) nodeenv==1.9.1 # via -c constraints.txt, pre-commit numpy==1.24.4 # via -c constraints.txt, contourpy, dace, gt4py (pyproject.toml), matplotlib -ordered-set==4.1.0 # via -c constraints.txt, deepdiff +orderly-set==5.2.2 # via -c constraints.txt, deepdiff packaging==24.1 # via -c constraints.txt, black, build, gt4py (pyproject.toml), ipykernel, jupytext, matplotlib, pipdeptree, pyproject-api, pytest, pytest-factoryboy, setuptools-scm, sphinx, tox parso==0.8.4 # via -c constraints.txt, jedi pathspec==0.12.1 # via -c constraints.txt, black @@ -121,15 +110,12 @@ prompt-toolkit==3.0.36 # via -c constraints.txt, ipython, questionary psutil==6.0.0 # via -c constraints.txt, -r requirements-dev.in, ipykernel, pytest-xdist ptyprocess==0.7.0 # via -c constraints.txt, pexpect pure-eval==0.2.3 # via -c constraints.txt, stack-data -pybind11==2.13.1 # via -c constraints.txt, gt4py (pyproject.toml) -pycodestyle==2.12.1 # via -c constraints.txt, flake8, flake8-debugger +pybind11==2.13.5 # via -c constraints.txt, gt4py (pyproject.toml) pydantic==2.8.2 # via -c constraints.txt, bump-my-version, pydantic-settings pydantic-core==2.20.1 # via -c constraints.txt, pydantic pydantic-settings==2.4.0 # via -c constraints.txt, bump-my-version -pydocstyle==6.3.0 # via -c constraints.txt, flake8-docstrings -pyflakes==3.2.0 # via -c constraints.txt, flake8 -pygments==2.18.0 # via -c constraints.txt, -r requirements-dev.in, devtools, flake8-rst-docstrings, ipython, nbmake, rich, sphinx -pyparsing==3.1.2 # via -c constraints.txt, matplotlib +pygments==2.18.0 # via -c constraints.txt, -r requirements-dev.in, devtools, ipython, nbmake, rich, sphinx +pyparsing==3.1.4 # via -c constraints.txt, matplotlib pyproject-api==1.7.1 # via -c constraints.txt, tox pyproject-hooks==1.1.0 # via -c constraints.txt, build, pip-tools pytest==8.3.2 # via -c constraints.txt, -r requirements-dev.in, gt4py (pyproject.toml), nbmake, pytest-cache, pytest-cov, pytest-factoryboy, pytest-instafail, pytest-xdist @@ -142,18 +128,17 @@ python-dateutil==2.9.0.post0 # via -c constraints.txt, faker, jupyter-client, m python-dotenv==1.0.1 # via -c constraints.txt, pydantic-settings pytz==2024.1 # via -c constraints.txt, babel pyyaml==6.0.2 # via -c constraints.txt, dace, jupytext, pre-commit -pyzmq==26.1.0 # via -c constraints.txt, ipykernel, jupyter-client +pyzmq==26.2.0 # via -c constraints.txt, ipykernel, jupyter-client questionary==2.0.1 # via -c constraints.txt, bump-my-version referencing==0.35.1 # via -c constraints.txt, jsonschema, jsonschema-specifications requests==2.32.3 # via -c constraints.txt, sphinx -restructuredtext-lint==1.4.0 # via -c constraints.txt, flake8-rst-docstrings -rich==13.7.1 # via -c constraints.txt, bump-my-version, rich-click +rich==13.8.0 # via -c constraints.txt, bump-my-version, rich-click rich-click==1.8.3 # via -c constraints.txt, bump-my-version rpds-py==0.20.0 # via -c constraints.txt, jsonschema, referencing -ruff==0.5.6 # via -c constraints.txt, -r requirements-dev.in +ruff==0.6.3 # via -c constraints.txt, -r requirements-dev.in setuptools-scm==8.1.0 # via -c constraints.txt, fparser six==1.16.0 # via -c constraints.txt, asttokens, astunparse, python-dateutil -snowballstemmer==2.2.0 # via -c constraints.txt, pydocstyle, sphinx +snowballstemmer==2.2.0 # via -c constraints.txt, sphinx sortedcontainers==2.4.0 # via -c constraints.txt, hypothesis sphinx==7.1.2 # via -c constraints.txt, -r requirements-dev.in, sphinx-rtd-theme, sphinxcontrib-jquery sphinx-rtd-theme==2.0.0 # via -c constraints.txt, -r requirements-dev.in @@ -167,11 +152,11 @@ sphinxcontrib-serializinghtml==1.1.5 # via -c constraints.txt, sphinx stack-data==0.6.3 # via -c constraints.txt, ipython sympy==1.12.1 # via -c constraints.txt, dace, gt4py (pyproject.toml) tabulate==0.9.0 # via -c constraints.txt, gt4py (pyproject.toml) -tomli==2.0.1 ; python_version < "3.11" # via -c constraints.txt, -r requirements-dev.in, black, build, coverage, flake8-pyproject, jupytext, mypy, pip-tools, pyproject-api, pytest, setuptools-scm, tox -tomlkit==0.13.0 # via -c constraints.txt, bump-my-version +tomli==2.0.1 ; python_version < "3.11" # via -c constraints.txt, -r requirements-dev.in, black, build, coverage, jupytext, mypy, pip-tools, pyproject-api, pytest, setuptools-scm, tox +tomlkit==0.13.2 # via -c constraints.txt, bump-my-version toolz==0.12.1 # via -c constraints.txt, cytoolz tornado==6.4.1 # via -c constraints.txt, ipykernel, jupyter-client -tox==4.17.0 # via -c constraints.txt, -r requirements-dev.in +tox==4.18.0 # via -c constraints.txt, -r requirements-dev.in traitlets==5.14.3 # via -c constraints.txt, comm, ipykernel, ipython, jupyter-client, jupyter-core, matplotlib-inline, nbclient, nbformat types-tabulate==0.9.0.20240106 # via -c constraints.txt, -r requirements-dev.in typing-extensions==4.12.2 # via -c constraints.txt, annotated-types, black, gt4py (pyproject.toml), ipython, mypy, pydantic, pydantic-core, pytest-factoryboy, rich, rich-click, setuptools-scm @@ -179,11 +164,11 @@ urllib3==2.2.2 # via -c constraints.txt, requests virtualenv==20.26.3 # via -c constraints.txt, pre-commit, tox wcmatch==9.0 # via -c constraints.txt, bump-my-version wcwidth==0.2.13 # via -c constraints.txt, prompt-toolkit -websockets==12.0 # via -c constraints.txt, dace +websockets==13.0.1 # via -c constraints.txt, dace wheel==0.44.0 # via -c constraints.txt, astunparse, pip-tools xxhash==3.0.0 # via -c constraints.txt, gt4py (pyproject.toml) -zipp==3.19.2 # via -c constraints.txt, importlib-metadata, importlib-resources +zipp==3.20.1 # via -c constraints.txt, importlib-metadata, importlib-resources # The following packages are considered to be unsafe in a requirements file: pip==24.2 # via -c constraints.txt, pip-tools, pipdeptree -setuptools==72.1.0 # via -c constraints.txt, gt4py (pyproject.toml), pip-tools, setuptools-scm +setuptools==74.0.0 # via -c constraints.txt, gt4py (pyproject.toml), pip-tools, setuptools-scm diff --git a/src/gt4py/eve/extended_typing.py b/src/gt4py/eve/extended_typing.py index fdc0f7a761..b16c77c464 100644 --- a/src/gt4py/eve/extended_typing.py +++ b/src/gt4py/eve/extended_typing.py @@ -28,7 +28,7 @@ import types as _types import typing as _typing from typing import * # noqa: F403 [undefined-local-with-import-star] -from typing import overload # Only needed to avoid false flake8 errors +from typing import overload import numpy.typing as npt import typing_extensions as _typing_extensions diff --git a/tests/cartesian_tests/unit_tests/backend_tests/test_module_generator.py b/tests/cartesian_tests/unit_tests/backend_tests/test_module_generator.py index 29292ceb45..963b824122 100644 --- a/tests/cartesian_tests/unit_tests/backend_tests/test_module_generator.py +++ b/tests/cartesian_tests/unit_tests/backend_tests/test_module_generator.py @@ -78,7 +78,6 @@ def sample_stencil_with_args( used_scalar: float, # type: ignore unused_scalar: bool, # type: ignore ): - # flake8: noqa with computation(PARALLEL), interval(...): # type: ignore used_io_field = used_in_field[1, 0, 0] + used_scalar # type: ignore diff --git a/tox.ini b/tox.ini index e6a5ab36c6..861ec02c0a 100644 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,6 @@ envlist = eve-py{310} next-py{310}-{nomesh,atlas} storage-py{310}-{internal,dace}-{cpu} - linters-py{310} # docs labels = test-cartesian-cpu = cartesian-py38-internal-cpu, cartesian-py39-internal-cpu, cartesian-py310-internal-cpu, \ @@ -100,12 +99,6 @@ commands = #pytest doctest-modules {posargs} src{/}gt4py{/}storage # -- Secondary tests -- -[testenv:linters-py{38,39,310,311}] -description = Run linters -commands = - flake8 .{/}src - mypy .{/}src - [testenv:notebooks-py{310,311}] description = Run notebooks commands_pre =