Skip to content

Commit 45353d5

Browse files
committed
Minor fixes
1 parent 174c7a7 commit 45353d5

File tree

3 files changed

+52
-53
lines changed

3 files changed

+52
-53
lines changed

examples/trajectory_io.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
eq = pde.PDE({"s": "-0.1 * s", "v": "-v"})
1919

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

23-
# run a simulation and write the results
24-
writer = pde.FileStorage(path.name, write_mode="truncate")
25-
eq.solve(state, t_range=32, dt=0.01, tracker=writer.tracker(1))
26-
27-
# read the simulation back in again
28-
reader = pde.FileStorage(path.name, write_mode="read_only")
29-
pde.plot_kymographs(reader)
26+
# read the simulation back in again
27+
reader = pde.FileStorage(path.name, write_mode="read_only")
28+
pde.plot_kymographs(reader)

pde/tools/docstrings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import re
1616
import textwrap
1717
from functools import partial
18-
from typing import TypeVar
18+
from typing import Callable, TypeVar
1919

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

123123

124-
TFunc = TypeVar("TFunc")
124+
TFunc = TypeVar("TFunc", bound=Callable)
125125

126126

127127
def replace_in_docstring(

tests/_notebooks/Test PlotTracker for different backend.ipynb

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
},
5252
{
5353
"cell_type": "code",
54-
"execution_count": 4,
54+
"execution_count": null,
5555
"metadata": {},
5656
"outputs": [
5757
{
@@ -78,18 +78,18 @@
7878
],
7979
"source": [
8080
"eq = pde.DiffusionPDE()\n",
81-
"movie_file = tempfile.NamedTemporaryFile(delete=False, suffix=\".mov\").name\n",
82-
"plot_tracker = pde.PlotTracker(\n",
83-
" 0.1, title=\"Visible – {time:.2g}\", show=True, movie=movie_file\n",
84-
")\n",
85-
"_, info = eq.solve(\n",
86-
" field,\n",
87-
" t_range=2,\n",
88-
" dt=0.1,\n",
89-
" backend=\"numpy\",\n",
90-
" ret_info=True,\n",
91-
" tracker=[\"progress\", plot_tracker],\n",
92-
")"
81+
"with tempfile.NamedTemporaryFile(delete=False, suffix=\".mov\") as movie_file:\n",
82+
" plot_tracker = pde.PlotTracker(\n",
83+
" 0.1, title=\"Visible – {time:.2g}\", show=True, movie=movie_file.name\n",
84+
" )\n",
85+
" _, info = eq.solve(\n",
86+
" field,\n",
87+
" t_range=2,\n",
88+
" dt=0.1,\n",
89+
" backend=\"numpy\",\n",
90+
" ret_info=True,\n",
91+
" tracker=[\"progress\", plot_tracker],\n",
92+
" )"
9393
]
9494
},
9595
{
@@ -144,7 +144,7 @@
144144
},
145145
{
146146
"cell_type": "code",
147-
"execution_count": 8,
147+
"execution_count": null,
148148
"metadata": {},
149149
"outputs": [
150150
{
@@ -164,18 +164,18 @@
164164
],
165165
"source": [
166166
"eq = pde.DiffusionPDE()\n",
167-
"movie_file = tempfile.NamedTemporaryFile(delete=False, suffix=\".mov\").name\n",
168-
"plot_tracker = pde.PlotTracker(\n",
169-
" 0.1, title=\"Hidden – {time:.2g}\", show=False, movie=movie_file\n",
170-
")\n",
171-
"_, info = eq.solve(\n",
172-
" field,\n",
173-
" t_range=2,\n",
174-
" dt=0.1,\n",
175-
" backend=\"numpy\",\n",
176-
" ret_info=True,\n",
177-
" tracker=[\"progress\", plot_tracker],\n",
178-
")"
167+
"with tempfile.NamedTemporaryFile(delete=False, suffix=\".mov\") as movie_file:\n",
168+
" plot_tracker = pde.PlotTracker(\n",
169+
" 0.1, title=\"Hidden – {time:.2g}\", show=False, movie=movie_file.name\n",
170+
" )\n",
171+
" _, info = eq.solve(\n",
172+
" field,\n",
173+
" t_range=2,\n",
174+
" dt=0.1,\n",
175+
" backend=\"numpy\",\n",
176+
" ret_info=True,\n",
177+
" tracker=[\"progress\", plot_tracker],\n",
178+
" )"
179179
]
180180
},
181181
{
@@ -236,7 +236,7 @@
236236
},
237237
{
238238
"cell_type": "code",
239-
"execution_count": 12,
239+
"execution_count": null,
240240
"metadata": {},
241241
"outputs": [
242242
{
@@ -263,22 +263,22 @@
263263
],
264264
"source": [
265265
"eq = pde.PDE({\"a\": \"laplace(a)\", \"b\": \"laplace(b)\"})\n",
266-
"movie_file = tempfile.NamedTemporaryFile(delete=False, suffix=\".mov\").name\n",
267-
"plot_tracker = pde.PlotTracker(\n",
268-
" 0.5,\n",
269-
" title=\"Visible Plot Collection – {time:.2g}\",\n",
270-
" show=True,\n",
271-
" movie=movie_file,\n",
272-
" plot_args={\"colorbar\": True},\n",
273-
")\n",
274-
"_, info = eq.solve(\n",
275-
" fc,\n",
276-
" t_range=2,\n",
277-
" dt=0.1,\n",
278-
" backend=\"numpy\",\n",
279-
" ret_info=True,\n",
280-
" tracker=[\"progress\", plot_tracker],\n",
281-
")"
266+
"with tempfile.NamedTemporaryFile(delete=False, suffix=\".mov\") as movie_file:\n",
267+
" plot_tracker = pde.PlotTracker(\n",
268+
" 0.5,\n",
269+
" title=\"Visible Plot Collection – {time:.2g}\",\n",
270+
" show=True,\n",
271+
" movie=movie_file.name,\n",
272+
" plot_args={\"colorbar\": True},\n",
273+
" )\n",
274+
" _, info = eq.solve(\n",
275+
" fc,\n",
276+
" t_range=2,\n",
277+
" dt=0.1,\n",
278+
" backend=\"numpy\",\n",
279+
" ret_info=True,\n",
280+
" tracker=[\"progress\", plot_tracker],\n",
281+
" )"
282282
]
283283
},
284284
{

0 commit comments

Comments
 (0)