项目作者: terasakisatoshi

项目描述 :
For those who want to try Julia
高级语言: Julia
项目地址: git://github.com/terasakisatoshi/MyWorkflow.jl.git
创建时间: 2019-12-18T15:07:12Z
项目社区:https://github.com/terasakisatoshi/MyWorkflow.jl

开源协议:MIT License

下载


MyWorkflow

Build Status
Stable
Dev

  • An example of workflow using Docker and GitHub Actions

Have a try MyWorkflow.jl

  • MyWorkflow.jl master (nightly) Binder Julia v1.6.3

  • MyWorkflow.jl v0.27.0 (stable) Binder Julia v1.6.3

  • MyWorkflow.jl v0.25.0 (old) Binder Julia v1.6.2

Feature

  • This repository gives us some useful techniques such as:
    1. how to utilize Docker Docker Compose with your Julia workflow.
    2. how to customize Julia’s system image via PackageCompiler.jl to reduce an overhead of package’s loading time e.g. Plots.jl etc…
    3. how to share our work on the Internet. Check our repository on Binder from Binder
    4. how to use GitHub actions as a CI functionality.
    5. how to communicate between a Docker container and Juno/Atom

Directory Structure

  1. $ tree .
  2. .
  3. ├── Dockerfile
  4. ├── LICENSE
  5. ├── Makefile
  6. ├── Project.toml
  7. ├── README.md
  8. ├── binder
  9. └── Dockerfile
  10. ├── docker-compose.yml
  11. ├── docs
  12. ├── Project.toml
  13. ├── make.jl
  14. └── src
  15. ├── assets
  16. ├── lab.png
  17. ├── open_notebook_on_jupyterlab.png
  18. ├── port9999.png
  19. └── theorem.css
  20. ├── example.md
  21. ├── figures
  22. ├── index.md
  23. ├── math.md
  24. ├── myworkflow.md
  25. └── weavesample.jmd
  26. ├── gitpod
  27. └── Dockerfile
  28. ├── jupytext.toml
  29. ├── playground
  30. ├── notebook
  31. ├── Chisq.md
  32. ├── Harris.md
  33. ├── Rotation3D.md
  34. ├── apply_PCA_to_MNIST.md
  35. ├── box_and_ball_system.md
  36. ├── clang.md
  37. ├── convex_hull.md
  38. ├── coordinate_system.md
  39. ├── curve.md
  40. ├── elastic_collision.md
  41. ├── example.md
  42. ├── fitting.md
  43. ├── free_fall.md
  44. ├── gradient_descent.md
  45. ├── histogram_eq.md
  46. ├── hop_step_jump.md
  47. ├── image_filtering.md
  48. ├── interact_sample.md
  49. ├── iris.md
  50. ├── jsxgraph_julia.md
  51. ├── jsxgraph_with_rawJS.md
  52. ├── jsxgraph_with_webio_jsexpr.md
  53. ├── lazysets.md
  54. ├── linear_regression.md
  55. ├── n-Soliton.md
  56. ├── ode.md
  57. ├── plots_fill_example.md
  58. ├── plots_sample.md
  59. ├── pluto
  60. └── sample.jl
  61. ├── point_on_circle.md
  62. ├── pyjulia.md
  63. ├── pyplot.md
  64. ├── rcall.md
  65. ├── reuleaux_triangle.md
  66. ├── seaborn.md
  67. ├── simple_harmonic_motion.md
  68. ├── staticarrays.md
  69. ├── staticarrays_fieldvector.md
  70. ├── tangent_vector.md
  71. └── wav_example.md
  72. └── test
  73. └── runtests.jl
  74. ├── requirements.txt
  75. ├── src
  76. └── MyWorkflow.jl
  77. └── test
  78. └── runtests.jl

How to use

Prepare Environment

  1. $ docker run --rm -it julia
  2. # some staff happens ...
  • It will initialize a fresh Julia environment even if you do not have a Julia on your (host) machine.

Buiding Docker image

  • O.K. Let’s build a Docker image for our purpose. Just run:
  1. $ make build

which is exactly equivalent to the following procedure:

  1. $ rm -f Manifest.toml
  2. $ docker build -t myworkflojl .
  3. $ docker-compose build
  4. $ docker-compose run --rm julia julia --project=/work -e 'using Pkg; Pkg.instantiate()'

Tips for Windows Users

  • You can install make command via winget.
  1. PS> # open powershell NOT `cmd.exe`
  2. PS> winget install -e GnuWin32.Make

The make.exe lives in C:\Program Files (x86)\GnuWin32\bin\make.exe. Therefore please add it to your PATH environment variable.
After that, if PS> Get-Command make works fine, you’re good to go.

  • Or try the following procedure:
  1. PS> Remove-Item -Path Manifest.toml -ErrorAction Ignore
  2. PS> docker build -t myworkflowjl .
  3. PS> docker-compose build
  4. PS> docker-compose run --rm julia julia --project=/work -e 'using Pkg; Pkg.instantiate()'

Pull Docker image (Optional)

  • Running make build may take much time to build our Docker image. Please use make pull instead.
  1. $ make pull

which is almost equivalent to:

  1. $ rm -f Manifest.toml
  2. $ docker pull myworkflowjl
  3. $ docker-compose run --rm julia julia --project=/work -e 'using Pkg; Pkg.instantiate()'

Running Jupyter Notebook/JupyterLab

  1. $ docker-compose up jupyter
  2. myjupyter | To access the notebook, open this file in a browser:
  3. myjupyter | file:///root/.local/share/jupyter/runtime/nbserver-1-open.html
  4. myjupyter | Or copy and paste one of these URLs:
  5. myjupyter | http://4a27c4a06b0f:8888/?token=xxxxxxxxxxxxxxxxxxxxxxx
  6. myjupyter | or http://127.0.0.1:8888/?token=xxxxxxxxxxxxxxxxxxxxxxx

Then open your web browser and access to http://127.0.0.1:8888/?token=xxxxxxxxxxxxxxxxxxxxxxx.

You can also initialize JupyterLab as you like via

  1. $ docker-compose up lab
  • You’ll see a JupyterLab screen its theme is Monokai++ (This choice comes from my preference.) :D .

img

  • If you like to open experiments/notebook/<ournotebook>.jl, right click the file to select and Open with -> Notebook. You’re good to go.

    img

  • Note that since we adopt jupytext technology, we do not have to commit/push *.ipynb file. Namely, we can manage Jupyter Notebook as a normal source code.

  • Enjoy your Jupyter life.

Running Pluto

Pluto.jl is a lightweight reactive notebooks for Julia. Just run the following command:

using Docker Compose

  1. $ docker-compose up pluto

Then, go to localhost:9999

From Jupyter Notebook/Lab

  • Run docker-compose up jupyter and then click New button on the top right of your browser. Then select Pluto Notebook.

image

Connect to docker container with Juno/Atom (For Linux or Mac users only)

  • We we will assume you’ve installed Juno.
  • Go to Open Settings -> Julia Client -> Julia Options -> Port for Communicating with the Julia process and set value from random to 9999.

imgs

  • To connect to Docker container, open your Atom editor and open command palette(via Cmd+shift+p or Ctrl+shift+p). Then select Julia Client Connect External Process. Finally again open command palette and select Julia Client: New Terminal. You’ll see a terminal at the bottom of the Atom edetor’s screen. After that, simply run make atom or
  1. # For Mac user
  2. $ docker run --rm -it --network=host -v ${PWD}:/work -w /work myworkflowjl julia -J/sysimages/atom.so --project=@. -L .atom/init_mac.jl
  1. # For Linux user
  2. $ docker run --rm -it --network=host -v ${PWD}:/work -w /work myworkflowjl julia -J/sysimages/atom.so --project=@. -L .atom/init_linux.jl

It will show Julia’s REPL inside of the terminal. pwd() should output "/work", otherwise (e.g. ~/work/MyWorkflow.jl) you’re something wrong (opening your Julia session on your host).

  1. julia> pwd()
  2. "/work"
  • Since our Docker image adopts sysimage which include precompile statements related to Atom or Plots.jl generated by PackageCompiler.jl. You’ll find the speed of using Plots; plot(sin) is much extremely faster than that of runs on Julia session on your host.
  1. # our sysimage
  2. julia> @time begin using Plots; plot(sin) end
  3. 0.022140 seconds (38.23 k allocations: 1.731 MiB) # <- Fast
  1. # normal Julia
  2. julia> @time begin using Plots; plot(sin) end
  3. 14.006315 seconds (42.16 M allocations: 2.131 GiB, 3.86% gc time) #<- So slow ...

Create docs/test

By running make web, you can create documentation files for our packages MyWorkflow.jl, namely:

  1. $ make web
  2. julia --project=docs -e '\
  3. using Pkg;\
  4. Pkg.develop(PackageSpec(path=pwd()));\
  5. Pkg.instantiate();\
  6. include("docs/make.jl");\
  7. '
  8. Path `~/work/MyWorkflow.jl` exists and looks like the correct package. Using existing path.
  9. Resolving package versions...
  10. No Changes to `~/work/MyWorkflow.jl/docs/Project.toml`
  11. No Changes to `~/work/MyWorkflow.jl/docs/Manifest.toml`
  12. Info: Weaving chunk 1 from line 25
  13. progress = 0.0
  14. Info: Weaved all chunks
  15. progress = 1
  16. [ Info: Weaved to /Users/terasaki/work/MyWorkflow.jl/docs/src/weavesample.md
  17. [ Info: SetupBuildDirectory: setting up build directory.
  18. [ Info: Doctest: running doctests.
  19. [ Info: ExpandTemplates: expanding markdown templates.
  20. [ Info: CrossReferences: building cross-references.
  21. [ Info: CheckDocument: running document checks.
  22. [ Info: Populate: populating indices.
  23. [ Info: RenderDocument: rendering document.
  24. [ Info: HTMLWriter: rendering HTML pages.
  25. Warning: Documenter could not auto-detect the building environment Skipping deployment.
  26. @ Documenter ~/.julia/packages/Documenter/3Y8Kg/src/deployconfig.jl:75
  27. python3 -m http.server --bind 0.0.0.0 --directory docs/build
  28. Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
  • It is good idea to run using doctest:
  1. $ julia --project=@.
  2. julia>
  3. julia> using MyWorkflow, Documenter; DocMeta.setdocmeta!(MyWorkflow, :DocTestSetup, :(using MyWorkflow); recursive=true) ;doctest(MyWorkflow)
  4. [ Info: SetupBuildDirectory: setting up build directory.
  5. [ Info: Doctest: running doctests.
  6. [ Info: Skipped ExpandTemplates step (doctest only).
  7. [ Info: Skipped CrossReferences step (doctest only).
  8. [ Info: Skipped CheckDocument step (doctest only).
  9. [ Info: Skipped Populate step (doctest only).
  10. [ Info: Skipped RenderDocument step (doctest only).
  11. Test Summary: | Pass Total
  12. Doctests: MyWorkflow | 1 1
  13. Test.DefaultTestSet("Doctests: MyWorkflow", Any[], 1, false)