From 93b669eaa7e2be582b11dfd202805c33d0262c2e Mon Sep 17 00:00:00 2001 From: Peter Schmiedeskamp Date: Tue, 19 Apr 2022 18:09:18 -0700 Subject: [PATCH 1/7] initial notebook for the Racket programming language --- .../racket-lang/1-install-racket.ipynb | 153 ++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 custom-environments/racket-lang/1-install-racket.ipynb diff --git a/custom-environments/racket-lang/1-install-racket.ipynb b/custom-environments/racket-lang/1-install-racket.ipynb new file mode 100644 index 0000000..75150f2 --- /dev/null +++ b/custom-environments/racket-lang/1-install-racket.ipynb @@ -0,0 +1,153 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "d933b4c6-7f11-454d-bf6a-72c4039da306", + "metadata": {}, + "source": [ + "# Use Racket with Studio Lab\n", + "\n", + "\n", + "[![Open In Studio Lab](https://studiolab.sagemaker.aws/studiolab.svg)](https://studiolab.sagemaker.aws/import/github/aws/studio-lab-examples/blob/main/custom-environments/racket-lang/1-install-racket.ipynb)\n", + "\n", + "This notebook will demonstrate installing a recent version of Racket (currently 8.3) and an associated Racket kernel." + ] + }, + { + "cell_type": "markdown", + "id": "56047c30-b329-468e-b152-5529693bd2bd", + "metadata": { + "tags": [] + }, + "source": [ + "## 1. Creating a Conda environment for Racket\n", + "\n", + "Installing Racket and associated packages in a conda environment helps keep the rest of your SageMaker Studio Lab environment pristine, and avoids the potential for conflicting packages. Here we create the environment with necessary dependencies preinstalled." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c1aadb0a-4e7e-47cb-b005-8ee841be487c", + "metadata": {}, + "outputs": [], + "source": [ + "%system conda create -n racket-lang zeromq" + ] + }, + { + "cell_type": "markdown", + "id": "974ca00c-0030-463e-a638-4320e02ad44e", + "metadata": {}, + "source": [ + "To find shared libraries installed via conda, we need to ensure that the LD_LIBRARY_PATH environment variable is set when our racket-lang environment is activated." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c7a93ef0-565a-478a-b457-15af48582f6d", + "metadata": {}, + "outputs": [], + "source": [ + "%system conda run -n racket-lang bash -c 'mkdir -p $CONDA_PREFIX/etc/conda/activate.d $CONDA_PREFIX/etc/conda/deactivate.d'\n", + "%system conda run -n racket-lang bash -c 'echo \"export LD_LIBRARY_PATH=$CONDA_PREFIX/lib\" > $CONDA_PREFIX/etc/conda/activate.d/envar.sh'\n", + "%system conda run -n racket-lang bash -c 'echo \"unset LD_LIBRARY_PATH\" > $CONDA_PREFIX/etc/conda/deactivate.d/envar.sh'" + ] + }, + { + "cell_type": "markdown", + "id": "1bbab127-822a-44ab-a2a5-644b1b890f30", + "metadata": { + "tags": [] + }, + "source": [ + "## 2. Downloading and installing Racket\n", + "\n", + "Racket is available either via direct download or via the Conda package manager. Here we demonstrate installing the official Racket release, as the Conda package of Racket tends to lag official releases. Racket is self-contained and is as simple as downloading, and running the installer." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c7558cf2-f813-492f-8991-a60680bda389", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "%system curl -L https://download.racket-lang.org/installers/8.4/racket-8.4-x86_64-linux-cs.sh -o /tmp/racket-install; chmod +x /tmp/racket-install\n", + "%system conda run -n racket-lang bash -c '/tmp/racket-install --unix-style --create-dir --dest $CONDA_PREFIX'; rm /tmp/racket-install" + ] + }, + { + "cell_type": "markdown", + "id": "bec6f61c-1156-46d3-ade6-d7562ed409fa", + "metadata": {}, + "source": [ + "## 2. Install the IRacket kernel\n", + "\n", + "Installing the IRacket kernel is similiarly simple. Here we use the `raco` package manager to install the IRacket kernel. Note that the `-i` flag to raco ensures the packages install to the version of raco we installed in our conda environment. If installing additional packages from e.g. the terminal, make sure to activate the racket-lang using `conda activate racket-lang` and then be sure to include the `-i` flag to `raco` for any Racket packages you wish to install." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "961e9baa-0584-4eb7-a244-feeff7e6cb8f", + "metadata": {}, + "outputs": [], + "source": [ + "%system conda run -n racket-lang raco pkg install -i --auto iracket" + ] + }, + { + "cell_type": "markdown", + "id": "670b5c00-3b24-4494-9db6-9c22f7cc703f", + "metadata": {}, + "source": [ + "After installing the iracket package (and any other packages we wish to install), we run the iracket package's setup script and ensure the IRacket kernel is moved to the correct directory." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "78fbd80a-b54e-4604-9186-38ac73d85ea5", + "metadata": {}, + "outputs": [], + "source": [ + "%system conda run -n racket-lang raco iracket install\n", + "%system bash -c 'mkdir -p $CONDA_PREFIX/share/jupyter/kernels'\n", + "%system bash -c 'mv ~/.local/share/jupyter/kernels/racket $CONDA_PREFIX/share/jupyter/kernels/'" + ] + }, + { + "cell_type": "markdown", + "id": "a3e58026-678e-415e-abd1-44c71af184f8", + "metadata": {}, + "source": [ + "Lastly, let's register a couple of kernel profiles with the default conda environment so they show up in our SageMaker Studio Lab launcher. Here we add two profiles: one single-threaded, and one with multiple threads enabled at startup." + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "default:Python", + "language": "python", + "name": "conda-env-default-py" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 4ddf4bb00a6949109c7d56f9fd1a3d18cd1cce78 Mon Sep 17 00:00:00 2001 From: Peter Schmiedeskamp Date: Wed, 20 Apr 2022 14:27:49 -0700 Subject: [PATCH 2/7] add README --- custom-environments/racket-lang/README.org | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 custom-environments/racket-lang/README.org diff --git a/custom-environments/racket-lang/README.org b/custom-environments/racket-lang/README.org new file mode 100644 index 0000000..51f9ab2 --- /dev/null +++ b/custom-environments/racket-lang/README.org @@ -0,0 +1,8 @@ +#+TITLE: Using the Racket programming language with Amazon SageMaker Studio Lab + +[[https://racket-lang.org/][Racket]] is a modern general purpose programming language in the lisp +family of languages with a growing ecosystem of packages across a +variety of domains including math, statistics, and machine learning. + +This directory contains Jupyter notebook examples for installing and +working with Racket in SageMaker Studio Lab. From 6b8ce10f2ff0bf00517ff857a3cdfe209ef19491 Mon Sep 17 00:00:00 2001 From: Peter Schmiedeskamp Date: Thu, 21 Apr 2022 01:09:46 +0000 Subject: [PATCH 3/7] clean up installation; initial usage example --- .../racket-lang/1-install-racket.ipynb | 12 +- .../racket-lang/2-using-racket.ipynb | 2471 +++++++++++++++++ 2 files changed, 2477 insertions(+), 6 deletions(-) create mode 100644 custom-environments/racket-lang/2-using-racket.ipynb diff --git a/custom-environments/racket-lang/1-install-racket.ipynb b/custom-environments/racket-lang/1-install-racket.ipynb index 75150f2..346ba82 100644 --- a/custom-environments/racket-lang/1-install-racket.ipynb +++ b/custom-environments/racket-lang/1-install-racket.ipynb @@ -5,7 +5,7 @@ "id": "d933b4c6-7f11-454d-bf6a-72c4039da306", "metadata": {}, "source": [ - "# Use Racket with Studio Lab\n", + "# Installing Racket in SageMaker Studio Lab\n", "\n", "\n", "[![Open In Studio Lab](https://studiolab.sagemaker.aws/studiolab.svg)](https://studiolab.sagemaker.aws/import/github/aws/studio-lab-examples/blob/main/custom-environments/racket-lang/1-install-racket.ipynb)\n", @@ -32,7 +32,7 @@ "metadata": {}, "outputs": [], "source": [ - "%system conda create -n racket-lang zeromq" + "%system conda create -n racket-lang zeromq cairo libjpeg-turbo pango" ] }, { @@ -85,7 +85,7 @@ "id": "bec6f61c-1156-46d3-ade6-d7562ed409fa", "metadata": {}, "source": [ - "## 2. Install the IRacket kernel\n", + "## 3. Install the IRacket kernel\n", "\n", "Installing the IRacket kernel is similiarly simple. Here we use the `raco` package manager to install the IRacket kernel. Note that the `-i` flag to raco ensures the packages install to the version of raco we installed in our conda environment. If installing additional packages from e.g. the terminal, make sure to activate the racket-lang using `conda activate racket-lang` and then be sure to include the `-i` flag to `raco` for any Racket packages you wish to install." ] @@ -97,7 +97,7 @@ "metadata": {}, "outputs": [], "source": [ - "%system conda run -n racket-lang raco pkg install -i --auto iracket" + "%system conda run -n racket-lang raco pkg install -i --auto iracket aws" ] }, { @@ -116,8 +116,8 @@ "outputs": [], "source": [ "%system conda run -n racket-lang raco iracket install\n", - "%system bash -c 'mkdir -p $CONDA_PREFIX/share/jupyter/kernels'\n", - "%system bash -c 'mv ~/.local/share/jupyter/kernels/racket $CONDA_PREFIX/share/jupyter/kernels/'" + "%system conda run -n racket-lang bash -c 'mkdir -p $CONDA_PREFIX/share/jupyter/kernels/racket'\n", + "%system conda run -n racket-lang bash -c 'mv ~/.local/share/jupyter/kernels/racket/* $CONDA_PREFIX/share/jupyter/kernels/racket/; rm -r ~/.local/share/jupyter/kernels/racket; rm -rf /home/studio-lab-user/.conda/envs/default/share/jupyter/kernels/racket'" ] }, { diff --git a/custom-environments/racket-lang/2-using-racket.ipynb b/custom-environments/racket-lang/2-using-racket.ipynb new file mode 100644 index 0000000..4eaadda --- /dev/null +++ b/custom-environments/racket-lang/2-using-racket.ipynb @@ -0,0 +1,2471 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "09cb2814-2d63-44b3-bff2-7ba330b1142b", + "metadata": {}, + "source": [ + "# Using the Racket programming language in SageMaker Studio Lab\n", + "\n", + "NOTE: This notebook assumes installation of Racket, the IRacket Jupyter kernel, as well as other key dependencies as illustrated in the `1-install-racket` notebook in this directory." + ] + }, + { + "cell_type": "markdown", + "id": "c6cd8676-340e-4b36-98a0-b599af100b62", + "metadata": {}, + "source": [ + "First we load some libraries included in the main Racket distribution as well as others installed in the previous notebook example." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "819e84f1-19f4-4457-903b-e975591e32ab", + "metadata": {}, + "outputs": [], + "source": [ + "(require aws\n", + " plot/no-gui\n", + " racket/math)" + ] + }, + { + "cell_type": "markdown", + "id": "93ef1666-8fd7-47c0-ba09-1a936f933a86", + "metadata": {}, + "source": [ + "Because we are running in a notebook environment we must load the plotting library as `(require plot/no-gui)`. This also means we cannot use the interactive `plot` and `plot3d` functions. Instead we can use the `plot-pict` and `plot3d-pict` functions to display plots in-line as illustrated below using examples from the [Racket documentation](https://docs.racket-lang.org/plot/intro.html)." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "b54d765b-3872-4b21-a547-600c50acc8d6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "(plot-pict '(prog # 400) 400 400 400 0 '() #f #f '#(#(-884279719003555/281474976710656 884279719003555/281474976710656) #(-9007154627701343/9007199254740992 9007154627701343/9007199254740992)) # # '#(0 0 1))" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(plot-pict (function sin (- pi) pi #:label \"y = sin(x)\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "68537283-e51d-421d-8a96-71dc48c14837", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "(plot-pict '(prog # 400) 400 400 400 0 '() #f #f '#(#(-884279719003555/281474976710656 884279719003555/281474976710656) #(-884279719003555/281474976710656 884279719003555/281474976710656) #(-1 1)) # # '#(0.43786960608197173 0.7583948903432614 -0.48281196999541276))" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(plot3d-pict (surface3d (λ (x y) (* (cos x) (sin y)))\n", + " (- pi) pi (- pi) pi)\n", + " #:title \"An R × R → R function\"\n", + " #:x-label \"x\" #:y-label \"y\" #:z-label \"cos(x) sin(y)\")" + ] + } + ], + "metadata": { + "kernelspec": { + "name": "conda-env-racket-lang-racket" + }, + "language_info": { + "codemirror_mode": "scheme", + "file_extension": ".rkt", + "mimetype": "text/x-racket", + "name": "Racket", + "pygments_lexer": "racket", + "version": "8.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From e9ba394c7214566d6a7eb8df1f7fb29561ac2dc5 Mon Sep 17 00:00:00 2001 From: Peter Schmiedeskamp Date: Thu, 21 Apr 2022 14:15:49 -0700 Subject: [PATCH 4/7] Update 2-using-racket.ipynb Manually set display name to appease Github rendering. --- custom-environments/racket-lang/2-using-racket.ipynb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/custom-environments/racket-lang/2-using-racket.ipynb b/custom-environments/racket-lang/2-using-racket.ipynb index 4eaadda..9b23141 100644 --- a/custom-environments/racket-lang/2-using-racket.ipynb +++ b/custom-environments/racket-lang/2-using-racket.ipynb @@ -2455,7 +2455,8 @@ ], "metadata": { "kernelspec": { - "name": "conda-env-racket-lang-racket" + "name": "conda-env-racket-lang-racket", + "display_name": "racket-lang:Racket", }, "language_info": { "codemirror_mode": "scheme", From 70673492f3f34fc9b9759a9bc3b4343bcc0f7cec Mon Sep 17 00:00:00 2001 From: Peter Schmiedeskamp Date: Thu, 21 Apr 2022 14:16:52 -0700 Subject: [PATCH 5/7] Update 2-using-racket.ipynb nuke errant comma --- custom-environments/racket-lang/2-using-racket.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom-environments/racket-lang/2-using-racket.ipynb b/custom-environments/racket-lang/2-using-racket.ipynb index 9b23141..3c5e575 100644 --- a/custom-environments/racket-lang/2-using-racket.ipynb +++ b/custom-environments/racket-lang/2-using-racket.ipynb @@ -2456,7 +2456,7 @@ "metadata": { "kernelspec": { "name": "conda-env-racket-lang-racket", - "display_name": "racket-lang:Racket", + "display_name": "racket-lang:Racket" }, "language_info": { "codemirror_mode": "scheme", From 3d99ddf6e309e28b114742555bfb0bc8d4932b18 Mon Sep 17 00:00:00 2001 From: Peter Schmiedeskamp Date: Thu, 21 Apr 2022 22:05:21 +0000 Subject: [PATCH 6/7] update metadata per Jupyter mechanism --- custom-environments/racket-lang/2-using-racket.ipynb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/custom-environments/racket-lang/2-using-racket.ipynb b/custom-environments/racket-lang/2-using-racket.ipynb index 4eaadda..5b9c037 100644 --- a/custom-environments/racket-lang/2-using-racket.ipynb +++ b/custom-environments/racket-lang/2-using-racket.ipynb @@ -2455,6 +2455,8 @@ ], "metadata": { "kernelspec": { + "display_name": "racket-lang:Racket", + "language": "racket", "name": "conda-env-racket-lang-racket" }, "language_info": { From ff34837fdf9ad7a871a1706a013216a9403d2b81 Mon Sep 17 00:00:00 2001 From: Peter Schmiedeskamp Date: Fri, 14 Jul 2023 10:00:20 -0500 Subject: [PATCH 7/7] bump racket version --- .../racket-lang/1-install-racket.ipynb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/custom-environments/racket-lang/1-install-racket.ipynb b/custom-environments/racket-lang/1-install-racket.ipynb index 346ba82..fb67144 100644 --- a/custom-environments/racket-lang/1-install-racket.ipynb +++ b/custom-environments/racket-lang/1-install-racket.ipynb @@ -76,7 +76,7 @@ }, "outputs": [], "source": [ - "%system curl -L https://download.racket-lang.org/installers/8.4/racket-8.4-x86_64-linux-cs.sh -o /tmp/racket-install; chmod +x /tmp/racket-install\n", + "%system curl -L https://download.racket-lang.org/installers/8.9/racket-8.9-x86_64-linux-cs.sh -o /tmp/racket-install; chmod +x /tmp/racket-install\n", "%system conda run -n racket-lang bash -c '/tmp/racket-install --unix-style --create-dir --dest $CONDA_PREFIX'; rm /tmp/racket-install" ] }, @@ -119,14 +119,6 @@ "%system conda run -n racket-lang bash -c 'mkdir -p $CONDA_PREFIX/share/jupyter/kernels/racket'\n", "%system conda run -n racket-lang bash -c 'mv ~/.local/share/jupyter/kernels/racket/* $CONDA_PREFIX/share/jupyter/kernels/racket/; rm -r ~/.local/share/jupyter/kernels/racket; rm -rf /home/studio-lab-user/.conda/envs/default/share/jupyter/kernels/racket'" ] - }, - { - "cell_type": "markdown", - "id": "a3e58026-678e-415e-abd1-44c71af184f8", - "metadata": {}, - "source": [ - "Lastly, let's register a couple of kernel profiles with the default conda environment so they show up in our SageMaker Studio Lab launcher. Here we add two profiles: one single-threaded, and one with multiple threads enabled at startup." - ] } ], "metadata": { @@ -145,7 +137,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.10" + "version": "3.9.16" } }, "nbformat": 4,