From eeef0539c03c5a625d663c1d084a6299b0fa1476 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Thu, 17 Oct 2024 13:03:25 -0600 Subject: [PATCH 1/8] Add directory README and launch notebook. --- examples/README-bmi-example-python.ipynb | 44 ++++++++++++++++++++++++ examples/README.md | 6 ++++ 2 files changed, 50 insertions(+) create mode 100644 examples/README-bmi-example-python.ipynb create mode 100644 examples/README.md diff --git a/examples/README-bmi-example-python.ipynb b/examples/README-bmi-example-python.ipynb new file mode 100644 index 0000000..a1b15f3 --- /dev/null +++ b/examples/README-bmi-example-python.ipynb @@ -0,0 +1,44 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "0", + "metadata": {}, + "source": [ + "# Examples: Python BMI" + ] + }, + { + "cell_type": "markdown", + "id": "1", + "metadata": {}, + "source": [ + "Here are examples of using the *Heat* model and its Python *BMI*.\n", + "\n", + "* [run-model.ipynb](./run-model.ipynb) and [run-model-from-bmi.ipynb](./run-model-from-bmi.ipynb): These Jupyter Notebooks show how to interact with the *Heat* model through its API and its BMI, respectively.\n", + "* [heat.yaml](./heat.yaml): A configuration file used to pass parameters to the *Heat* BMI." + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "CSDMS", + "language": "python", + "name": "csdms" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..10ffd4f --- /dev/null +++ b/examples/README.md @@ -0,0 +1,6 @@ +# Examples: Python BMI + +Here are examples of using the *Heat* model and its Python BMI. + +* [run-model.ipynb](./run-model.ipynb) and [run-model-from-bmi.ipynb](./run-model-from-bmi.ipynb): These Jupyter Notebooks show how to interact with the *Heat* model through its API and its BMI, respectively. +* [heat.yaml](./heat.yaml): A configuration file used to pass parameters to the *Heat* BMI. From 07ec68beccb70cb009c761eb4b28245a1a09f159 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Thu, 17 Oct 2024 15:36:47 -0600 Subject: [PATCH 2/8] Touch up text and code in notebooks --- examples/run-model-from-bmi.ipynb | 20 ++++++++++---------- examples/run-model.ipynb | 18 +++++++++--------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/examples/run-model-from-bmi.ipynb b/examples/run-model-from-bmi.ipynb index ad1c650..9fb2287 100644 --- a/examples/run-model-from-bmi.ipynb +++ b/examples/run-model-from-bmi.ipynb @@ -4,21 +4,21 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Run the `Heat` model through its BMI" + "# Run the *Heat* model through its BMI" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "`Heat` models the diffusion of temperature on a uniform rectangular plate with Dirichlet boundary conditions. View the source code for the [model](https://github.com/csdms/bmi-example-python/blob/master/heat/heat.py) and its [BMI](https://github.com/csdms/bmi-example-python/blob/master/heat/bmi_heat.py) on GitHub." + "*Heat* models the diffusion of temperature on a uniform rectangular plate with Dirichlet boundary conditions. View the source code for the [model](https://github.com/csdms/bmi-example-python/blob/master/heat/heat.py) and its [BMI](https://github.com/csdms/bmi-example-python/blob/master/heat/bmi_heat.py) on GitHub." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Start by importing `os`, `numpy` and the `Heat` BMI:" + "Start by importing *numpy* and the *Heat* BMI:" ] }, { @@ -27,7 +27,6 @@ "metadata": {}, "outputs": [], "source": [ - "import os\n", "import numpy as np\n", "\n", "from heat import BmiHeat" @@ -62,14 +61,14 @@ "metadata": {}, "outputs": [], "source": [ - "print(x.get_component_name())" + "x.get_component_name()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Start the `Heat` model through its BMI using a configuration file:" + "Start the *Heat* model through its BMI using a configuration file:" ] }, { @@ -78,7 +77,7 @@ "metadata": {}, "outputs": [], "source": [ - "cat heat.yaml" + "!cat heat.yaml" ] }, { @@ -193,8 +192,9 @@ "outputs": [], "source": [ "temperature = np.zeros(shape)\n", - "temperature[3, 4] = 100.0\n", - "x.set_value(\"plate_surface__temperature\", temperature)" + "temperature[tuple(shape//2)] = 100.0\n", + "temperature_flat = temperature.flatten()\n", + "x.set_value(\"plate_surface__temperature\", temperature_flat)" ] }, { @@ -268,7 +268,7 @@ "metadata": {}, "outputs": [], "source": [ - "distant_time = 2.0\n", + "distant_time = 10 * x.get_time_step()\n", "while x.get_current_time() < distant_time:\n", " x.update()" ] diff --git a/examples/run-model.ipynb b/examples/run-model.ipynb index 0a38d2e..ac9d352 100644 --- a/examples/run-model.ipynb +++ b/examples/run-model.ipynb @@ -4,21 +4,21 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Run the `Heat` model" + "# Run the *Heat* model" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "`Heat` models the diffusion of temperature on a uniform rectangular plate with Dirichlet boundary conditions. View the [source code](https://github.com/csdms/bmi-example-python/blob/master/heat/heat.py) for the model on GitHub." + "*Heat* models the diffusion of temperature on a uniform rectangular plate with Dirichlet boundary conditions. View the [source code](https://github.com/csdms/bmi-example-python/blob/master/heat/heat.py) for the model on GitHub." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Start by importing `numpy` and `Heat`:" + "Start by importing *numpy* and *Heat*:" ] }, { @@ -35,7 +35,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Create an instance of the model, setting `shape` and `alpha` parameters:" + "Create an instance of the model, setting the `shape` and `alpha` parameters:" ] }, { @@ -71,7 +71,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "What does the initial temperature field look like?" + "Zero out the initial temperature field:" ] }, { @@ -97,7 +97,7 @@ "metadata": {}, "outputs": [], "source": [ - "m.temperature[3, 4] = 100.0\n", + "m.temperature[n_rows//2, n_cols//2] = 100.0\n", "print(m.temperature)" ] }, @@ -153,7 +153,7 @@ "metadata": {}, "outputs": [], "source": [ - "distant_time = 2.0\n", + "distant_time = 10 * m.time_step\n", "while m.time < distant_time:\n", " m.advance_in_time()" ] @@ -162,7 +162,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "View the new state of the temperature field (with help from `np.set_printoptions`):" + "View the new state of the temperature field (with help from *np.set_printoptions*):" ] }, { @@ -179,7 +179,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Note that temperature is set to zero at the boundaries." + "Note that temperature is set to zero at the boundaries, so it's not conserved on the plate:" ] }, { From 5d89a4e8170334aac02107690c26089b5dfba2aa Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Thu, 17 Oct 2024 15:44:41 -0600 Subject: [PATCH 3/8] Update ruff setting --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index fd4dac2..a28988f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -93,7 +93,7 @@ line_length = 88 [tool.ruff] line-length = 88 -ignore = [ +lint.ignore = [ "E203", "E501", ] From cb1f9b003762a01c2944af7513879ae750a46f31 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Thu, 17 Oct 2024 15:44:52 -0600 Subject: [PATCH 4/8] Make pretty --- heat/__init__.py | 1 + heat/bmi_heat.py | 1 - heat/heat.py | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/heat/__init__.py b/heat/__init__.py index 20911f3..18a6399 100644 --- a/heat/__init__.py +++ b/heat/__init__.py @@ -1,4 +1,5 @@ """Model the diffusion of heat over a 2D plate.""" + from ._version import __version__ from .bmi_heat import BmiHeat from .heat import Heat, solve_2d diff --git a/heat/bmi_heat.py b/heat/bmi_heat.py index 310855a..54dc81f 100644 --- a/heat/bmi_heat.py +++ b/heat/bmi_heat.py @@ -8,7 +8,6 @@ class BmiHeat(Bmi): - """Solve the heat equation for a 2D plate.""" _name = "The 2D Heat Equation" diff --git a/heat/heat.py b/heat/heat.py index e940511..aed5eb2 100644 --- a/heat/heat.py +++ b/heat/heat.py @@ -54,7 +54,6 @@ def solve_2d(temp, spacing, out=None, alpha=1.0, time_step=1.0): class Heat(object): - """Solve the Heat equation on a grid. Examples From 104dbccdb219f50f1b24b731603e63eef3ceb30d Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Thu, 17 Oct 2024 15:52:37 -0600 Subject: [PATCH 5/8] Use Miniforge in place of Mambaforge Mambaforge is being retired: https://conda-forge.org/news/2024/07/29/sunsetting-mambaforge/. --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f6df638..f148768 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,7 +27,6 @@ jobs: - uses: conda-incubator/setup-miniconda@v3 with: - miniforge-variant: Mambaforge miniforge-version: latest python-version: ${{ matrix.python-version }} @@ -38,7 +37,7 @@ jobs: - name: Install requirements run: | - mamba install --file=requirements.txt --file=requirements-testing.txt + conda install --file=requirements.txt --file=requirements-testing.txt - name: Build and install package run: pip install -e . From f1c9fe6b192a3f953a553e79274ce151e4900fd1 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Thu, 17 Oct 2024 15:59:29 -0600 Subject: [PATCH 6/8] Drop Python 3.9, add 3.13 --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f148768..b8c6a7d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v4 From b8a3618ef80acbb79b6eeedde0e2e2f31b5a9e28 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Thu, 17 Oct 2024 16:17:35 -0600 Subject: [PATCH 7/8] Also update Python version information in metadata --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a28988f..dddcf85 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,14 +26,14 @@ classifiers = [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Scientific/Engineering :: Physics", ] -requires-python = ">=3.9" +requires-python = ">=3.10" dependencies = [ "numpy", "scipy", From bd09d7958a5400efe75ece9eab43748679183ea9 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Thu, 17 Oct 2024 16:18:21 -0600 Subject: [PATCH 8/8] Use absolute path to working directory with bmi_tester --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b8c6a7d..c64dd2f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -45,7 +45,7 @@ jobs: - name: Test run: | pytest --cov=heat --cov-report=xml:./coverage.xml -vvv - bmi-test heat:BmiHeat --config-file=./examples/heat.yaml --root-dir=./examples -vvv + bmi-test heat:BmiHeat --config-file=${GITHUB_WORKSPACE}/examples/heat.yaml --root-dir=examples -vvv - name: Coveralls if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'