Skip to content

Developer Notes

ajvanamerongen edited this page Mar 23, 2026 · 9 revisions

Welcome to DevNotes. Here you can place any tips & tricks that could be useful for your colleagues. At the bottom of this page is a list of common mistakes and how to resolve them. Please add any you've found yourself.

Debugging Julia using Infiltrator

Debugging is often done with Visual Studio Code's built-in debugger. However, it does not support the latest Julia syntax and fails. A useful package to debug is Infiltrator.jl.

  1. Add the package to your current project (in julia package manager: add Infiltrator)
  2. Add to the top of your script using Infiltrator
  3. Then add @infiltrate anywhere in your script.
  4. Run your script from a non-VSC terminal with 'julia --project /path/to/script.jl'

You then have an active REPL session with the local variables. Type a variable to investigate it, or run @locals for an immediate glance at your local variables. Use '?' for a quick overview of options.

image

Happy debugging!

Software to use

  • Terminals
    • Mac's integrated terminal
    • Windows: Git bash terminal (has a nice layout that tracks your environment and current git branch)
  • Integrated Development Environments
    • Vim (simple, lightweight, good for editing simple scripts on remote cluster)
    • Visual Studio Code
    • Spyder (good for checking variables_
    • Jupyter Notebooks
  • Document transfer software
    • Filezilla
    • Moba XTerm
  • Visualization
    • Paraview

Improving your Visual Studio Code

Matlab in VSC

Add your project to the MATLAB PATH so VSC can run without changing the working directory. Otherwise, it will give you a warning pop-up and ask you to change the working directory every time.

  • In a VSC MATLAB terminal, run these three commands:
    1. rootFolder = /path/to/directory/
    2. addpath(genpath(rootFolder))
    3. savepath (to make it permanent)

(Auto-)formatters

When collaborating on code, it can be convenient to agree on and enforce a certain default layout of the code. Some examples are the number of spaces used for indentation, whether to write equations as y=ax+b or y = a * x + b, and whether or not to split long lines of code over multiple lines.

Python has a community-agreed standard style called PEP8. Standards also exist for C, MATLAB, and Julia, although it is unclear whether these are universally adopted. Using a standard improves readability and collaboration.

Formatters are extensions for Visual Studio Code that format your code when pressing:

  • macOS: Option + Shift + F
  • Windows: Shift + Alt + F

Auto-formatters can also be configured to run automatically on file save.

Below is a step-by-step walkthrough for setting up auto-formatters for Julia, C, MATLAB, and Python.

Julia (Runic)

  1. Runic repository: https://github.com/fredrikekre/Runic.jl
  2. JustRelax uses Runic for formatting. It is strict and enforces a consistent layout across all files.
  3. ChatGPT prompt used:
     > “the project i work on, justrelax.jl, mentions it uses code style 'runic.jl'. please elaborate, and can you help with how i use it? I'm used to using Black formatter in python and format on save. is this similar and how do i use it?”

  4. In a VSC bash terminal:
     1. Add Runic in a separate environment:
        ```bash
        julia --project=@runic --startup-file=no -e 'using Pkg; Pkg.add("Runic")'
        ```
     2. Add executables so Runic can be run from the command line:
        ```bash
        mkdir -p ~/.local/bin
        curl -fsSL -o ~/.local/bin/runic https://raw.githubusercontent.com/fredrikekre/Runic.jl/refs/heads/master/bin/runic
        chmod +x ~/.local/bin/runic
        curl -fsSL -o ~/.local/bin/git-runic https://raw.githubusercontent.com/fredrikekre/Runic.jl/refs/heads/master/bin/git-runic
        chmod +x ~/.local/bin/git-runic
        ```
     3. Add Runic to PATH:
        - Temporary:
          ```bash
          export PATH="$HOME/.local/bin:$PATH"
          ```
        - Permanent: add the above line to `~/.bashrc` and reload using:
          ```bash
          source ~/.bashrc
          ```
     4. Verify installation:
        ```bash
        runic --help
        runic --version
        ```
     5. Format files manually:
        ```bash
        runic --inplace <path/to/file/or/directory>
        ```
     6. Enable auto-format on save:
        1. Install the VS Code extension **Custom Local Formatters**
        2. Install `juliaformatter` in the Julia REPL
        3. Add the following to `settings.json`:
           ```json
           "[julia]": {
               "editor.formatOnSave": true,
               "editor.defaultFormatter": "julialang.language-julia"
           }
           ```

Auto-formatter for MATLAB

There is a convenient formatter available for MATLAB.

  1. Install MATLAB, Visual Studio Code, and the MATLAB extension by MathWorks.
    • Verify installation by:
      • Running where matlab in the VSC terminal
      • Seeing “MATLAB: Connected” in the bottom bar
      • Running a .m file
  2. Install the extension matlab-formatter by AftenWiesel.
  3. Format manually using:
    • macOS: Option + Shift + F
    • Windows: Shift + Alt + F
  4. Enable auto-format on save by adding to settings.json:
    "[matlab]": {
        "editor.defaultFormatter": "MatlabFormatter.matlab-formatter",
        "editor.formatOnSave": true
    }

Auto-formatter for C

LLVM/Clang-Format is a commonly used auto-formatter for C.

  1. Install LLVM:
  2. Install Clang-Format extension by Xaver Hellauer in Visual Studio Code.
  3. Configure the formatter:
    1. Open settings.json
    2. Add:
      "clang-format.executable": "C:\\Program Files\\LLVM\\bin\\clang-format.exe"
  4. Enable auto-format on save:
    "[c]": {
        "editor.defaultFormatter": "xaver.clang-format",
        "editor.formatOnSave": true
    }

Advanced Visual Studio Code extensions

Install Visual Studio Code as your IDE.

Recommended extensions:

  • autoDocstring – Python Docstring Generator
  • Black – Python code formatter (PEP8)
  • Jupyter
  • Markdown All in One
  • Pylance
  • Python
  • MATLAB
  • Rewrap
  • Code Spell Checker

Advanced formatting settings:

Best coding practices:

  1. Code formatting: PEP8
  2. Docstrings: PEP257 (Google-style, with PEP484 type hints)
  3. Type hinting: PEP484
  4. Boy/Girl Scout rule
  5. SOLID principles

Common mistakes

Running Julia on Eejit

CUDA.jl could not find an appropriate CUDA runtime to use.

When using CUDA on an interactive (GPU) node, Bert got this error (9 march 2026). If it complains about a CUDA version, it means that the cluster interpreted and precompiled CUDA on the login node. In that case, it precompiled without knowing what GPU's we use. This means that you need to provide info to julia what CUDA to expect.

In a Julia REPL session (while on an eejit interactive gpu node):

   using CUDA
   CUDA.set_runtime_version!(v"12.5")