diff --git a/docs/source/examples/Futures.ipynb b/docs/source/examples/Futures.ipynb index 6fab885f..0e0ab31e 100644 --- a/docs/source/examples/Futures.ipynb +++ b/docs/source/examples/Futures.ipynb @@ -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" ] @@ -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()" diff --git a/docs/source/examples/Monitoring an MPI Simulation - 1.ipynb b/docs/source/examples/Monitoring an MPI Simulation - 1.ipynb index ee0c6f4c..2b149205 100644 --- a/docs/source/examples/Monitoring an MPI Simulation - 1.ipynb +++ b/docs/source/examples/Monitoring an MPI Simulation - 1.ipynb @@ -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))" ] }, { @@ -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", @@ -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" ] }, @@ -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": { diff --git a/docs/source/examples/Monitoring an MPI Simulation - 2.ipynb b/docs/source/examples/Monitoring an MPI Simulation - 2.ipynb index 92252569..8c0c7d91 100644 --- a/docs/source/examples/Monitoring an MPI Simulation - 2.ipynb +++ b/docs/source/examples/Monitoring an MPI Simulation - 2.ipynb @@ -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))" ] }, { @@ -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", @@ -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": { diff --git a/docs/source/examples/Parallel Magics.ipynb b/docs/source/examples/Parallel Magics.ipynb index 0143d736..99bb1f8b 100644 --- a/docs/source/examples/Parallel Magics.ipynb +++ b/docs/source/examples/Parallel Magics.ipynb @@ -568,6 +568,7 @@ "source": [ "%%px\n", "import psutil\n", + "\n", "psutil.Process().nice(20 if psutil.POSIX else psutil.IDLE_PRIORITY_CLASS)" ] }, @@ -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" ] }, { @@ -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)" ] }, @@ -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)" ] }, @@ -3261,6 +3262,7 @@ "source": [ "%%px\n", "from numpy.random import random\n", + "\n", "A = random((100, 100, 'invalid shape'))" ] }, @@ -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)" ] }, { @@ -3469,6 +3471,7 @@ "source": [ "%%px --local\n", "import os\n", + "\n", "thispid = os.getpid()\n", "print(thispid)" ] diff --git a/docs/source/examples/Using MPI with IPython Parallel.ipynb b/docs/source/examples/Using MPI with IPython Parallel.ipynb index 983585b7..2ec9fded 100644 --- a/docs/source/examples/Using MPI with IPython Parallel.ipynb +++ b/docs/source/examples/Using MPI with IPython Parallel.ipynb @@ -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", diff --git a/docs/source/examples/broadcast/MPI Broadcast.ipynb b/docs/source/examples/broadcast/MPI Broadcast.ipynb index e35d6679..68ed7f09 100644 --- a/docs/source/examples/broadcast/MPI Broadcast.ipynb +++ b/docs/source/examples/broadcast/MPI Broadcast.ipynb @@ -248,7 +248,7 @@ } ], "source": [ - "%%time \n", + "%%time\n", "ar = eall.push({'data': data}, block=False)\n", "ar.wait_interactive()" ] @@ -2568,7 +2568,8 @@ "source": [ "%%px\n", "import numpy as np\n", - "np.linalg.norm(data, 2)\n" + "\n", + "np.linalg.norm(data, 2)" ] } ], @@ -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": { diff --git a/docs/source/examples/progress.ipynb b/docs/source/examples/progress.ipynb index 5133d854..90d72e89 100644 --- a/docs/source/examples/progress.ipynb +++ b/docs/source/examples/progress.ipynb @@ -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}\"" ] }, { @@ -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", @@ -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", diff --git a/docs/source/examples/rmt/rmt.ipynb b/docs/source/examples/rmt/rmt.ipynb index a11673d9..cf91587c 100644 --- a/docs/source/examples/rmt/rmt.ipynb +++ b/docs/source/examples/rmt/rmt.ipynb @@ -22,6 +22,7 @@ "metadata": {}, "outputs": [], "source": [ + "import matplotlib.pyplot as plt\n", "import numpy as np\n", "from rmtkernel import ensemble_diffs, normalize_diffs\n", "\n", @@ -48,12 +49,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": true, - "jupyter": { - "outputs_hidden": true - } - }, + "metadata": {}, "outputs": [], "source": [ "def wigner_dist(s):\n", @@ -64,12 +60,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": true, - "jupyter": { - "outputs_hidden": true - } - }, + "metadata": {}, "outputs": [], "source": [ "def generate_wigner_data():\n", @@ -111,9 +102,9 @@ } ], "source": [ - "plot(s, rhos)\n", - "xlabel('Normalized level spacing s')\n", - "ylabel('Probability $\\rho(s)$')" + "plt.plot(s, rhos)\n", + "plt.xlabel('Normalized level spacing s')\n", + "plt.ylabel('Probability $\\rho(s)$')" ] }, { @@ -134,12 +125,7 @@ { "cell_type": "code", "execution_count": 6, - "metadata": { - "collapsed": true, - "jupyter": { - "outputs_hidden": true - } - }, + "metadata": {}, "outputs": [], "source": [ "def serial_diffs(num, N):\n", @@ -152,12 +138,7 @@ { "cell_type": "code", "execution_count": 7, - "metadata": { - "collapsed": true, - "jupyter": { - "outputs_hidden": true - } - }, + "metadata": {}, "outputs": [], "source": [ "serial_nmats = 1000\n", @@ -222,10 +203,10 @@ } ], "source": [ - "hist_data = hist(serial_diffs, bins=30, normed=True)\n", - "plot(s, rhos)\n", - "xlabel('Normalized level spacing s')\n", - "ylabel('Probability $P(s)$')" + "hist_data = plt.hist(serial_diffs, bins=30, normed=True)\n", + "plt.plot(s, rhos)\n", + "plt.xlabel('Normalized level spacing s')\n", + "plt.ylabel('Probability $P(s)$')" ] }, { @@ -246,12 +227,7 @@ { "cell_type": "code", "execution_count": 11, - "metadata": { - "collapsed": true, - "jupyter": { - "outputs_hidden": true - } - }, + "metadata": {}, "outputs": [], "source": [ "def parallel_diffs(rc, num, N):\n", @@ -267,12 +243,7 @@ { "cell_type": "code", "execution_count": 12, - "metadata": { - "collapsed": true, - "jupyter": { - "outputs_hidden": true - } - }, + "metadata": {}, "outputs": [], "source": [ "client = ipp.Client()\n", @@ -284,12 +255,7 @@ { "cell_type": "code", "execution_count": 13, - "metadata": { - "collapsed": true, - "jupyter": { - "outputs_hidden": true - } - }, + "metadata": {}, "outputs": [], "source": [ "parallel_nmats = 40 * serial_nmats\n", diff --git a/docs/source/examples/visualizing-tasks.ipynb b/docs/source/examples/visualizing-tasks.ipynb index 5ef28ecf..93273b39 100644 --- a/docs/source/examples/visualizing-tasks.ipynb +++ b/docs/source/examples/visualizing-tasks.ipynb @@ -304,16 +304,17 @@ } ], "source": [ - "y = df.engine_id\n", - "x = df.started\n", - "width = df.completed\n", - "height = np.ones(len(df))\n", - "\n", "import matplotlib as mpl\n", + "import numpy as np\n", "from matplotlib import cm\n", "from matplotlib.collections import PatchCollection\n", "from matplotlib.patches import Rectangle\n", "\n", + "y = df.engine_id\n", + "x = df.started\n", + "width = df.completed\n", + "height = np.ones(len(df))\n", + "\n", "color_map = mpl.cm.ScalarMappable(\n", " norm=mpl.colors.Normalize(vmin=0, vmax=df.compute.max()),\n", " cmap=cm.viridis,\n", @@ -633,7 +634,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.6" + "version": "3.11.9" }, "widgets": { "application/vnd.jupyter.widget-state+json": { diff --git a/pyproject.toml b/pyproject.toml index d91cb886..1578d50b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -144,7 +144,7 @@ filterwarnings = [ [tool.nbqa.process_cells] # handle %px cell magics -# it's still going to get confused about imports +# it's still going to get confused about which imports are local "ruff format" = [ "px", ] @@ -175,6 +175,11 @@ select = [ [tool.ruff.lint.per-file-ignores] "**/tests/**" = ["F841", "E741", "F401"] "**/__init__.py" = ["I", "F4"] +# for nbqa, these should be *nbqa_ipynb.py +# after https://github.com/nbQA-dev/nbQA/pull/870 +"docs/source/examples/**" = [ + "F704" # top-level await is valid in IPython +] [tool.tbump]