Pluto.jl

Pluto.jl type access

  • Operating System:

  • Terminal:

  • Shell:

  • Editor:

  • Package Manager:

  • Programming Language:

  • Utility:

  • Extension:

Pluto.jl is a modern, interactive notebook environment for the Julia programming language. It is designed to provide a reactive, intuitive, and lightweight interface for coding, data analysis, teaching, and exploration.

Key Features of Pluto.jl:

  • Reactive execution: Pluto automatically re-evaluates cells when dependencies change, ensuring that the notebook's output is always consistent with the input.

  • Lightweight and user-friendly: With minimal setup requirements and an intuitive interface, Pluto is ideal for beginners, educators, and data scientists.

  • Dynamic visualizations: Its live execution model allows users to visualize and understand code behavior dynamically, making it great for prototyping and data exploration.

For more details, visit the Pluto.jl documentation.

Setting Up Julia Environments

Julia environments provide isolated management of packages and dependencies.

Defining a custom JULIA_DEPOT_PATH streamlines environment setup and promotes consistent behavior across different deployments.

Creating a custom environment

To create a custom Julia environment during a job, follow these steps:

  1. Open the app's terminal interface and set the JULIA_DEPOT_PATH environment variable:

    export JULIA_DEPOT_PATH=/work/depot:$JULIA_DEPOT_PATH
    
    • /work/depot specifies the directory for storing the environment and compiled packages.

  2. Create and activate a new environment, then add packages:

    julia -e 'import Pkg; Pkg.activate("my_env", shared=true); Pkg.add(["package1", "package2"])'
    
    • my_env is the name of the custom environment.

    • Replace package1 and package2 with the desired package names.

After creating the environment, the /work/depot directory will have the following structure:

/work/depot/
├── compiled
│   └── v1.11
├── environments
│   └── my_env
├── logs
│   ├── artifact_usage.toml
│   └── manifest_usage.toml
├── packages
│   ├── package1
│   └── pakcage2
├── registries
└── scratchspaces

The depot folder will remain accessible on UCloud after the job completes.

Activating the environment

To use the custom environment in a Pluto.jl notebook:

  1. Import the depot folder into the application via the Select folders to use option.

  2. Open a Pluto notebook and activate the environment by running:

    import Pkg
    Pkg.activate("my_env", shared=true)
    
  3. View the installed packages in the environment:

    Pkg.status()
    

Pluto.jl Notebook Settings

  1. Automatically opening a notebook file: You can specify the path to a Pluto.jl notebook file that should open automatically when the server starts. This is particularly useful for predefined workflows or presentations.

  2. Optimizing performance with distributed workers: Pluto.jl can use multiple distributed Julia workers for parallel computation. This is especially beneficial for large-scale data analysis or computations.

Automating Initialization

Pluto can be started with the Initialization optional parameter to run a script that pre-installs the required Julia packages. This method ensures that dependencies are available at application startup without relying on a persistent Julia environment.

Example of a Bash script

#!/bin/bash

# Function to display an error and exit
function exit_err {
    echo "$1" >&2
    exit 1
}

# Array of package specifications (name and version separated by a colon)
JULIA_PACKAGES=( "DataFrames" "RDatasets" )

# Build the Julia code to install packages with specified versions
JULIA_CODE="
using Pkg
"

for pkg_spec in "${JULIA_PACKAGES[@]}"; do
    IFS=':' read -r pkg version <<< "$pkg_spec"
    if [ -n "$version" ]; then
        JULIA_CODE+="
println(\"Installing $pkg@$version...\")
Pkg.add(PackageSpec(name=\"$pkg\", version=\"$version\"))
println(\"$pkg@$version installed successfully.\")
"
    else
        JULIA_CODE+="
println(\"Installing $pkg...\")
Pkg.add(\"$pkg\")
println(\"$pkg installed successfully.\")
"
    fi
done

# Run the Julia code
echo "Installing Julia packages with specified versions..."
julia -e "$JULIA_CODE" || exit_err "Failed to install Julia packages."

echo "Julia package installation completed successfully."

The JULIA_PACKAGES array can be customized to include the desired package