diff --git a/ui-tests/notebooks/Lorenz.ipynb b/ui-tests/notebooks/Lorenz.ipynb index d557ea49..55408189 100644 --- a/ui-tests/notebooks/Lorenz.ipynb +++ b/ui-tests/notebooks/Lorenz.ipynb @@ -1,155 +1,249 @@ { - "metadata": { - "kernelspec": { - "name": "xpython (env-python)", - "display_name": "Python 3.13 (XPython) [env-python]", - "language": "python" - }, - "language_info": { - "codemirror_mode": { - "name": "python", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8" - } - }, - "nbformat_minor": 4, - "nbformat": 4, "cells": [ { "cell_type": "markdown", - "source": "# The Lorenz Differential Equations", - "metadata": {} + "metadata": {}, + "source": [ + "# The Lorenz Differential Equations" + ] }, { "cell_type": "markdown", - "source": "Before we start, we import some preliminary libraries.", - "metadata": {} + "metadata": {}, + "source": [ + "Before we start, we import some preliminary libraries." + ] }, { "cell_type": "code", - "source": "import numpy as np\nfrom matplotlib import pyplot as plt\nfrom scipy import integrate\n\nfrom ipywidgets import interactive", + "execution_count": null, "metadata": { "trusted": true }, "outputs": [], - "execution_count": null + "source": [ + "import numpy as np\n", + "from matplotlib import pyplot as plt\n", + "from scipy import integrate\n", + "\n", + "from ipywidgets import interactive" + ] }, { "cell_type": "markdown", - "source": "We will also define the actual solver and plotting routine.", - "metadata": {} + "metadata": {}, + "source": [ + "We will also define the actual solver and plotting routine." + ] }, { "cell_type": "code", - "source": "def solve_lorenz(sigma=10.0, beta=8./3, rho=28.0):\n \"\"\"Plot a solution to the Lorenz differential equations.\"\"\"\n\n max_time = 4.0\n N = 30\n\n fig = plt.figure(1)\n ax = fig.add_axes([0, 0, 1, 1], projection='3d')\n ax.axis('off')\n\n # prepare the axes limits\n ax.set_xlim((-25, 25))\n ax.set_ylim((-35, 35))\n ax.set_zlim((5, 55))\n\n def lorenz_deriv(x_y_z, t0, sigma=sigma, beta=beta, rho=rho):\n \"\"\"Compute the time-derivative of a Lorenz system.\"\"\"\n x, y, z = x_y_z\n return [sigma * (y - x), x * (rho - z) - y, x * y - beta * z]\n\n # Choose random starting points, uniformly distributed from -15 to 15\n np.random.seed(1)\n x0 = -15 + 30 * np.random.random((N, 3))\n\n # Solve for the trajectories\n t = np.linspace(0, max_time, int(250*max_time))\n x_t = np.asarray([integrate.odeint(lorenz_deriv, x0i, t)\n for x0i in x0])\n\n # choose a different color for each trajectory\n colors = plt.cm.viridis(np.linspace(0, 1, N))\n\n for i in range(N):\n x, y, z = x_t[i,:,:].T\n lines = ax.plot(x, y, z, '-', c=colors[i])\n plt.setp(lines, linewidth=2)\n angle = 104\n ax.view_init(30, angle)\n plt.show()\n\n return t, x_t", + "execution_count": null, "metadata": { "trusted": true }, "outputs": [], - "execution_count": null + "source": [ + "def solve_lorenz(sigma=10.0, beta=8./3, rho=28.0):\n", + " \"\"\"Plot a solution to the Lorenz differential equations.\"\"\"\n", + "\n", + " max_time = 4.0\n", + " N = 30\n", + "\n", + " fig = plt.figure(1)\n", + " ax = fig.add_axes([0, 0, 1, 1], projection='3d')\n", + " ax.axis('off')\n", + "\n", + " # prepare the axes limits\n", + " ax.set_xlim((-25, 25))\n", + " ax.set_ylim((-35, 35))\n", + " ax.set_zlim((5, 55))\n", + "\n", + " def lorenz_deriv(x_y_z, t0, sigma=sigma, beta=beta, rho=rho):\n", + " \"\"\"Compute the time-derivative of a Lorenz system.\"\"\"\n", + " x, y, z = x_y_z\n", + " return [sigma * (y - x), x * (rho - z) - y, x * y - beta * z]\n", + "\n", + " # Choose random starting points, uniformly distributed from -15 to 15\n", + " np.random.seed(1)\n", + " x0 = -15 + 30 * np.random.random((N, 3))\n", + "\n", + " # Solve for the trajectories\n", + " t = np.linspace(0, max_time, int(250*max_time))\n", + " x_t = np.asarray([integrate.odeint(lorenz_deriv, x0i, t)\n", + " for x0i in x0])\n", + "\n", + " # choose a different color for each trajectory\n", + " colors = plt.cm.viridis(np.linspace(0, 1, N))\n", + "\n", + " for i in range(N):\n", + " x, y, z = x_t[i,:,:].T\n", + " lines = ax.plot(x, y, z, '-', c=colors[i])\n", + " plt.setp(lines, linewidth=2)\n", + " angle = 104\n", + " ax.view_init(30, angle)\n", + " plt.show()\n", + "\n", + " return t, x_t" + ] }, { "cell_type": "markdown", - "source": "We explore the Lorenz system of differential equations:\n\n$$\n\\begin{aligned}\n\\dot{x} & = \\sigma(y-x) \\\\\n\\dot{y} & = \\rho x - y - xz \\\\\n\\dot{z} & = -\\beta z + xy\n\\end{aligned}\n$$\n\nLet's change (\\\\(\\sigma\\\\), \\\\(\\beta\\\\), \\\\(\\rho\\\\)) with ipywidgets and examine the trajectories.", - "metadata": {} + "metadata": {}, + "source": [ + "We explore the Lorenz system of differential equations:\n", + "\n", + "$$\n", + "\\begin{aligned}\n", + "\\dot{x} & = \\sigma(y-x) \\\\\n", + "\\dot{y} & = \\rho x - y - xz \\\\\n", + "\\dot{z} & = -\\beta z + xy\n", + "\\end{aligned}\n", + "$$\n", + "\n", + "Let's change (\\\\(\\sigma\\\\), \\\\(\\beta\\\\), \\\\(\\rho\\\\)) with ipywidgets and examine the trajectories." + ] }, { "cell_type": "code", - "source": "w=interactive(solve_lorenz,sigma=(0.0,50.0),rho=(0.0,50.0))\nw", + "execution_count": null, "metadata": { "trusted": true }, "outputs": [], - "execution_count": null + "source": [ + "w=interactive(solve_lorenz,sigma=(0.0,50.0),rho=(0.0,50.0))\n", + "w" + ] }, { "cell_type": "markdown", - "source": "For the default set of parameters, we see the trajectories swirling around two points, called attractors. ", - "metadata": {} + "metadata": {}, + "source": [ + "For the default set of parameters, we see the trajectories swirling around two points, called attractors. " + ] }, { "cell_type": "markdown", - "source": "The object returned by `interactive` is a `Widget` object and it has attributes that contain the current result and arguments:", - "metadata": {} + "metadata": {}, + "source": [ + "The object returned by `interactive` is a `Widget` object and it has attributes that contain the current result and arguments:" + ] }, { "cell_type": "code", - "source": "t, x_t = w.result", + "execution_count": null, "metadata": { "trusted": true }, "outputs": [], - "execution_count": null + "source": [ + "t, x_t = w.result" + ] }, { "cell_type": "code", - "source": "w.kwargs", + "execution_count": null, "metadata": { "trusted": true }, "outputs": [], - "execution_count": null + "source": [ + "w.kwargs" + ] }, { "cell_type": "markdown", - "source": "After interacting with the system, we can take the result and perform further computations. In this case, we compute the average positions in \\\\(x\\\\), \\\\(y\\\\) and \\\\(z\\\\).", - "metadata": {} + "metadata": {}, + "source": [ + "After interacting with the system, we can take the result and perform further computations. In this case, we compute the average positions in \\\\(x\\\\), \\\\(y\\\\) and \\\\(z\\\\)." + ] }, { "cell_type": "code", - "source": "xyz_avg = x_t.mean(axis=1)", + "execution_count": null, "metadata": { "trusted": true }, "outputs": [], - "execution_count": null + "source": [ + "xyz_avg = x_t.mean(axis=1)" + ] }, { "cell_type": "code", - "source": "xyz_avg.shape", + "execution_count": null, "metadata": { "trusted": true }, "outputs": [], - "execution_count": null + "source": [ + "xyz_avg.shape" + ] }, { "cell_type": "markdown", - "source": "Creating histograms of the average positions (across different trajectories) show that, on average, the trajectories swirl about the attractors.", - "metadata": {} + "metadata": {}, + "source": [ + "Creating histograms of the average positions (across different trajectories) show that, on average, the trajectories swirl about the attractors." + ] }, { "cell_type": "code", - "source": "from matplotlib import pyplot as plt\n%matplotlib inline", + "execution_count": null, "metadata": { "trusted": true }, "outputs": [], - "execution_count": null + "source": [ + "from matplotlib import pyplot as plt\n", + "%matplotlib inline" + ] }, { "cell_type": "code", - "source": "plt.hist(xyz_avg[:,0])\nplt.title('Average $x(t)$');", + "execution_count": null, "metadata": { "trusted": true }, "outputs": [], - "execution_count": null + "source": [ + "plt.hist(xyz_avg[:,0])\n", + "plt.title('Average $x(t)$');" + ] }, { "cell_type": "code", - "source": "plt.hist(xyz_avg[:,1])\nplt.title('Average $y(t)$');", + "execution_count": null, "metadata": { "trusted": true }, "outputs": [], - "execution_count": null + "source": [ + "plt.hist(xyz_avg[:,1])\n", + "plt.title('Average $y(t)$');" + ] } - ] -} \ No newline at end of file + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3.13 (XPython) [env-python]", + "language": "python", + "name": "xpython (env-python)" + }, + "language_info": { + "codemirror_mode": { + "name": "python", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/ui-tests/notebooks/cpp.ipynb b/ui-tests/notebooks/cpp.ipynb index cde4e74f..92421f33 100644 --- a/ui-tests/notebooks/cpp.ipynb +++ b/ui-tests/notebooks/cpp.ipynb @@ -76,29 +76,6 @@ "std::cout << \"some output\" << std::endl;" ] }, - { - "cell_type": "code", - "execution_count": 2, - "id": "9622f20f-5925-4544-a97b-aada3a14209a", - "metadata": { - "trusted": true, - "vscode": { - "languageId": "c++" - } - }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "some error\n" - ] - } - ], - "source": [ - "std::cerr << \"some error\" << std::endl;" - ] - }, { "cell_type": "code", "execution_count": 3, diff --git a/ui-tests/notebooks/r.ipynb b/ui-tests/notebooks/r.ipynb index 8b7b5b1a..46627283 100644 --- a/ui-tests/notebooks/r.ipynb +++ b/ui-tests/notebooks/r.ipynb @@ -165,13 +165,6 @@ "## Plotting" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Some of the following R Code was pulled from https://www.datacamp.com/doc/r/graphics-with-ggplot2, and updated to use newer `ggplot2` APIs." - ] - }, { "cell_type": "code", "execution_count": null, @@ -413,30 +406,6 @@ "print(hsv_color)\n", "print(lab_color)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "trusted": true, - "vscode": { - "languageId": "r" - } - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "trusted": true, - "vscode": { - "languageId": "r" - } - }, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/ui-tests/tests/jupyterlite_xeus.spec.ts b/ui-tests/tests/jupyterlite_xeus.spec.ts index 15027c76..c6fcfa24 100644 --- a/ui-tests/tests/jupyterlite_xeus.spec.ts +++ b/ui-tests/tests/jupyterlite_xeus.spec.ts @@ -1,7 +1,21 @@ -import { test } from '@jupyterlab/galata'; +import { IJupyterLabPageFixture, test } from '@jupyterlab/galata'; import { expect } from '@playwright/test'; +async function runAndCheckNotebook( + page: IJupyterLabPageFixture, + notebook: string +) { + await page.notebook.open(notebook); + + await page.notebook.runCellByCell(); + + const stderrElements = page.locator( + '[data-mime-type="application/vnd.jupyter.stderr"]' + ); + await expect(stderrElements).toHaveCount(0); +} + test.describe('General Tests', () => { test.beforeEach(({ page }) => { page.setDefaultTimeout(600000); @@ -42,33 +56,20 @@ test.describe('General Tests', () => { test('xeus-cpp should execute code', async ({ page }) => { await page.goto('lab/index.html'); - let notebook = 'cpp.ipynb'; - - await page.notebook.open(notebook); - await page.notebook.runCellByCell(); - - notebook = 'cpp-third-party-libs.ipynb'; - - await page.notebook.open(notebook); - await page.notebook.runCellByCell(); + await runAndCheckNotebook(page, 'cpp.ipynb'); + await runAndCheckNotebook(page, 'cpp-third-party-libs.ipynb'); }); test('xeus-python should execute code', async ({ page }) => { await page.goto('lab/index.html'); - const notebook = 'Lorenz.ipynb'; - - await page.notebook.open(notebook); - await page.notebook.runCellByCell(); + await runAndCheckNotebook(page, 'Lorenz.ipynb'); }); test('xeus-r should execute code', async ({ page }) => { await page.goto('lab/index.html'); - const notebook = 'r.ipynb'; - - await page.notebook.open(notebook); - await page.notebook.runCellByCell(); + await runAndCheckNotebook(page, 'r.ipynb'); }); test('(Multi-kernels test) xeus-python from env-default should execute some code', async ({