Last active
October 30, 2022 08:18
-
-
Save terasakisatoshi/911efa1b8ce8a2e83dde0f271a26db74 to your computer and use it in GitHub Desktop.
Reduce overhead of loading Plots.jl packages on jupyter using PackageCompiler.jl ( tested on Julia v1.5.0 )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM julia:1.5.1 | |
RUN apt-get update && \ | |
apt-get install -y \ | |
build-essential \ | |
cmake \ | |
python3 \ | |
python3-dev \ | |
python3-distutils \ | |
curl \ | |
ca-certificates \ | |
git \ | |
libgconf-2-4 \ | |
xvfb \ | |
libgtk-3-0 \ | |
dvipng \ | |
texlive-latex-recommended \ | |
zip \ | |
libxt6 libxrender1 libxext6 libgl1-mesa-glx libqt5widgets5 # GR && \ | |
apt-get clean && rm -rf /var/lib/apt/lists/* # clean up | |
RUN curl -kL https://bootstrap.pypa.io/get-pip.py | python3 && \ | |
pip3 install \ | |
jupyter \ | |
jupyterlab \ | |
jupytext \ | |
ipywidgets \ | |
jupyter-contrib-nbextensions \ | |
jupyter-nbextensions-configurator \ | |
jupyterlab_code_formatter autopep8 black | |
# suppress warning for related to GR backend | |
ENV GKSwstype=100 | |
RUN julia -e 'ENV["PYTHON"]=Sys.which("python3"); \ | |
ENV["JUPYTER"]=Sys.which("jupyter"); \ | |
using Pkg; \ | |
Pkg.add(["IJulia", "Plots", "PackageCompiler"]); \ | |
# Install test dependencies for IJulia \ | |
Pkg.add(PackageSpec(name="JSON", version="0.21.0")); \ | |
# Install test dependencies for Plots \ | |
Pkg.add(PackageSpec(name="Plots", version="1.6.0")); \ | |
Pkg.add(PackageSpec(name="ImageMagick", version="1.1.6")); \ | |
Pkg.add(PackageSpec(name="VisualRegressionTests", version="1.0.0")); \ | |
Pkg.add(PackageSpec(name="FileIO", version="1.4.2")); \ | |
Pkg.add(PackageSpec(name="StableRNGs", version="0.1.1")); \ | |
Pkg.add(PackageSpec(name="Gtk", version="1.1.4")); \ | |
Pkg.add(PackageSpec(name="GeometryTypes", version="0.8.3")); \ | |
Pkg.add(PackageSpec(name="GeometryBasics", version="0.2.15")); \ | |
Pkg.add(PackageSpec(name="HDF5", version="0.13.5")); \ | |
Pkg.add(PackageSpec(name="PGFPlotsX", version="1.2.9")); \ | |
Pkg.add(PackageSpec(name="StaticArrays", version="0.12.4")); \ | |
Pkg.add(PackageSpec(name="OffsetArrays", version="1.1.3")); \ | |
Pkg.add(PackageSpec(name="UnicodePlots", version="1.1.0")); \ | |
Pkg.add(PackageSpec(name="Distributions", version="0.23.10")); \ | |
Pkg.pin([\ | |
"Plots", "ImageMagick", "VisualRegressionTests", "FileIO", \ | |
"StableRNGs", "Gtk", "GeometryTypes", "GeometryBasics", \ | |
"HDF5", "PGFPlotsX", "StaticArrays", "OffsetArrays", \ | |
"UnicodePlots", "Distributions" \ | |
])' | |
# show current state | |
RUN julia -e "using Pkg; Pkg.status()" | |
# generate precompile_statements_file | |
RUN xvfb-run julia \ | |
--trace-compile=ijuliacompile.jl \ | |
-e 'ENV["CI"]="true"; using Plots, IJulia; \ | |
include(joinpath(pkgdir(IJulia), "test", "runtests.jl")); \ | |
try include(joinpath(pkgdir(Plots), "test", "runtests.jl")) catch end' | |
# update sysimage | |
RUN julia -e 'using PackageCompiler; \ | |
create_sysimage(\ | |
[:IJulia, :Plots], \ | |
precompile_statements_file="ijuliacompile.jl", \ | |
replace_default=true\ | |
)' | |
RUN julia -e 'using Pkg; Pkg.precompile(); using InteractiveUtils; versioninfo()' | |
CMD ["julia"] |
For those who like to run locally with julia --trace-compile=traced.jl
ENV["GKSwstype"]=100
ENV["PYTHON"]=Sys.which("python3");
ENV["JUPYTER"]=Sys.which("jupyter");
using Pkg
Pkg.add(["IJulia", "PackageCompiler"]);
# Install test dependencies for IJulia
Pkg.add([PackageSpec(name="JSON", version="0.21.0"),
# Install test dependencies for Plots v1.6.0
PackageSpec(name="Plots", version="1.6.0"),
PackageSpec(name="ImageMagick", version="1.1.6"),
PackageSpec(name="VisualRegressionTests", version="1.0.0"),
PackageSpec(name="FileIO", version="1.4.2"),
PackageSpec(name="StableRNGs", version="0.1.1"),
PackageSpec(name="Gtk", version="1.1.4"),
PackageSpec(name="GeometryTypes", version="0.8.3"),
PackageSpec(name="GeometryBasics", version="0.2.15"),
PackageSpec(name="HDF5", version="0.13.5"),
PackageSpec(name="PGFPlotsX", version="1.2.9"),
PackageSpec(name="StaticArrays", version="0.12.4"),
PackageSpec(name="OffsetArrays", version="1.1.3"),
PackageSpec(name="UnicodePlots", version="1.1.0"),
PackageSpec(name="Distributions", version="0.23.10"),
])
using Plots
include(joinpath(pkgdir(Plots), "test", "runtests.jl"))
Or download file from this gist and save it as traced.jl
After that, simply run:
using PackageCompiler; create_sysimage([:Plots, :Revise, :OhMyREPL], precompile_statements_file="traced.jl", sysimage_path="plots")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
Dockerfile
abovehttp://127.0.0.1:8888/?token=xxxxxxxxxx
on your web browser (where tokenxxxxxxxxxx
is depends on your environment)