Skip to content

Commit

Permalink
run ruff via nbqa on examples
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Oct 29, 2024
1 parent c08f9ea commit 05dc87c
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 88 deletions.
3 changes: 1 addition & 2 deletions docs/source/examples/Futures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"%%px --local --block\n",
"import os\n",
"import time\n",
"\n",
"import numpy as np\n",
"from numpy.linalg import norm"
]
Expand Down Expand Up @@ -186,8 +187,6 @@
}
],
"source": [
"import os\n",
"\n",
"f = rc[-1].apply(os.getpid)\n",
"f.add_done_callback(lambda _: print(\"I got PID: %i\" % _.result()))\n",
"f.result()"
Expand Down
14 changes: 8 additions & 6 deletions docs/source/examples/Monitoring an MPI Simulation - 1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@
"source": [
"%%px --block\n",
"# MPI initialization, library imports and sanity checks on all engines\n",
"from mpi4py import MPI\n",
"import numpy as np\n",
"import time\n",
"\n",
"from mpi4py import MPI\n",
"\n",
"mpi = MPI.COMM_WORLD\n",
"bcast = mpi.bcast\n",
"barrier = mpi.barrier\n",
"rank = mpi.rank\n",
"print(\"MPI rank: %i/%i\" % (mpi.rank,mpi.size))"
"print(\"MPI rank: %i/%i\" % (mpi.rank, mpi.size))"
]
},
{
Expand Down Expand Up @@ -229,7 +229,7 @@
" )\n",
" X, Y = np.meshgrid(Xax, Yax)\n",
" f = freqs[j]\n",
" Z = np.cos(f * (X ** 2 + Y ** 2))\n",
" Z = np.cos(f * (X**2 + Y**2))\n",
" # We add a small delay to simulate that a real-world computation\n",
" # would take much longer, and we ensure all nodes are synchronized\n",
" time.sleep(delay)\n",
Expand Down Expand Up @@ -533,7 +533,9 @@
],
"source": [
"%%px --target 0 --block\n",
"from ipyparallel import bind_kernel; bind_kernel()\n",
"from ipyparallel import bind_kernel\n",
"\n",
"bind_kernel()\n",
"%connect_info"
]
},
Expand Down Expand Up @@ -564,7 +566,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
"version": "3.11.9"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
Expand Down
11 changes: 6 additions & 5 deletions docs/source/examples/Monitoring an MPI Simulation - 2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,18 @@
"source": [
"%%px --block\n",
"# MPI initialization, library imports and sanity checks on all engines\n",
"import time\n",
"\n",
"from mpi4py import MPI\n",
"\n",
"# Load data publication API so engines can send data to notebook client\n",
"from ipyparallel.datapub import publish_data\n",
"import numpy as np\n",
"import time\n",
"\n",
"mpi = MPI.COMM_WORLD\n",
"bcast = mpi.bcast\n",
"barrier = mpi.barrier\n",
"rank = mpi.rank\n",
"print(\"MPI rank: %i/%i\" % (mpi.rank,mpi.size))"
"print(\"MPI rank: %i/%i\" % (mpi.rank, mpi.size))"
]
},
{
Expand Down Expand Up @@ -196,7 +197,7 @@
" )\n",
" X, Y = np.meshgrid(Xax, Yax)\n",
" f = freqs[j]\n",
" Z = np.cos(f * (X ** 2 + Y ** 2))\n",
" Z = np.cos(f * (X**2 + Y**2))\n",
"\n",
" # We are now going to publish data to the clients. We take advantage of fast\n",
" # MPI communications and gather the Z mesh at the rank 0 node in the Zcat variable:\n",
Expand Down Expand Up @@ -419,7 +420,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
"version": "3.11.9"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
Expand Down
23 changes: 13 additions & 10 deletions docs/source/examples/Parallel Magics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@
"source": [
"%%px\n",
"import psutil\n",
"\n",
"psutil.Process().nice(20 if psutil.POSIX else psutil.IDLE_PRIORITY_CLASS)"
]
},
Expand All @@ -578,8 +579,8 @@
"outputs": [],
"source": [
"%%px\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
"import matplotlib.pyplot as plt\n",
"import numpy as np"
]
},
{
Expand Down Expand Up @@ -619,10 +620,10 @@
],
"source": [
"%%px --noblock\n",
"x = np.linspace(0,np.pi,1000)\n",
"for n in range(id,12, stride):\n",
"x = np.linspace(0, np.pi, 1000)\n",
"for n in range(id, 12, stride):\n",
" print(n)\n",
" plt.plot(x,np.sin(n*x))\n",
" plt.plot(x, np.sin(n * x))\n",
"plt.title(\"Plot %i\" % id)"
]
},
Expand Down Expand Up @@ -1318,11 +1319,11 @@
],
"source": [
"%%px --group-outputs=engine\n",
"x = np.linspace(0,np.pi,1000)\n",
"for n in range(id+1,12, stride):\n",
"x = np.linspace(0, np.pi, 1000)\n",
"for n in range(id + 1, 12, stride):\n",
" print(n)\n",
" plt.figure()\n",
" plt.plot(x,np.sin(n*x))\n",
" plt.plot(x, np.sin(n * x))\n",
" plt.title(\"Plot %i\" % n)"
]
},
Expand Down Expand Up @@ -3261,6 +3262,7 @@
"source": [
"%%px\n",
"from numpy.random import random\n",
"\n",
"A = random((100, 100, 'invalid shape'))"
]
},
Expand Down Expand Up @@ -3343,10 +3345,10 @@
"source": [
"%%px\n",
"import time\n",
"\n",
"if rank == 0:\n",
" raise RuntimeError(\"rank 0 failed!\")\n",
"time.sleep(10)\n",
" "
"time.sleep(10)"
]
},
{
Expand Down Expand Up @@ -3469,6 +3471,7 @@
"source": [
"%%px --local\n",
"import os\n",
"\n",
"thispid = os.getpid()\n",
"print(thispid)"
]
Expand Down
6 changes: 3 additions & 3 deletions docs/source/examples/Using MPI with IPython Parallel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@
"rank = comm.Get_rank()\n",
"\n",
"if rank == 0:\n",
" data = [(i+1)**2 for i in range(size)]\n",
" data = [(i + 1) ** 2 for i in range(size)]\n",
"else:\n",
" data = None\n",
" data = None\n",
"data = comm.scatter(data, root=0)\n",
"\n",
"assert data == (rank+1)**2, 'data=%s, rank=%s' % (data, rank)\n",
"assert data == (rank + 1) ** 2, f'data={data}, rank={rank}'\n",
"{\n",
" 'data': data,\n",
" 'rank': rank,\n",
Expand Down
7 changes: 4 additions & 3 deletions docs/source/examples/broadcast/MPI Broadcast.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
}
],
"source": [
"%%time \n",
"%%time\n",
"ar = eall.push({'data': data}, block=False)\n",
"ar.wait_interactive()"
]
Expand Down Expand Up @@ -2568,7 +2568,8 @@
"source": [
"%%px\n",
"import numpy as np\n",
"np.linalg.norm(data, 2)\n"
"\n",
"np.linalg.norm(data, 2)"
]
}
],
Expand All @@ -2588,7 +2589,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
"version": "3.11.9"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
Expand Down
11 changes: 8 additions & 3 deletions docs/source/examples/progress.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -353,19 +353,22 @@
"n_steps = 10\n",
"\n",
"progress = W.IntProgress(max=n_steps, description=f\"rank {rank}: 0\")\n",
"\n",
"\n",
"def _set_color(change):\n",
" if change.new == progress.max:\n",
" progress.bar_style = \"success\"\n",
" else:\n",
" progress.bar_style = \"\"\n",
"\n",
"\n",
"progress.observe(_set_color, \"value\")\n",
"display(progress)\n",
"\n",
"for i in range(n_steps):\n",
" time.sleep(random.random())\n",
" progress.value += 1\n",
" progress.description = f\"rank {rank}: {progress.value}/{progress.max}\"\n",
"\n"
" progress.description = f\"rank {rank}: {progress.value}/{progress.max}\""
]
},
{
Expand Down Expand Up @@ -448,11 +451,13 @@
"\n",
"if rank == 0:\n",
" progress = W.IntProgress(max=n_steps, description=\"Step 0\")\n",
"\n",
" def _set_color(change):\n",
" if change.new == progress.max:\n",
" progress.bar_style = \"success\"\n",
" else:\n",
" progress.bar_style = \"\"\n",
"\n",
" progress.observe(_set_color, \"value\")\n",
" display(progress)\n",
"\n",
Expand Down Expand Up @@ -585,7 +590,7 @@
],
"source": [
"%%px\n",
"button = W.Button(description=f\"step\")\n",
"button = W.Button(description=\"step\")\n",
"progress = W.IntProgress(max=5, description=\"0 / 5\")\n",
"count = 0\n",
"\n",
Expand Down
Loading

0 comments on commit 05dc87c

Please sign in to comment.