Getting Started

Estimated time: 1-1.5 hours (includes package installation and Julia’s first-run compilation)

Introduction

This course uses Julia for all code examples and exercises. This page helps you set up your computing environment before the course begins.

ImportantJulia compiles code on first use

Unlike R or Python, Julia compiles functions the first time you run them. This means:

  • First run of any function is slow (seconds to minutes for complex packages)
  • Subsequent runs are fast (compiled code is cached for the session)
  • Restarting Julia loses the cache (compilation happens again)

This “time to first plot” or “TTFX” is a known Julia trade-off. The payoff is that your code runs much faster once compiled. During the course:

  • Expect the first using Turing to take 10-30 seconds
  • Expect the first MCMC sample to take longer than subsequent ones
  • If something seems stuck, wait a minute before assuming it’s broken

Three ways to engage with the course:

  1. Web only: Read the materials online without running code. Fine for an overview, but you’ll learn more by doing.
  2. Local installation: Install Julia and run everything on your own machine. Recommended for the full experience.
  3. Cloud option: Use a pre-configured cloud environment (if provided by your instructor).

Local installation

Step 1: Install Julia

Download Julia from julialang.org/downloads. We recommend version 1.11 or later.

Installation options:

  • juliaup (recommended): A version manager that makes it easy to install and switch between Julia versions
    • Windows: winget install julia -s msstore
    • macOS/Linux: curl -fsSL https://install.julialang.org | sh
  • Direct download: Get the installer for your platform from the downloads page

After installation, open a terminal and verify Julia is working:

julia --version

You should see something like julia version 1.11.2.

Step 3: Clone the course repository

Back in your terminal (not the Julia REPL), download the course materials:

git clone https://github.com/sbfnk/mfiidd.julia.git
cd mfiidd.julia

If you don’t have git, you can download the repository as a ZIP file from the GitHub page.

Then open the course folder in VS Code: either run code mfiidd.julia from the terminal, or use File → Open Folder in VS Code and navigate to the mfiidd.julia directory.

Step 4: Install Julia packages

With the mfiidd.julia folder open in VS Code, start the Julia REPL: press Ctrl+Shift+P (or Cmd+Shift+P on macOS), type “Julia: Start REPL”, and press Enter. The REPL should open in the bottom panel showing a julia> prompt.

Now activate the project environment and install packages:

using Pkg
Pkg.activate(".")
Pkg.instantiate()

Pkg.activate(".") tells Julia to use the course’s own set of packages rather than your global installation — think of it as a self-contained library that ensures everyone has the same package versions. Pkg.instantiate() then reads Project.toml and Manifest.toml to download and install those exact versions.

WarningExpect a long wait on first run

Package installation typically takes 15-30 minutes depending on your internet connection and computer speed. The process downloads ~1GB of packages and then precompiles them. This is a good time to get a coffee or read ahead in the course materials. If installation takes more than 45 minutes, check your internet connection or see the Troubleshooting section below.

What to expect in the console:

  Downloading artifact: LLVM...
  Downloading artifact: GR...
    Updating registry at `~/.julia/registries/General.toml`
   Resolving package versions...
  Downloaded Turing ─ v0.35.0
  Downloaded DifferentialEquations ─ v7.15.0
  ...many more packages...
Precompiling project...
  ✓ Distributions
  ✓ OrdinaryDiffEq
  ...many more...
  72 dependencies successfully precompiled in 342 seconds

Warnings about “precompilation may be incomplete” are usually harmless. The process is complete when you see the julia> prompt again.

Step 5: Verify the installation

ImportantRun this before the course starts

Don’t skip this step. Package installation can succeed while something is still broken. Run the verification code below to confirm everything works. If you hit errors, you’ll have time to troubleshoot before the course begins.

Test that core packages load correctly by copying the code below into your Julia REPL (the julia> prompt from step 4). You can paste the whole block at once — Julia will run each line in order:

using Turing
using DifferentialEquations
using Plots

# Quick test: sample from a simple model
@model function coin_flip(n)
    p ~ Beta(1, 1)
    k ~ Binomial(n, p)
end

chain = sample(coin_flip(10) | (; k = 7), NUTS(), 100)
println("Installation successful!")

The | operator conditions the model on observed data. Here, coin_flip(10) | (; k = 7) means “run the coin flip model with 10 trials, given that we observed 7 heads”. Turing then infers the posterior distribution of p (the coin’s bias). You’ll see this pattern throughout the course — we’ll explain it in detail in the MCMC session.

The first time you run this, expect it to take a minute or two as Julia compiles the packages (see the note about compilation above). If it completes without errors and prints “Installation successful!”, you’re ready for the course. If you see errors, check the Troubleshooting section below.

Troubleshooting

“Package X not found”

Make sure you’ve activated the project environment:

using Pkg
Pkg.activate(".")  # Note the dot - this activates the current directory
Pkg.status()       # Should show course packages, not your global environment

Slow package loading

Julia compiles code on first use. The first using Turing in a session takes longer than subsequent calls. This is normal. For faster startup during development, consider PackageCompiler.jl or Revise.jl.

Windows-specific issues

  • Long path errors: Enable long paths in Windows settings or use a shorter installation path
  • Firewall prompts: Allow Julia through your firewall for package downloads

macOS Apple Silicon

Julia runs natively on Apple Silicon (M1/M2/M3). Ensure you download the macOS (Apple Silicon) version, not the Intel version.

Updating before the course

If you installed the packages days or weeks before the course, update them:

using Pkg
Pkg.activate(".")
Pkg.update()
Pkg.precompile()

Working with the materials

Quarto documents (.qmd)

Course sessions are Quarto documents (.qmd) combining text and executable Julia code. If you’ve used RMarkdown before, Quarto is its successor — same idea, but language-agnostic. To render a session:

quarto preview sessions/introduction.qmd

Or render the entire site:

quarto preview

Running code interactively

In VS Code with the Julia extension:

  1. Open a .qmd file
  2. Place cursor in a code block
  3. Press Shift+Enter to execute and move to next block
  4. Or Ctrl+Enter to execute without moving

Alternatively, copy code into the Julia REPL.

Session checklist

Before starting, verify you can:

If all boxes are ticked, you’re ready. Head to the Course Structure for an overview, or jump straight to the Introduction.