{ "cells": [ { "cell_type": "markdown", "id": "d933b4c6-7f11-454d-bf6a-72c4039da306", "metadata": {}, "source": [ "# Use Julia 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/julia/1-install-julia.ipynb)\n", "\n", "This notebook will demonstrate installing a recent version of Julia (currently 1.7.1) and an associated Julia kernel." ] }, { "cell_type": "markdown", "id": "7e523bd8-6c7b-430a-9968-e9a46a502829", "metadata": {}, "source": [ "## 1. Downloading and installing Julia\n", "\n", "Julia is available either via direct download or via the Conda package manager. Here we demonstrate installing the official Julia release, as it is self-contained and is as simple as downloading, decompressing, and then linking the julia executable into a path recognized by our conda environment." ] }, { "cell_type": "code", "execution_count": 5, "id": "c7558cf2-f813-492f-8991-a60680bda389", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "[]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%system curl -OL https://julialang-s3.julialang.org/bin/linux/x64/1.7/julia-1.7.1-linux-x86_64.tar.gz\n", "\n", "%system tar xzvf julia-1.7.1-linux-x86_64.tar.gz -C $HOME\n", "\n", "%system ln -s $HOME/julia-1.7.1/bin/julia $CONDA_PREFIX/bin/julia\n", "\n", "%system rm julia-1.7.1-linux-x86_64.tar.gz" ] }, { "cell_type": "markdown", "id": "bec6f61c-1156-46d3-ade6-d7562ed409fa", "metadata": {}, "source": [ "## 2. Install the IJulia kernel\n", "\n", "Installing the IJulia kernel is similiarly simple. Here we invoke the Julia executable we installed in the previous section, and then use the Julia package manager to install the IJulia kernel" ] }, { "cell_type": "code", "execution_count": 6, "id": "12bf6ca9-9349-4b82-b1ea-f5e26b27ee25", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[' Updating registry at `~/.julia/registries/General.toml`',\n", " ' Resolving package versions...',\n", " ' Updating `~/.julia/environments/v1.7/Project.toml`',\n", " ' [7073ff75] + IJulia v1.23.2',\n", " ' Updating `~/.julia/environments/v1.7/Manifest.toml`',\n", " ' [8f4d0f93] + Conda v1.6.0',\n", " ' [7073ff75] + IJulia v1.23.2',\n", " ' [692b3bcd] + JLLWrappers v1.3.0',\n", " ' [682c06a0] + JSON v0.21.2',\n", " ' [739be429] + MbedTLS v1.0.3',\n", " ' [69de0a69] + Parsers v2.1.2',\n", " ' [21216c6a] + Preferences v1.2.2',\n", " ' [b85f4697] + SoftGlobalScope v1.1.0',\n", " ' [81def892] + VersionParsing v1.2.1',\n", " ' [c2297ded] + ZMQ v1.2.1',\n", " ' [8f1865be] + ZeroMQ_jll v4.3.4+0',\n", " ' [a9144af2] + libsodium_jll v1.0.20+0',\n", " ' [0dad84c5] + ArgTools',\n", " ' [56f22d72] + Artifacts',\n", " ' [2a0f44e3] + Base64',\n", " ' [ade2ca70] + Dates',\n", " ' [f43a241f] + Downloads',\n", " ' [7b1f6079] + FileWatching',\n", " ' [b77e0a4c] + InteractiveUtils',\n", " ' [b27032c2] + LibCURL',\n", " ' [76f85450] + LibGit2',\n", " ' [8f399da3] + Libdl',\n", " ' [56ddb016] + Logging',\n", " ' [d6f4376e] + Markdown',\n", " ' [a63ad114] + Mmap',\n", " ' [ca575930] + NetworkOptions',\n", " ' [44cfe95a] + Pkg',\n", " ' [de0858da] + Printf',\n", " ' [3fa0cd96] + REPL',\n", " ' [9a3f8284] + Random',\n", " ' [ea8e919c] + SHA',\n", " ' [9e88b42a] + Serialization',\n", " ' [6462fe0b] + Sockets',\n", " ' [fa267f1f] + TOML',\n", " ' [a4e569a6] + Tar',\n", " ' [8dfed614] + Test',\n", " ' [cf7118a7] + UUIDs',\n", " ' [4ec0a83e] + Unicode',\n", " ' [deac9b47] + LibCURL_jll',\n", " ' [29816b5a] + LibSSH2_jll',\n", " ' [c8ffd9c3] + MbedTLS_jll',\n", " ' [14a3606d] + MozillaCACerts_jll',\n", " ' [83775a58] + Zlib_jll',\n", " ' [8e850ede] + nghttp2_jll',\n", " ' [3f19e933] + p7zip_jll']" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%system julia -e 'using Pkg; Pkg.add([\"IJulia\"]);'" ] }, { "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." ] }, { "cell_type": "code", "execution_count": 10, "id": "84ca7430-dc35-4e31-b61f-c7032d315bb8", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['[ Info: Installing Julia (single-threaded) kernelspec in /home/studio-lab-user/.conda/envs/default/share/jupyter/kernels/julia-(single-threaded)-1.7']" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%system JUPYTER_DATA_DIR=$CONDA_PREFIX/share/jupyter/ \\\n", " julia -e 'using IJulia; installkernel(\"Julia (single-threaded)\")'" ] }, { "cell_type": "code", "execution_count": 11, "id": "1b0220ef-58e4-4c1c-b9da-3596e9dea897", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['[ Info: Installing Julia (4 threads) kernelspec in /home/studio-lab-user/.conda/envs/default/share/jupyter/kernels/julia-(4-threads)-1.7']" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%system JUPYTER_DATA_DIR=$CONDA_PREFIX/share/jupyter/ \\\n", " julia -e 'using IJulia; installkernel(\"Julia (4 threads)\", env=Dict(\"JULIA_NUM_THREADS\"=>\"4\"))'" ] }, { "cell_type": "markdown", "id": "768d705d-14cc-47af-8cb1-6c2358ee803a", "metadata": {}, "source": [ "## 3. Using Julia\n", "\n", "With Julia installed, and the IJulia kernel registered, you can create a new Julia notebook from the SageMaker Studio Lab launcher. You can also follow along with the example Julia notebook in this folder." ] } ], "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.7" } }, "nbformat": 4, "nbformat_minor": 5 }