Setting up GPEC
On Windows via WSL (Ubuntu)
Install WSL and Ubuntu If you don't already have WSL and Ubuntu installed, set this up. This page gives detailed instructions on how to complete the installation. In the Windows Powershell,
- Make sure WSL is installed:
PowerShell wsl --install - Set Ubuntu as your default WSL distro:
PowerShell wsl --set-default Ubuntu - Launch Ubuntu and update:
PowerShell sudo apt update && sudo apt upgrade -y
- Make sure WSL is installed:
Install build tools in WSL
shell sudo apt install build-essential cmake -ybuild-essential→ GCC, makecmake→ sometimes needed by dependenciesInstall Julia in WSL
Download the latest Linux tarball from the official site Julia downloads. It will look like
shell wget https://julialang-s3.julialang.org/bin/linux/x64/1.11/julia-1.11.3-linux-x86_64.tar.gz☆ Replace the URL with the latest stable version.
Extract and move it to /opt (or any path):
shell tar -xvzf julia-1.11.3-linux-x86_64.tar.gz sudo mv julia-1.11.3 /opt/☆ Ensure these commands match the tarball you installed. These commands match the above tarball and might need to be modified for you installation.
Add Julia to PATH:
shell echo 'export PATH=/opt/julia-1.11.3/bin:$PATH' >> ~/.bashrc source ~/.bashrcTest it is properly installed
shell julia --version
Clone GPEC into your WSL home folder:
shell git clone https://github.com/OpenFUSIONToolkit/GeneralizedPerturbedEquilibrium.git cd GeneralizedPerturbedEquilibriumInstall the Julia packages for GPEC
- Launch Julia:
shell julia - In Julia REPL:
julia using Pkg Pkg.instantiate() # install recorded dependencies Pkg.add("Preferences") # install missing dependency if needed Pkg.precompile() # precompile all packages - probably unnecessary
- Launch Julia:
At this point, you should be able to run the code or connect VS Code to your WSL session.
(Optionally) Integrate WSL with VS Code
- Install Remote - WSL extension in VS Code.
- Open VS Code → Connect To → Connect to WSL.
- Click Open Folder and then navigate to the GPEC folder on your VM. Open your GPEC folder from WSL: ~/GeneralizedPerturbedEquilibrium.
If this is not working, you can launch vscode from the WSL shell you have using the command
code .- Open a terminal inside VS Code — it will automatically use WSL/Ubuntu.
- You can now run Julia scripts directly from the terminal.
Run GPEC
- Launch Julia and run your scripts as usual:
shell include("path/to/script.jl")
- Launch Julia and run your scripts as usual:
On macOS
Prerequisites
Before starting, you'll need a Terminal app to enter commands. You can find it by:
- Press
Cmd + Spaceto open Spotlight - Type "Terminal" and press Enter
Keep this Terminal window open throughout the installation process.
1. Install Xcode Command Line Tools
These tools provide the compilers and build utilities needed by GPEC's dependencies.
Open Terminal and run:
xcode-select --installA dialog will appear asking you to install the tools. Click "Install" and wait for it to complete (this may take several minutes).
Verify installation:
gcc --versionYou should see output showing the GCC version.
2. Install Homebrew (Package Manager)
Homebrew makes it easy to install software on macOS. If you already have Homebrew installed, skip to step 3.
Install Homebrew by running this command in Terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Follow the on-screen instructions. You may need to enter your Mac password.
After installation completes, the installer will show you two commands to run to add Homebrew to your PATH. They will look something like:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile eval "$(/opt/homebrew/bin/brew shellenv)"Important: Copy and run these exact commands from your Terminal output.
Verify Homebrew is installed:
brew --version
3. Install Julia
Julia is the programming language GPEC is written in.
Option A: Install via Homebrew (Recommended for beginners)
Install Julia:
brew install juliaVerify Julia is installed:
julia --versionYou should see something like
julia version 1.11.x.
Option B: Install via Official Installer
Download the macOS installer (
.dmgfile) for the latest stable version (1.11 or higher)Open the downloaded
.dmgfile and drag Julia to your Applications folderAdd Julia to your PATH by running in Terminal:
sudo mkdir -p /usr/local/bin sudo ln -s /Applications/Julia-1.11.app/Contents/Resources/julia/bin/julia /usr/local/bin/juliaReplace
1.11with your actual version if different.Verify Julia is installed:
julia --version
4. Clone the GPEC Repository
Now we'll download the GPEC code from GitHub.
Choose where you want to put GPEC. For example, your home directory:
cd ~Or create a Code folder:
mkdir -p ~/Code cd ~/CodeClone GPEC from GitHub:
git clone https://github.com/OpenFUSIONToolkit/GeneralizedPerturbedEquilibrium.gitIf you don't have
gitinstalled, macOS will prompt you to install it.Enter the GPEC directory:
cd GeneralizedPerturbedEquilibrium
5. Install Julia Packages
Now we'll install all the Julia packages that GPEC depends on.
Launch Julia from the GPEC directory:
julia --project=.The
--project=.flag tells Julia to use the GPEC project environment.You should now see the Julia prompt:
julia>Install all dependencies by typing these commands in the Julia prompt:
using Pkg Pkg.instantiate()This will download and install all required packages. It may take several minutes the first time.
Precompile all packages (optional, but speeds up first use):
Pkg.precompile()Test that GPEC loads correctly:
using GeneralizedPerturbedEquilibriumIf you see no errors, everything is working!
Exit Julia:
exit()
6. Run an Example
Now you're ready to run GPEC! See the Running GPEC section below for full details. As a quick test:
Make sure you're in the GPEC directory:
cd ~/Code/GeneralizedPerturbedEquilibriumRun GPEC on one of the included examples:
./gpec examples/DIIID-like_ideal_exampleThe first time you run GPEC, it will take a few minutes to compile. Subsequent runs will be faster.
7. Troubleshooting
If Julia can't find packages:
Make sure you're running Julia with the project environment:
cd ~/Code/GeneralizedPerturbedEquilibrium
julia --project=.If you get permission errors:
Make sure you have write permissions in the GPEC directory. You may need to use sudo for some Homebrew commands, but avoid using sudo with Julia commands.
Alternative: Using VS Code (Optional)
VS Code provides a convenient IDE for developing with GPEC:
Install VS Code from https://code.visualstudio.com/
Install the Julia extension:
- Open VS Code
- Click the Extensions icon (or press
Cmd + Shift + X) - Search for "Julia" and install the official Julia extension
Open the GPEC folder in VS Code:
- Click File → Open Folder
- Navigate to and select your GPEC directory
Open a terminal inside VS Code (Terminal → New Terminal) and run scripts directly:
julia --project=. path/to/script.jl
Running GPEC
Once GPEC is installed and built, you can run it in two ways:
As a Command-Line Script
GPEC includes an executable script (gpec) in the project root directory. To run GPEC on a directory containing a gpec.toml configuration file:
./gpec path/to/directoryExample:
# Run GPEC on one of the included examples
./gpec examples/DIIID-like_ideal_example
# Run in the current directory (must contain gpec.toml)
./gpecThe script will:
- Read configuration from
gpec.tomlin the specified directory - Load or generate the equilibrium based on the
[Equilibrium]section - Compute force-free states (stability analysis) based on the
[ForceFreeStates]section - If a
[PerturbedEquilibrium]section exists, compute the plasma response to external perturbations - Write output to HDF5 files as configured
Early Termination: You can stop execution early by setting:
force_termination = truein[Equilibrium]to stop after equilibrium setupforce_termination = truein[ForceFreeStates]to stop after stability analysis (before perturbed equilibrium)
As a Julia Library
You can also use GPEC programmatically in your own Julia scripts:
using GeneralizedPerturbedEquilibrium
# Run the full GPEC analysis pipeline
GeneralizedPerturbedEquilibrium.main(["path/to/directory"])
# Or access individual modules
using GeneralizedPerturbedEquilibrium.Equilibrium
using GeneralizedPerturbedEquilibrium.Vacuum
using GeneralizedPerturbedEquilibrium.ForceFreeStates
# Set up equilibrium only
equil = Equilibrium.setup_equilibrium("path/to/gpec.toml")
# Access equilibrium data
println("q at axis: ", equil.params.q0)
println("Beta-N: ", equil.params.betan)Configuration Files
GPEC uses TOML configuration files (gpec.toml) with the following main sections:
[Equilibrium]: Equilibrium solver settings (input file, grid resolution, coordinate system, etc.)[Wall]: Wall geometry for vacuum calculations (shape, size, position)[ForceFreeStates]: Stability analysis settings (mode numbers, tolerances, flags)[PerturbedEquilibrium]: Plasma response settings (forcing data, output options)
See the example directories for complete configuration file templates.
Developer Tips
Revise.jl
When iterating on code, use Revise.jl to avoid full recompilation on every change. It tracks source file modifications and recompiles only the affected code.
Install Revise in your global Julia environment (not in this project's Project.toml):
# In the Julia REPL (no --project flag)
using Pkg
Pkg.add("Revise")Then load it before GeneralizedPerturbedEquilibrium in any session:
using Revise
using GeneralizedPerturbedEquilibriumFor it to load automatically, add using Revise to your Julia startup file:
# ~/.julia/config/startup.jl
try
using Revise
catch e
@warn "Could not load Revise" exception=e
endPre-commit Hooks
The repository uses pre-commit hooks to maintain code quality. They run automatically on git commit and:
- Format Julia code according to
.JuliaFormatter.tomlsettings - Remove trailing whitespace and fix line endings
- Validate YAML/TOML syntax
- Prevent accidentally committing large files (>5MB)
Installation:
# Install pre-commit (requires Python/pip)
pip install pre-commit
# Install JuliaFormatter globally (required for Julia code formatting hook)
julia -e 'using Pkg; Pkg.add("JuliaFormatter")'
# Install the git hooks in your local repository
cd /path/to/GPEC
pre-commit installYou can also run the hooks manually without committing:
pre-commit run --all-files # run on all files
pre-commit run # run on staged files onlyIn rare cases where you need to bypass the hooks:
git commit --no-verifyThis is discouraged as it may introduce formatting inconsistencies.