Skip to content

Commit

Permalink
Minor fixes (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-zwicker authored Nov 9, 2024
1 parent 174c7a7 commit 42472f0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 53 deletions.
15 changes: 7 additions & 8 deletions examples/trajectory_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
eq = pde.PDE({"s": "-0.1 * s", "v": "-v"})

# get a temporary file to write data to
path = NamedTemporaryFile(suffix=".hdf5")
with NamedTemporaryFile(suffix=".hdf5") as path:
# run a simulation and write the results
writer = pde.FileStorage(path.name, write_mode="truncate")
eq.solve(state, t_range=32, dt=0.01, tracker=writer.tracker(1))

# run a simulation and write the results
writer = pde.FileStorage(path.name, write_mode="truncate")
eq.solve(state, t_range=32, dt=0.01, tracker=writer.tracker(1))

# read the simulation back in again
reader = pde.FileStorage(path.name, write_mode="read_only")
pde.plot_kymographs(reader)
# read the simulation back in again
reader = pde.FileStorage(path.name, write_mode="read_only")
pde.plot_kymographs(reader)
4 changes: 2 additions & 2 deletions pde/tools/docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import re
import textwrap
from functools import partial
from typing import TypeVar
from typing import Callable, TypeVar

DOCSTRING_REPLACEMENTS = {
# description of function arguments
Expand Down Expand Up @@ -121,7 +121,7 @@ def get_text_block(identifier: str) -> str:
return "".join(textwrap.dedent(raw_text))


TFunc = TypeVar("TFunc")
TFunc = TypeVar("TFunc", bound=Callable)


def replace_in_docstring(
Expand Down
86 changes: 43 additions & 43 deletions tests/_notebooks/Test PlotTracker for different backend.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -78,18 +78,18 @@
],
"source": [
"eq = pde.DiffusionPDE()\n",
"movie_file = tempfile.NamedTemporaryFile(delete=False, suffix=\".mov\").name\n",
"plot_tracker = pde.PlotTracker(\n",
" 0.1, title=\"Visible – {time:.2g}\", show=True, movie=movie_file\n",
")\n",
"_, info = eq.solve(\n",
" field,\n",
" t_range=2,\n",
" dt=0.1,\n",
" backend=\"numpy\",\n",
" ret_info=True,\n",
" tracker=[\"progress\", plot_tracker],\n",
")"
"with tempfile.NamedTemporaryFile(delete=False, suffix=\".mov\") as movie_file:\n",
" plot_tracker = pde.PlotTracker(\n",
" 0.1, title=\"Visible – {time:.2g}\", show=True, movie=movie_file.name\n",
" )\n",
" _, info = eq.solve(\n",
" field,\n",
" t_range=2,\n",
" dt=0.1,\n",
" backend=\"numpy\",\n",
" ret_info=True,\n",
" tracker=[\"progress\", plot_tracker],\n",
" )"
]
},
{
Expand Down Expand Up @@ -144,7 +144,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -164,18 +164,18 @@
],
"source": [
"eq = pde.DiffusionPDE()\n",
"movie_file = tempfile.NamedTemporaryFile(delete=False, suffix=\".mov\").name\n",
"plot_tracker = pde.PlotTracker(\n",
" 0.1, title=\"Hidden – {time:.2g}\", show=False, movie=movie_file\n",
")\n",
"_, info = eq.solve(\n",
" field,\n",
" t_range=2,\n",
" dt=0.1,\n",
" backend=\"numpy\",\n",
" ret_info=True,\n",
" tracker=[\"progress\", plot_tracker],\n",
")"
"with tempfile.NamedTemporaryFile(delete=False, suffix=\".mov\") as movie_file:\n",
" plot_tracker = pde.PlotTracker(\n",
" 0.1, title=\"Hidden – {time:.2g}\", show=False, movie=movie_file.name\n",
" )\n",
" _, info = eq.solve(\n",
" field,\n",
" t_range=2,\n",
" dt=0.1,\n",
" backend=\"numpy\",\n",
" ret_info=True,\n",
" tracker=[\"progress\", plot_tracker],\n",
" )"
]
},
{
Expand Down Expand Up @@ -236,7 +236,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -263,22 +263,22 @@
],
"source": [
"eq = pde.PDE({\"a\": \"laplace(a)\", \"b\": \"laplace(b)\"})\n",
"movie_file = tempfile.NamedTemporaryFile(delete=False, suffix=\".mov\").name\n",
"plot_tracker = pde.PlotTracker(\n",
" 0.5,\n",
" title=\"Visible Plot Collection – {time:.2g}\",\n",
" show=True,\n",
" movie=movie_file,\n",
" plot_args={\"colorbar\": True},\n",
")\n",
"_, info = eq.solve(\n",
" fc,\n",
" t_range=2,\n",
" dt=0.1,\n",
" backend=\"numpy\",\n",
" ret_info=True,\n",
" tracker=[\"progress\", plot_tracker],\n",
")"
"with tempfile.NamedTemporaryFile(delete=False, suffix=\".mov\") as movie_file:\n",
" plot_tracker = pde.PlotTracker(\n",
" 0.5,\n",
" title=\"Visible Plot Collection – {time:.2g}\",\n",
" show=True,\n",
" movie=movie_file.name,\n",
" plot_args={\"colorbar\": True},\n",
" )\n",
" _, info = eq.solve(\n",
" fc,\n",
" t_range=2,\n",
" dt=0.1,\n",
" backend=\"numpy\",\n",
" ret_info=True,\n",
" tracker=[\"progress\", plot_tracker],\n",
" )"
]
},
{
Expand Down

0 comments on commit 42472f0

Please sign in to comment.