Commit 04635011 authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

Update example.

* guix-kernel-demo.ipynb: Update.
parent beb421ac
......@@ -16,11 +16,11 @@
```scheme
;;guix <command> <args>
<code>
```
Differente command are available:
Different commands are available:
- **environment** to create new environment with container
- **run** eval code in guix kernel container
- **kernel** eval code in specific kernel
---
......@@ -34,89 +34,48 @@
#### Default environment
%% Cell type:code id: tags:
``` scheme
(version)
```
%%%% Output: execute_result
"2.2.4"
%% Cell type:markdown id: tags:
#### Create new environment
Use *magic* cells to specify package version, just like this:
```scheme
;;guix environment <name> <- <packages...>
<code>
```
%% Cell type:code id: tags:
``` scheme
;;guix environment env-guile <- guile@2.2 guile-commonmark
(version)
```
%%%% Output: execute_result
%% Cell type:markdown id: tags:
### Run: Run code in existing environment
Check current guile-version:
%% Cell type:code id: tags:
``` scheme
;;guix run env-guile
(version)
```
%%%% Output: execute_result
"2.2.4"
%% Cell type:markdown id: tags:
Specify default container:
%% Cell type:code id: tags:
``` scheme
;;guix run default
(version)
;;guix run env-guile
(system* "guile" "--version")
(search-path (string-split (getenv "PATH") #\;) "guile")
```
%%%% Output: execute_result
"2.2.4"
%% Cell type:markdown id: tags:
Define function:
%% Cell type:code id: tags:
``` scheme
;;guix run env-guile
(define (list-environ env)
(cond
((null? env) #t)
(else
(display (car env)) (newline)
(list-environ (cdr env)))))
(for-each (lambda (variable)
(display variable)
(newline))
(environ)))
```
%%%% Output: execute_result
#<unspecified>
%% Cell type:markdown id: tags:
Use function:
%% Cell type:code id: tags:
......@@ -124,55 +83,30 @@
``` scheme
;;guix run env-guile
(list-environ (environ))
```
%%%% Output: execute_result
HOME=/home/prouby
USER=prouby
LOGNAME=prouby
TERM=xterm
PWD=/home/prouby/src/jupyter/guix/guix-kernel
PAGER=
SHELL=/gnu/store/q4b3s9y4i0da36drp7zfq9yqcf43s47v-bash-4.4.19/bin/bash
PS1='Jupyter Guix Kernel [env-guile] -> '
JUPYTER_ENV=env-guile
PATH=/gnu/store/nwpr2r4hlhbl6wyx6bzrp9yc20qnjny9-profile/bin
CPATH=/gnu/store/nwpr2r4hlhbl6wyx6bzrp9yc20qnjny9-profile/include
INFOPATH=/gnu/store/nwpr2r4hlhbl6wyx6bzrp9yc20qnjny9-profile/share/info
MANPATH=/gnu/store/nwpr2r4hlhbl6wyx6bzrp9yc20qnjny9-profile/share/man
LIBRARY_PATH=/gnu/store/nwpr2r4hlhbl6wyx6bzrp9yc20qnjny9-profile/lib
ALOCAL_PATH=/gnu/store/nwpr2r4hlhbl6wyx6bzrp9yc20qnjny9-profile/share/alocal
JUPYTER_PATH=/gnu/store/nwpr2r4hlhbl6wyx6bzrp9yc20qnjny9-profile/share/jupyter
GUILE_LOAD_PATH=/gnu/store/nwpr2r4hlhbl6wyx6bzrp9yc20qnjny9-profile/share/guile/site/2.2
GUILE_LOAD_COMPILED_PATH=/gnu/store/nwpr2r4hlhbl6wyx6bzrp9yc20qnjny9-profile/lin/guile/2.2/site-ccache
#t
%% Cell type:markdown id: tags:
### Kernel: Eval code in other jupyter kernel
Create environment 'guile-kernel' with guile kernel for jupyter:
%% Cell type:code id: tags:
``` scheme
;;guix environment with-kernel-container <- jupyter-guile-kernel
;;guix environment guile-kernel-env <- jupyter-guile-kernel
```
%%%% Output: execute_result
%% Cell type:markdown id: tags:
Run code in guile kernel:
%% Cell type:code id: tags:
``` scheme
;;guix kernel with-kernel-container guile
;;guix kernel guile-kernel-env guile
(define (random-art num)
(define (new-char)
(if (eq? (random 10) 5)
(display "+")
(display "."))
......@@ -187,25 +121,21 @@
Use previous function in guile kernel:
%% Cell type:code id: tags:
``` scheme
;;guix kernel with-kernel-container guile
;;guix kernel guile-kernel-env guile
(random-art 3000)
```
%%%% Output: execute_result
..+...+...............+.............+....+............++.....+...................+..........+.........................++..........................+...............+.......+....................+............................+......+.....+..........+..+..++...........................++.......+.+..+..........+..+......+...........+.+.....+.....................+.............+...+.+......................++.......................+......+............+...+......++...+....+++..+.........................+++...................................+.+.........................+.......+......................++.............+..+.........+.......+..+......+..+...+........................+..........+...............................+......+.........+...............+..+....+....................+........+...........................+...............+..................++...............................+...........+...................+..............++......+......+....+.+........................+.................+.+....+........+.........+...+.......................+........................+.........................................+...+..........+....+..++......+.....................+..........+.................+.+..................+...........+....+....+......................+.+.............................+...........................+.+.........+..............++....+......................+..........+...+.........+...+......+..................................+.+...+.....+................+................+.....+.............+....+..............................................+............+.....+...+...........+....................+........................+......+......+..............++....+.............................+........+......+........++..+...++.......+..+....+......++....+...........+.......+........+....+......+...............+...............++...+..................................+.................+..............++......................+.+...+.....+.+.......+....................+............+..........+..........................+........+...+..............+...+.....++..+.........................+......+...+......+...+..................+.+.............++...+..+.....+.....++.............+.....+....+++..............+.........................+...........+....+........+.+..........+................++++.++..+.......+........+...............+...............++..................+................................+....+.........+.+......++.+....+...............++.+............................++.........+...........................++....................+.+.....................................+........+....+.+....+.......+...........+.....+.....+........+........+..................+.............+..+.....+.+....+..........+......+...........+...+.......+...+...++.+.+...........+................................+.............+............................................+...........+..+.+........++.............+.+....+........................+..............+.....+........................#<unspecified>
%% Cell type:markdown id: tags:
---
## Use ipython
## Using IPython
### Create environment with ipython
### Create an environment with IPython
%% Cell type:code id: tags:
``` scheme
;;guix environment my-ipython <- python-ipython python-ipykernel
......@@ -216,11 +146,11 @@
%% Cell type:markdown id: tags:
---
### Run code in Ipython
### Run code in the IPython kernel
%% Cell type:code id: tags:
``` scheme
;;guix kernel my-ipython ipython
......@@ -229,10 +159,92 @@
print ("Hello Jupyter !")
hello ()
```
%% Cell type:code id: tags:
``` scheme
;;guix kernel my-ipython ipython
import os
os.getcwd()
```
%%%% Output: execute_result
'/'
%% Cell type:code id: tags:
``` scheme
;;guix kernel my-ipython ipython
os.listdir('/')
```
%%%% Output: execute_result
['etc', 'var', 'tmp', 'gnu', 'dev', 'proc']
%% Cell type:markdown id: tags:
## A Matplotlib environment
%% Cell type:code id: tags:
``` scheme
;;guix environment matplotlib-env <- python-ipython python-ipykernel python-ipywidgets python-matplotlib
```
%% Cell type:code id: tags:
``` scheme
;;guix kernel matplotlib-env ipython
%matplotlib inline
from matplotlib import pyplot as plt
from matplotlib import style
import random
x = random.sample(range(1, 5000), 1000)
num_bins = 100
n, bins, patches = plt.hist(x, num_bins, facecolor='green', alpha=0.5)
plt.title('Histogram Example')
plt.xlabel('Values')
plt.xlabel('Counts')
plt.show()
```
%% Cell type:code id: tags:
``` scheme
;;guix environment R <- r-irkernel r
```
%%%% Output: execute_result
%%%% Output: execute_result
%% Cell type:code id: tags:
``` scheme
;;guix run R
(use-modules (ice-9 ftw))
(scandir (getenv "PATH"))
```
%%%% Output: execute_result
("." ".." "R" "Rscript")
%% Cell type:code id: tags:
``` scheme
;;guix kernel R ir
2+2
```
%% Cell type:markdown id: tags:
---
`guix-kernel-demo.ipynb` for guix-kernel.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment