Edit or run this notebook
Scientific Computing TU Berlin Winter 2021/22 © Jürgen Fuhrmann
Notebook 03
1.7 ms
238 ms
6.1 ms

Julia workflows

When working with Julia, we can choose between a number of workflows.

5.9 Î¼s

Pluto notebook

This ist what you see in action here. After calling pluto, you can start with an empty notebook and add cells.

Great for teaching or trying out ideas.

8.2 Î¼s

Jupyter notebook

With the help of the package IJulia.jl it is possible to work with Jupyter notebooks in the browser. The Jupyter system is rather complex and Pluto hopefully will be able to replace it, in particular because of its reactivity features.

7.3 Î¼s

"Classical" workflow

Use a classical code editor (emacs, vi or whatever you prefer) in a separate window and edit files, when saved to disk run code in a console window.

With Julia, this workflow has the disadvantage that everytime Julia is started, the just-in-time compiler (JIT) needs to recompile all the code to be run if its compiled version is not cached.

While a significant part of the compiled code of installed packages is cached, Julia needs to assume that the code you write can have changed.

  • Remedy: Never leave Julia, start a permanent Julia session, include edited code after each change.

2.4 ms

The REPL

aka Read - Eval - Print - Loop or Julia command prompt

One enters the REPL when one starts julia in a console window without giving filename.

The REPL allows to execute Julia statements in an interactive fashion. It has convenient editing capabilities.

9.1 Î¼s

Helpful commands in the REPL default mode:

commmandaction
quit() or Ctrl+Dexit Julia
Ctrl+Cinterrupt execution
Ctrl+Lclear screen
Append ;suppress displaying return value
include("filename.jl")source a Julia code file and execute content
14.0 Î¼s

The REPL has different modes which can be invoked by certain characters:

modepromptenter/exit
Defaultjuliabackspace in other modes to enter
Helphelp?>? to enter
type command name to search
Shellshell>; to enter
type command to execute
Package managerPkg>] to enter
14.9 Î¼s

Revise.jl

The Revise.jl package allows to keep track of changed files used in a Julia session if they have been included via includet (t for "tracked"). It controls recompilation of changed code - only those parts which indeed have changed are newly compiled by the JIT, moreover, recompilation is triggered automatically, no need to include code again and again.

In order to make this work, one needs to add

if isinteractive()
    try
        @eval using Revise
        Revise.async_steal_repl_backend()
    catch err
        @warn "Could not load Revise."
    end
end

to the startup file ~/.julia/config/startup.jl and to run Julia via julia -i.

Revise.jl also keeps track of packages loaded and their changes. In this setting it also can be used with Pluto.

6.9 Î¼s

Recommendation

When using the REPL based workflow, don't miss Revise.jl and try to find a Julia mode for your favorite editor which provides auto-indentation, highlighteing etc. Mine (emacs) has one.

5.8 Î¼s

IDE based workflow

Use an IDE (integrated development environment). Currently the best one for Julia is Visual Studio Code with the Julia extension.

For introductory material, see the tutorial information given upon starting of a newly installed instance of code. For the Julia extension, find videos on code Julia for Talented Amateurs.

6.9 Î¼s

Packages

1.8 Î¼s

Structure of a package

  • Packages are modules searched for in a number of standard places and as git repositories on the internet

  • Locally, each package is stored in directory named e.g. MyPack for a package MyPack.jl.

  • Structure of a package Directory:

    • Subdirectory MyPack/src for sources

    • Main source MyPack/src/MyPack.jl defining a module named MyPack

    • Further Julia sources in MyPack/src/ included by MyPack/src/MyPack.jl

    • Code for unit testing in MyPack/test

      • a well designed package has a good number of tests which are run upon every upload on github

    • Code for documentation generation in MyPack/docs

      • a well designed package has documentation generated upon every upload on github

    • License

      • Packages in the general registry (see below) are required to have an open source license

    • Metadata

15.3 Î¼s

Metadata

Package metadata are stored in MyPack/Project.toml

  • Name

  • Unique Universal Identifier (UUID) - a long character string hopefully unique in the world

  • Author

  • Version number

  • Package dependencies (names and UUIDs)

  • Version bounds for package dependencies

9.1 Î¼s

Environments

Environments (projects) are essentially lists of packages used in a current Julia session. An environment is described by a directory containing at least two metadata files:

  • Project.toml describing the list of packages required for the project

  • Manifest.toml describing the actually installed versions of the required packages and all their dependencies

1.5 ms

Global environment

By default, a global environment stored in .julia/environments/vX.Y under the user home directory will be used

4.9 Î¼s

Local environments

In oder to avoid version clashes for different projects, one can activate any directory - e.g. mydir as a local package environment by invoking Julia with

julia --project=mydir

3.5 Î¼s

Package manager

  • Default packages (e.g. the package manager Pkg) are always found in the .julia subdirectory of your home directory

  • The package manager allows to add packages to your installation by finding their git repositories via the Julia General Registry or another registry

    • Packages are found via the UUID

    • During package installation, compatibility is checked accordint to the [compat] entries in the respective Project.toml files

9.0 Î¼s

Basic package manager commands

The package manager can be used in two ways: via the Pkg REPL mode or via Julia function calls after havig invoked using Pkg.

Functionpkg modeExplanation
Pkg.add("MyPack")pkg> add MyPackadd MyPack.jl to current environment
Pkg.rm("MyPack")pkg> rm MyPackremove MyPack.jl from current environment
Pkg.update()pkg> upupdate packages in current environment
Pkg.activate("mydir")pkg> activate mydiractivate directory as current environment
Pkg.instantiate()pkg> instatiatepopulate current environment according to Manifest.toml
Pkg.test("MyPack")pkg> test mypackrun tests of MyPack.jl
Pkg.status()pkg> statuslist packages

For more information, see the documentation of the package manager

18.9 Î¼s
Loading...
ii
Loading...