-
Notifications
You must be signed in to change notification settings - Fork 0
Developer Notes
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 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.
- Add the package to your current project (in julia package manager: add Infiltrator)
- Add to the top of your script
using Infiltrator - Then add @infiltrate anywhere in your script.
- 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.
Happy debugging!
- 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
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:
rootFolder = /path/to/directory/addpath(genpath(rootFolder))-
savepath(to make it permanent)
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.
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"
}
```
There is a convenient formatter available for MATLAB.
- Install MATLAB, Visual Studio Code, and the MATLAB extension by MathWorks.
- Verify installation by:
- Running
where matlabin the VSC terminal - Seeing “MATLAB: Connected” in the bottom bar
- Running a
.mfile
- Running
- Verify installation by:
- Install the extension matlab-formatter by AftenWiesel.
- Format manually using:
- macOS:
Option + Shift + F - Windows:
Shift + Alt + F
- macOS:
- Enable auto-format on save by adding to
settings.json:"[matlab]": { "editor.defaultFormatter": "MatlabFormatter.matlab-formatter", "editor.formatOnSave": true }
LLVM/Clang-Format is a commonly used auto-formatter for C.
- Install LLVM:
- https://github.com/llvm/llvm-project/releases/tag/llvmorg-18.1.8
- On Windows, download
LLVM-18.1.8-win64.exe - During installation, enable the option to add LLVM to PATH
- Install Clang-Format extension by Xaver Hellauer in Visual Studio Code.
- Configure the formatter:
- Open
settings.json - Add:
"clang-format.executable": "C:\\Program Files\\LLVM\\bin\\clang-format.exe"
- Open
- Enable auto-format on save:
"[c]": { "editor.defaultFormatter": "xaver.clang-format", "editor.formatOnSave": true }
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:
- Configure Black and isort to run on save following: https://cereblanco.medium.com/setup-black-and-isort-in-vscode-514804590bf9
Best coding practices:
- Code formatting: PEP8
- Docstrings: PEP257 (Google-style, with PEP484 type hints)
- Type hinting: PEP484
- Boy/Girl Scout rule
- SOLID principles
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")