Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/environment-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ channels:
- https://prefix.dev/conda-forge
dependencies:
- xeus-cpp
- symengine
3 changes: 2 additions & 1 deletion docs/environment-r.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: xeus-r-kernel-docs
channels:
- https://repo.mamba.pm/emscripten-forge
- https://prefix.dev/emscripten-forge-dev
- https://prefix.dev/conda-forge
dependencies:
- xeus-r
- r-ggplot2
35 changes: 9 additions & 26 deletions packages/xeus/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ export abstract class EmpackedXeusRemoteKernel extends XeusRemoteKernelBase {
}

// Load shared libs
await this._maybeLoadSharedLibs();
await loadSharedLibs({
sharedLibs: this._sharedLibs,
prefix: '/',
Module: this.Module,
logger: this.logger
});
}

/**
Expand Down Expand Up @@ -326,36 +331,14 @@ export abstract class EmpackedXeusRemoteKernel extends XeusRemoteKernelBase {
this._paths = { ...newPath, ...paths };
this._sharedLibs = sharedLibs;

await this._maybeLoadSharedLibs();

this._env = newEnv;
}

private async _maybeLoadSharedLibs() {
const toLoad: TSharedLibsMap = {};

// If we're running in the Python kernel, load all cpython shared libs beforehand,
// otherwise load everything but cpython shared libs
if (this._pythonVersion) {
for (const pkgName of Object.keys(this._sharedLibs)) {
toLoad[pkgName] = this._sharedLibs[pkgName].filter(sharedLib =>
sharedLib.includes('cpython-3')
);
}
} else {
for (const pkgName of Object.keys(this._sharedLibs)) {
toLoad[pkgName] = this._sharedLibs[pkgName].filter(
sharedLib => !sharedLib.includes('cpython-3')
);
}
}

await loadSharedLibs({
sharedLibs: toLoad,
sharedLibs: this._sharedLibs,
prefix: '/',
Module: this.Module,
logger: this.logger
});

this._env = newEnv;
}

private _pythonVersion: number[] | undefined;
Expand Down
2 changes: 1 addition & 1 deletion ui-tests/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import jupyterlab

extra_labextensions_path = str(Path(jupyterlab.__file__).parent / "galata")
cmd = f"jupyter lite build --FederatedExtensionAddon.extra_labextensions_path={extra_labextensions_path}"
cmd = f"jupyter lite build --contents notebooks --FederatedExtensionAddon.extra_labextensions_path={extra_labextensions_path}"

run(
cmd,
Expand Down
9 changes: 9 additions & 0 deletions ui-tests/env-cpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: env-cpp
channels:
- https://prefix.dev/emscripten-forge-dev
- https://prefix.dev/conda-forge
dependencies:
- xeus-cpp
- symengine
- xtensor-blas
- xsimd
2 changes: 1 addition & 1 deletion ui-tests/env2.yml → ui-tests/env-default.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: env2
name: env-default
channels:
- https://prefix.dev/emscripten-forge-dev
- https://prefix.dev/conda-forge
Expand Down
2 changes: 1 addition & 1 deletion ui-tests/env3.yml → ui-tests/env-javascript.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: env3
name: env-javascript
channels:
- https://repo.mamba.pm/emscripten-forge
- conda-forge
Expand Down
10 changes: 5 additions & 5 deletions ui-tests/env1.yml → ui-tests/env-python.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: env1
name: env-python
channels:
- https://prefix.dev/emscripten-forge-dev
- https://prefix.dev/conda-forge
dependencies:
- xeus-python
- xeus-lua
- xeus-r
- xeus-cpp
- pandas
- scipy
- numpy
- matplotlib
- bqplot
- ipywidgets
7 changes: 7 additions & 0 deletions ui-tests/env-r.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: env-r
channels:
- https://prefix.dev/emscripten-forge-dev
- https://prefix.dev/conda-forge
dependencies:
- xeus-r
- r-ggplot2
1 change: 0 additions & 1 deletion ui-tests/jupyter-lite.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"jupyter-lite-schema-version": 0,
"jupyter-config-data": {
"appName": "JupyterLite UI Tests",
"defaultKernelName": "xlua",
"exposeAppInBrowser": true
}
}
8 changes: 7 additions & 1 deletion ui-tests/jupyter_lite_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"output_dir": "dist"
},
"XeusAddon": {
"environment_file": ["env1.yml", "env2.yml", "env3.yml"]
"environment_file": [
"env-default.yml",
"env-cpp.yml",
"env-javascript.yml",
"env-python.yml",
"env-r.yml"
]
}
}
155 changes: 155 additions & 0 deletions ui-tests/notebooks/Lorenz.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{
"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": {}
},
{
"cell_type": "markdown",
"source": "Before we start, we import some preliminary libraries.",
"metadata": {}
},
{
"cell_type": "code",
"source": "import numpy as np\nfrom matplotlib import pyplot as plt\nfrom scipy import integrate\n\nfrom ipywidgets import interactive",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": "We will also define the actual solver and plotting routine.",
"metadata": {}
},
{
"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",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"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": {}
},
{
"cell_type": "code",
"source": "w=interactive(solve_lorenz,sigma=(0.0,50.0),rho=(0.0,50.0))\nw",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": "For the default set of parameters, we see the trajectories swirling around two points, called attractors. ",
"metadata": {}
},
{
"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": {}
},
{
"cell_type": "code",
"source": "t, x_t = w.result",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "code",
"source": "w.kwargs",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"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": {}
},
{
"cell_type": "code",
"source": "xyz_avg = x_t.mean(axis=1)",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "code",
"source": "xyz_avg.shape",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": "Creating histograms of the average positions (across different trajectories) show that, on average, the trajectories swirl about the attractors.",
"metadata": {}
},
{
"cell_type": "code",
"source": "from matplotlib import pyplot as plt\n%matplotlib inline",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "code",
"source": "plt.hist(xyz_avg[:,0])\nplt.title('Average $x(t)$');",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "code",
"source": "plt.hist(xyz_avg[:,1])\nplt.title('Average $y(t)$');",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
}
]
}
Loading
Loading