Skip to content

Commit 8d0c325

Browse files
committed
misc: Lint some notebooks
1 parent 53f3371 commit 8d0c325

18 files changed

Lines changed: 392 additions & 219 deletions

examples/.ruff.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Extend the `pyproject.toml` file in the parent directory
2+
extend = "../pyproject.toml"
3+
4+
# Use a different line length for examples only
5+
# TODO: Shorten line lengths in examples
6+
line-length = 120

examples/cfd/01_convection.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"# Repeat initialisation, so we can re-run the cell\n",
110110
"init_hat(field=u, dx=dx, dy=dy, value=2.)\n",
111111
"\n",
112-
"for n in range(nt + 1):\n",
112+
"for _ in range(nt + 1):\n",
113113
" # Copy previous result into a new buffer\n",
114114
" un = u.copy()\n",
115115
"\n",
@@ -122,7 +122,8 @@
122122
" u[-1, :] = 1. # right\n",
123123
" u[:, 0] = 1. # bottom\n",
124124
" u[:, -1] = 1. # top\n",
125-
" # Note that in the above expressions the NumPy index -1 corresponds to the final point of the array along the indexed dimension,\n",
125+
" # Note that in the above expressions the NumPy index -1 corresponds to the\n",
126+
" # final point of the array along the indexed dimension,\n",
126127
" # i.e. here u[-1, :] is equivalent to u[80, :].\n"
127128
]
128129
},

examples/cfd/01_convection_revisited.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"# Repeat initialisation, so we can re-run the cell\n",
104104
"init_smooth(field=u, dx=dx, dy=dy)\n",
105105
"\n",
106-
"for n in range(nt + 1):\n",
106+
"for _ in range(nt + 1):\n",
107107
" # Copy previous result into a new buffer\n",
108108
" un = u.copy()\n",
109109
"\n",

examples/cfd/02_convection_nonlinear.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
],
111111
"source": [
112112
"# NBVAL_IGNORE_OUTPUT\n",
113-
"for n in range(nt + 1): # loop across number of time steps\n",
113+
"for _ in range(nt + 1): # loop across number of time steps\n",
114114
" un = u.copy()\n",
115115
" vn = v.copy()\n",
116116
" u[1:, 1:] = (un[1:, 1:] -\n",

examples/cfd/03_diffusion.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"outputs": [],
5858
"source": [
5959
"def diffuse(u, nt):\n",
60-
" for n in range(nt + 1):\n",
60+
" for _ in range(nt + 1):\n",
6161
" un = u.copy()\n",
6262
" u[1:-1, 1:-1] = (un[1:-1, 1:-1] +\n",
6363
" nu * dt / dy**2 * (un[1:-1, 2:] - 2 * un[1:-1, 1:-1] + un[1:-1, 0:-2]) +\n",

examples/cfd/03_diffusion_nonuniform.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"outputs": [],
8181
"source": [
8282
"def diffuse(u, nt, visc):\n",
83-
" for n in range(nt + 1):\n",
83+
" for _ in range(nt + 1):\n",
8484
" un = u.copy()\n",
8585
" u[1:-1, 1:-1] = (un[1:-1, 1:-1] +\n",
8686
" visc*dt / dy**2 * (un[1:-1, 2:] - 2 * un[1:-1, 1:-1] + un[1:-1, 0:-2]) +\n",
@@ -257,7 +257,6 @@
257257
],
258258
"source": [
259259
"from devito import Grid, TimeFunction, Eq, solve, Function\n",
260-
"from sympy.abc import a\n",
261260
"\n",
262261
"# Initialize `u` for space order 2\n",
263262
"grid = Grid(shape=(nx, ny), extent=(2., 2.))\n",

examples/cfd/06_poisson.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"source": [
8282
"%%time\n",
8383
"# NBVAL_IGNORE_OUTPUT\n",
84-
"for it in range(nt):\n",
84+
"for _ in range(nt):\n",
8585
" pd = p.copy()\n",
8686
" p[1:-1, 1:-1] = (((pd[1:-1, 2:] + pd[1:-1, :-2]) * dy**2 +\n",
8787
" (pd[2:, 1:-1] + pd[:-2, 1:-1]) * dx**2 -\n",

examples/cfd/07_cavity_flow.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176
" pn = np.empty_like(p)\n",
177177
" pn = p.copy()\n",
178178
"\n",
179-
" for q in range(nit):\n",
179+
" for _ in range(nit):\n",
180180
" pn = p.copy()\n",
181181
" p[1:-1, 1:-1] = (((pn[2:, 1:-1] + pn[0:-2, 1:-1]) * dy**2 +\n",
182182
" (pn[1:-1, 2:] + pn[1:-1, 0:-2]) * dx**2) /\n",
@@ -211,7 +211,7 @@
211211
" vn = np.empty_like(v)\n",
212212
" b = np.zeros((nx, ny))\n",
213213
"\n",
214-
" for n in range(0, nt):\n",
214+
" for _ in range(0, nt):\n",
215215
" un = u.copy()\n",
216216
" vn = v.copy()\n",
217217
"\n",

examples/cfd/08_shallow_water_equation.ipynb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
" Operator that solves the equations expressed above.\n",
9191
" It computes and returns the discharge fluxes M, N and wave height eta from\n",
9292
" the 2D Shallow water equation using the FTCS finite difference method.\n",
93-
" \n",
93+
"\n",
9494
" Parameters\n",
9595
" ----------\n",
9696
" eta : TimeFunction\n",
@@ -113,15 +113,18 @@
113113
" animations.\n",
114114
" \"\"\"\n",
115115
"\n",
116-
" eps = np.finfo(grid.dtype).eps\n",
116+
" # eps = np.finfo(grid.dtype).eps\n",
117117
"\n",
118118
" # Friction term expresses the loss of amplitude from the friction with the seafloor\n",
119119
" frictionTerm = g * alpha**2 * sqrt(M**2 + N**2) / D**(7./3.)\n",
120120
"\n",
121121
" # System of equations\n",
122122
" pde_eta = Eq(eta.dt + M.dxc + N.dyc)\n",
123123
" pde_M = Eq(M.dt + (M**2/D).dxc + (M*N/D).dyc + g*D*eta.forward.dxc + frictionTerm*M)\n",
124-
" pde_N = Eq(N.dt + (M.forward*N/D).dxc + (N**2/D).dyc + g*D*eta.forward.dyc + g * alpha**2 * sqrt(M.forward**2 + N**2) / D**(7./3.)*N)\n",
124+
" pde_N = Eq(\n",
125+
" N.dt + (M.forward*N/D).dxc + (N**2/D).dyc + g*D*eta.forward.dyc\n",
126+
" + g * alpha**2 * sqrt(M.forward**2 + N**2) / D**(7./3.)*N\n",
127+
" )\n",
125128
"\n",
126129
" stencil_eta = solve(pde_eta, eta.forward)\n",
127130
" stencil_M = solve(pde_M, M.forward)\n",

examples/cfd/09_Darcy_flow_equation.ipynb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
" self.sqrt_eig[0, 0] = 0.0\n",
110110
"\n",
111111
" self.size = []\n",
112-
" for j in range(self.dim):\n",
112+
" for _ in range(self.dim):\n",
113113
" self.size.append(size)\n",
114114
"\n",
115115
" self.size = tuple(self.size)\n",
@@ -365,8 +365,8 @@
365365
"'''\n",
366366
"Function to generate 'u' from 'a' using Devito\n",
367367
"\n",
368-
"parameters \n",
369-
"-----------------\n",
368+
"Parameters\n",
369+
"----------\n",
370370
"perm: Array of size (s, s)\n",
371371
" This is \"a\"\n",
372372
"f: Array of size (s, s)\n",
@@ -375,7 +375,6 @@
375375
"\n",
376376
"\n",
377377
"def darcy_flow_2d(perm, f):\n",
378-
"\n",
379378
" # a(x) is the coefficients\n",
380379
" # f is the forcing function\n",
381380
" # initialize a, f with inputs permeability and forcing\n",

0 commit comments

Comments
 (0)