jgart 11 months ago
commit
391b928d16
  1. 29
      LICENSE
  2. 24
      README.md
  3. 342
      guix-kernel-demo.ipynb
  4. 4
      requirements.scm

29
LICENSE

@ -0,0 +1,29 @@
BSD 3-Clause License
Copyright (c) 2018-, Jupyter Development Team
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

24
README.md

@ -0,0 +1,24 @@
# Guix Python environment with requirements.scm
[![Binder](http://mybinder.org/badge_logo.svg)](http://mybinder.org/v2/gh/binder-examples/requirements/master)
A Binder-compatible repo with a `requirements.scm` file.
Access this Binder at the following URL
http://mybinder.org/v2/gh/binder-examples/requirements/master
## Notes
The `requirements.scm` file should list all Python libraries that your notebooks
depend on, and they will be installed using:
```
pip install -r requirements.scm
```
The base Binder image contains no extra dependencies, so be as
explicit as possible in defining the packages that you need. This includes
specifying explict versions wherever possible.
In this example we include the library `seaborn` which will be installed in
the environment, and our notebook uses it to plot a figure.

342
guix-kernel-demo.ipynb

@ -0,0 +1,342 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Demo Guix Jupyter kernel\n",
"\n",
"Project source code: [Guix-kernel](https://gitlab.inria.fr/guix-hpc/guix-kernel).\n",
"\n",
"![Guix-Jupyter](logo.png)\n",
"\n",
"---\n",
"## Getting Started\n",
"\n",
"The `;;guix environment` _magic command_ allows you to create an execution environment containing a Jupyter kernel, or to run code in a previously-created environment.\n",
"\n",
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Evaluating Code in a Jupyter Kernel\n",
"\n",
"Create an environment called `guile-kernel` containing the Guile kernel for Jupyter:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
";;guix pin 36cc160e721a764c16f53c6f7fbd9d09c581717e"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
";;guix environment guile-kernel-env <- jupyter-guile-kernel"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run code in guile kernel:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
";;guix environment guile-kernel-env\n",
"(define (list-environ env)\n",
" (for-each (lambda (variable)\n",
" (display variable)\n",
" (newline))\n",
" (environ)))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
";; Here we don't repeat \"guix environment\", so we use the\n",
";; same environment as the previous cell.\n",
"(list-environ (environ))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"(define (random-art num)\n",
" (define (new-char)\n",
" (if (eq? (random 10) 5)\n",
" (display \"+\")\n",
" (display \".\"))\n",
" (random-art (- num 1)))\n",
"\n",
" (if (not (zero? num))\n",
" (new-char)))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Call the previously-defined function in the Guile kernel:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"(random-art 3000)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"\n",
"## Using IPython\n",
"\n",
"### Create an environment with IPython"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
";;guix environment my-ipython <- python-ipython python-ipykernel"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"\n",
"### Run code in the IPython kernel"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
";;guix environment my-ipython\n",
"# This is python lang !\n",
"def hello ():\n",
" print (\"Hello Jupyter !\")\n",
" \n",
"hello ()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
";;guix environment my-ipython\n",
"import os\n",
"os.getcwd()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"os.getuid()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"os.getpid()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"os.listdir('/')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## A Matplotlib environment"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
";;guix environment matplotlib-env <- python-ipython python-ipykernel python-ipywidgets python-matplotlib"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
";;guix environment matplotlib-env\n",
"%matplotlib inline\n",
"from matplotlib import pyplot as plt\n",
"from matplotlib import style\n",
"import random\n",
"x = random.sample(range(1, 5000), 1000)\n",
"num_bins = 100\n",
"n, bins, patches = plt.hist(x, num_bins, facecolor='green', alpha=0.5)\n",
"\n",
"plt.title('Histogram Example')\n",
"plt.xlabel('Values')\n",
"plt.xlabel('Counts')\n",
"plt.show() "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
";;guix environment R <- r r-irkernel"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"version"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
";;guix download https://ftp.gnu.org/gnu/coreutils/coreutils-8.30.tar.xz e831b3a86091496cdba720411f9748de81507798f6130adeaef872d206e1b057\n",
";;\n",
";; Here we download a file and make it available in the 'R'\n",
";; environment created above. We specify its SHA256 hash\n",
";; to ensure the integrity of the computations that follow."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"file.info('coreutils-8.30.tar.xz')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Using the built-in kernel for [GNU Guile](https://gnu.org/s/guile)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
";;guix environment guile <- guile"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"(version)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"(getaddrinfo \"www.gnu.org\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"(getpid)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"`guix-kernel-demo.ipynb` for guix-kernel.\n",
"\n",
"_Version 0.0.1_"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Guix",
"language": "scheme",
"name": "guix"
},
"language_info": {
"codemirror_mode": "scheme",
"file_extension": ".scm",
"mimetype": "application/x-scheme",
"name": "guile",
"pygments_lexer": "scheme",
"version": "3.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

4
requirements.scm

@ -0,0 +1,4 @@
numpy==1.16.*
matplotlib==3.*
seaborn==0.8.1
pandas
Loading…
Cancel
Save