When a Julia program is executed, Julia first loads and parses all code. Then,
the just-in-time compiler has to compile all functions at their first use, which
incurs an overhead each time a program is run. For proper packages and commands
executed in the REPL (= "return-eval-print loop", which is what the Julia
community calls the interactive command-line prompt that opens when executing
julia without any files as arguments), however, the previously compiled functions are
cached. Therefore, Trixi.jl should generally always be used interactively from the
REPL without closing Julia during development, as it allows much faster turnaround times.
If you naively run Trixi.jl from the REPL, you will not be able to change your
Trixi.jl source files and then run the changed code without restarting the REPL,
which destroys any potential benefits from caching. However, restarting
Julia can be avoided by using the Revise.jl
package, which tracks changed files and re-loads them automatically. Therefore,
it is highly recommended to first install Revise with the following command in Julia:
To enter the package REPL mode, press ] in the standard Julia REPL mode. Then, execute
(@v1.9) pkg> add ReviseNow you are able to run Trixi.jl from the REPL, change Trixi.jl code between runs, and enjoy the advantages of the compilation cache! Before you start using Revise regularly, please be aware of some of the Pitfalls when using Revise.
Another recommended package for working from the REPL is OhMyREPL.jl. It can be installed by running
(@v1.9) pkg> add OhMyREPLand adds syntax highlighting, bracket highlighting, and other helpful improvements for using Julia interactively. To automatically use OhMyREPL when starting the REPL, follow the instructions given in the official documentation.
If you've installed Trixi.jl and Revise in your default environment, begin by executing:
juliaThis will start the Julia REPL. Then, run
julia> using Revise; using TrixiYou can run a simulation by executing
julia> trixi_include(default_example())Together, all of these commands can take some time, roughly half a minute on a modern workstation. Most of the time is spent on compilation of Julia code etc. If you execute the last command again in the same REPL, it will finish within a few milliseconds (maybe ~45 on a modern workstation). This demonstrates the second reason for using the REPL: the compilation cache. That is, those parts of the code that do not change between two Trixi.jl runs do not need to be recompiled and thus execute much faster after the first run.
If you followed the [installation instructions for developers](@ref for-developers), execute
Julia with the project directory set to the run directory of the
program/tool you want to use.
For example, to run Trixi.jl this way, you need to start the REPL with
julia --project=path/to/Trixi.jl/runand execute
julia> using Revise; using Trixito load Revise and Trixi.jl. You can then proceed with the usual commands and run Trixi.jl as in
the example above.
The --project flag is required such that Julia can properly load Trixi.jl and all dependencies
if Trixi.jl is not installed in the global environment. The same procedure also
applies should you opt to install the postprocessing tool
Trixi2Vtk
manually such that you can modify their implementations.
While Revise is a great help for developing Julia code, there are a few situations to watch out for when using Revise. The following list of potential issues is based on personal experiences of the Trixi.jl developers and probably incomplete. Further information on limitations and possible issues with Revise can be found in the official documentation.
!!! tip "If in doubt, restart the REPL" Oftentimes, it is possible to recover from issues with Revise by fixing the offending code. Sometimes, however, this is not possible or you might have troubles finding out what exactly caused the problems. Therefore, in these cases, or if in doubt, restart the REPL to get a fresh start.
Revise does not stop on syntax errors, e.g., when you accidentally write
a[i) instead of a[i]. In this case, Revise reports an error but continues
to use the old version of your files! This is especially dangerous for syntax
errors, as they are detected while Revise reloads changed code, which happens in
the beginning of a new execution. Thus, the syntax error message quickly
disappears from the terminal once Trixi.jl starts writing output to the screen and
you might not even have noticed that an error occurred at all.
Therefore, when you are deep in a coding/debugging session and wonder why your code modifications do not seem to have any effect, scroll up in your terminal to check if you missed earlier syntax errors, or - if in doubt - restart your REPL.
Sometimes, Revise stops tracking files when changing the Git branch. That is, modifications to Trixi.jl's source files will not be reloaded by Revise and thus have no effect of a currently running REPL session. This issue is particularly annoying for a developer, since it does not come with any warning! Therefore, it is good practice to always restart the REPL after changing branches.
Revise cannot handle changes to type definitions, e.g., when modifying the
fields in a struct. In this case, Revise reports an error and refuses to run
your code unless you undo the modifications. Once you undo the changes, Revise
will usually continue to work as expected again. However, if you want to keep
your type modifications, you need to restart the REPL.
The Julia manual is an excellent resource to learn Julia. Here, we list some helpful commands than can increase your productivity in the Julia REPL.
- Use the REPL help mode
entered by typing
?.julia> using Trixi help?> trixi_include search: trixi_include trixi_include([mod::Module=Main,] elixir::AbstractString; kwargs...) include the file elixir and evaluate its content in the global scope of module mod. You can override specific assignments in elixir by supplying keyword arguments. It's basic purpose is to make it easier to modify some parameters while running Trixi.jl from the REPL. Additionally, this is used in tests to reduce the computational burden for CI while still providing examples with sensible default values for users. Examples ≡≡≡≡≡≡≡≡≡≡ julia> trixi_include(@__MODULE__, default_example(), tspan=(0.0, 0.1)) [...] julia> sol.t[end] 0.1
- You can copy and paste REPL history including
julia>prompts into the REPL. - Use tab completion in the REPL, both for names of functions/types/variables and
for function arguments.
julia> flux_ranocha( # and TAB flux_ranocha(u_ll, u_rr, orientation::Integer, equations::CompressibleEulerEquations1D) in Trixi at ~/.julia/dev/Trixi/src/equations/compressible_euler_1d.jl:390 flux_ranocha(u_ll, u_rr, orientation::Integer, equations::CompressibleEulerEquations2D) in Trixi at ~/.julia/dev/Trixi/src/equations/compressible_euler_2d.jl:839 [...]
- Use
methodswithto discover methods associated to a given type etc.julia> methodswith(CompressibleEulerEquations2D) [1] initial_condition_convergence_test(x, t, equations::CompressibleEulerEquations2D) in Trixi at ~/.julia/dev/Trixi/src/equations/compressible_euler_2d.jl:51 [...]
- Use
@which(or@edit) for method calls.julia> @which trixi_include(default_example()) trixi_include(elixir::AbstractString; kwargs...) in Trixi at ~/.julia/dev/Trixi/src/auxiliary/special_elixirs.jl:36
- Use
aproposto search through the documentation and docstrings.julia> apropos("MHD") Trixi.IdealGlmMhdEquations3D Trixi.IdealGlmMhdMulticomponentEquations2D Trixi.calc_fast_wavespeed_roe Trixi.IdealGlmMhdEquations1D Trixi.initial_condition_constant Trixi.flux_nonconservative_powell Trixi.GlmSpeedCallback Trixi.flux_derigs_etal Trixi.flux_hindenlang_gassner Trixi.initial_condition_convergence_test Trixi.min_max_speed_naive Trixi.IdealGlmMhdEquations2D Trixi.IdealGlmMhdMulticomponentEquations1D [...]
Trixi.jl uses @inbounds to avoid bounds checking and therefore speed up the code.
After initial bounds/range/axes checks at a high level (in the callgraph), @inbounds
is applied and then propagated to the lower-level functions. For this propagation
to work, such a function has to be defined as follows.
Before inbounds access is assumed, the indices should be verified once in an explicit
@boundscheck block. Such a block is removed whenever @inbounds is propagated correctly, e.g.,
Base.@propagate_inbounds function get_node_vars(u, equations, solver::DG, indices...)
# Explicit bounds check, which can be removed by calling this function with `@inbounds`
@boundscheck checkbounds(u, eachvariable(equations), indices...)
# Assume inbounds access now
return SVector(ntuple(@inline(v->@inbounds u[v, indices...]),
Val(nvariables(equations))))
endWhen developing and introducing new functions, kernels or features within Trixi.jl, we strongly suggest to enable Julia's explicit bounds checking by starting the REPL with
julia --project=path/to/Trixi.jl/run --check-bounds=yesto avoid possible silent errors. In this way, Julia ignores @inbounds and always
performs the bounds checks described above, so that out-of-bounds accesses are
always caught.
When writing code, the choice of text editor can have a significant impact on productivity and developer satisfaction. While using the default text editor of the operating system has its own benefits (specifically the lack of an explicit installation procure), usually it makes sense to switch to a more programming-friendly tool. In the following, a few of the many options are listed and discussed:
Visual Studio Code is a modern open source editor with good support for Julia. If you are new to programming or do not have a preference for a text editor yet, Visual Studio Code is a good choice.
Vim and Emacs are both very popular editors that work great with Julia. One of their advantages is that they are text editors without a GUI and as such are available for almost any operating system. They also are preinstalled on virtually all Unix-like systems. However, Vim and Emacs come with their own, steep learning curve if they have never been used before. Therefore, if in doubt, it is probably easier to get started with a classic GUI-based text editor (like Visual Studio Code). If you decide to use Vim or Emacs, make sure that you install the corresponding Vim plugin julia-vim or Emacs major mode julia-emacs.
Instructions for AI coding agents such as Claude Code, Codex, Copilot, or Cursor
are collected in the file
AGENTS.md
in the root directory of the repository. Most agents read this file
automatically; Claude Code reads it via CLAUDE.md, which imports AGENTS.md.
Among other things, it instructs agents to never run the full test suite
(which is done in CI), but only individual test items related to their changes
(see Testing). To do so, agents create and reuse the local Julia project
run_agents/ in the repository (via the script utils/setup_run_agents.jl),
which develops the local version of Trixi.jl and contains all test
dependencies. This directory is ignored by git. No setup
is required on your side for this basic workflow.
If you use an agent to prepare a pull request, please follow the guidelines on
LLM/AI usage in
CONTRIBUTING.md.
By default, agents start a new Julia process for every command, which means that
Trixi.jl and the test dependencies have to be loaded (and partially compiled)
again each time. This overhead can be avoided with MCP servers providing
persistent Julia sessions. Repeated test runs are then much faster, and changes
to the source code are picked up automatically via
Revise.jl. AGENTS.md describes how
agents use the following two MCP servers:
- julia-mcp starts and manages Julia
sessions for the agent automatically, in the environment
run_agents/. - Kaimon.jl connects agents to Julia sessions (REPLs) started by you. You see the code the agent runs in your REPL, and you and the agent share the state of the session. Kaimon.jl requires Julia v1.12 or newer.
If a Kaimon.jl session loading Trixi.jl from the current checkout of the repository is available, agents use it. Otherwise, they use julia-mcp if available and the standard workflow (new Julia processes) otherwise. You can install one of these MCP servers or both.
To set up julia-mcp, follow these steps (see the README of julia-mcp for further details and other clients):
- Install uv, e.g., via
brew install uvon macOS or as described in its documentation. - Make sure that
juliais available in yourPATH(e.g., via juliaup) and install Revise.jl in your global Julia environment, which is loaded automatically in the sessions:julia -e 'using Pkg; Pkg.add("Revise")' - Clone julia-mcp to some directory outside of the Trixi.jl repository, e.g.,
git clone https://github.com/aplavin/julia-mcp.git ~/some/directory/julia-mcp - Register the MCP server with your agent. We recommend to start Julia with a
single thread (as most CI jobs do, which is relevant, e.g., for tests of
memory allocations) and with bounds checking enabled (as
Pkg.testdoes, see [Enabling bounds checking](@ref enabling-bounds-checking)). Since custom Julia flags replace the default flags of julia-mcp,--startup-file=nois also passed explicitly.- Claude Code (user-wide, i.e., for all projects):
claude mcp add --scope user julia -- uv run --directory ~/some/directory/julia-mcp python server.py --threads=1 --check-bounds=yes --startup-file=no - Codex:
This adds the following entry to
codex mcp add julia -- uv run --directory ~/some/directory/julia-mcp server.py --threads=1 --check-bounds=yes --startup-file=no~/.codex/config.toml, which you can also create manually (with the absolute path of your clone of julia-mcp):[mcp_servers.julia] command = "uv" args = ["run", "--directory", "/path/to/julia-mcp", "server.py", "--threads=1", "--check-bounds=yes", "--startup-file=no"]
PATH. Thus, the commandsclaudeandcodexused above may not be available in your shell if you only installed these extensions. In this case, install the command line tools (e.g., viabrew install --cask claude-codeandbrew install --cask codexon macOS) or edit the configuration files directly. The command line tools and the VS Code extensions share their configuration, so an MCP server registered once is available in both. - Claude Code (user-wide, i.e., for all projects):
- Restart your agent (or VS Code) and check that the MCP server is available,
e.g., via
/mcpin Claude Code. Then, ask the agent to run a test item, e.g.,"TreeMesh2D Advection: elixir_advection_basic.jl", using the Julia MCP tool. The first run takes a while because of compilation; repeated runs in the same session are much faster.
To set up Kaimon.jl, follow these steps (see the documentation of Kaimon.jl for further details):
- Install Kaimon.jl with Julia v1.12 or newer, e.g., the latest stable
release of Julia via
julia +releasewith juliaup, in the package REPL mode viaThis installs the executablepkg> app add Kaimon
kaimonin~/.julia/bin, which needs to be in yourPATH. This executable uses the exact Julia binary used for the installation. Thus, repeat the installation if juliaup removed this binary after an update. - Start the Kaimon.jl server by running
kaimonin a terminal. On the first run, a setup wizard asks for a security mode, an API key, and a port. Then, open the configuration tab of the dashboard by pressing6and pressito register the MCP server with your agent (e.g., Claude Code). Keep the default (user) scope: the project scope writes the file.mcp.jsonincluding your API key to the current directory, which must not be committed. The server needs to be running whenever agents should use Kaimon.jl. - Create a Julia project with the test dependencies that develops your local
clone of Trixi.jl, e.g., in the directory
run_kaimon/, which is ignored by git, and add the packages needed for the session:We recommend not to usejulia +release utils/setup_run_agents.jl run_kaimon julia +release --project=run_kaimon -e 'using Pkg; Pkg.add(["KaimonGate", "Revise"])'run_agents/for this purpose if you use it with another version of Julia (e.g., via julia-mcp), since a manifest should only be used with the Julia version it was resolved for. Running the scriptutils/setup_run_agents.jlagain checks whetherrun_kaimon/is still up to date. It never modifies an existing project in a directory passed as argument but throws an error if the project needs to be updated or was resolved with another Julia version, e.g., afterreleasestarted to point to a new version of Julia. In this case, removerun_kaimon/and repeat this step. - Start a Julia session in this project from the root directory of your clone
of Trixi.jl, e.g., with the same flags as recommended for julia-mcp,
and connect it to the Kaimon.jl server via
julia +release --project=run_kaimon --threads=1 --check-bounds=yes
Loading Revise.jl before Trixi.jl ensures that changes to the source code are picked up in the session.julia> using Revise; using Trixi; using KaimonGate; KaimonGate.serve()
- Restart your agent (or VS Code) and check that the MCP server is available,
e.g., via
/mcpin Claude Code. Then, ask the agent to run a test item, e.g.,"TreeMesh2D Advection: elixir_advection_basic.jl", using the Kaimon.jl session. You will see the code of the agent in your REPL.
Julia offers several options for debugging. A classical debugger is available with the Debugger.jl package or in the Julia extension for VS Code. However, it can be quite slow and, at the time of writing (January 2023), currently does not work properly with Trixi.jl. The Infiltrator.jl package on the other hand does not offer all features of a full debugger, but is a fast and simple tool that allows users to set breakpoints to open a local REPL session and access the call stack and variables.
The Infiltrator package provides fast, interactive breakpoints using the @infiltrate command,
which drops the user into a local REPL session. From there, it is possible to access local variables,
see the call stack, and execute statements.
The package can be installed in the Julia REPL by executing
(@v1.9) pkg> add InfiltratorTo load the package in the Julia REPL execute
julia> using InfiltratorBreakpoints can be set by adding a line with the @infiltrate macro at the respective position
in the code. Use [Revise](@ref interactive-use-of-julia) if you want to set and delete breakpoints
in your package without having to restart Julia.
!!! note "Use @autoinfiltrate when debugging Trixi.jl"
When running Julia inside a package environment, e.g., inside the source
code of Trixi.jl itself, the @infiltrate macro only works if
Infiltrator has been added to the package dependencies. To avoid this,
you can use the (non-exported) @autoinfiltrate macro
in Trixi.jl, which only requires Infiltrator.jl to be available in the
current environment stack and will auto-load it for you.
Triggering the breakpoint starts a REPL session where it is possible to interact with the current local scope. Possible commands are:
@locals: Print the local variables.@exfiltrate: Save the local variables to a global storage, which can be accessed with thesafehousevariable outside the Infiltrator session.@trace: Print the current stack trace.- Execute other arbitrary statements
?: Print a help list with all options
To finish a debugging session, either use @continue to continue and eventually stop at the
next breakpoint or @exit to skip further breakpoints. After the code has finished, local
variables saved with @exfiltrate can be accessed in the REPL using the safehouse variable.
Limitations of using Infiltrator.jl are that local variables cannot be changed, and that it is not possible to step into further calls or access other function scopes.
-
Check whether everything is okay, tests pass etc.
-
Set the new version number in
Project.tomlaccording to the Julian version of semver. Commit and push. -
Comment
@JuliaRegistrator registeron the commit setting the version number. -
JuliaRegistratorwill create a PR with the new version in the General registry. Wait for it to be merged. -
Increment the version number in
Project.tomlagain with suffix-DEV. For example, if you have released versionv0.2.0, usev0.2.1-DEVas new version number. -
When a new version of Trixi.jl was released, check whether the
[compat]entries intest/Project.tomlin Trixi2Vtk should be updated. When a new version of Trixi2Vtk was released, check whether the[compat]entries indocs/Project.tomlin Trixi.jl should be updated.These entries will also be checked regularly by CompatHelper (once a day). Hence, if everything was released correctly, you should only need to do these checks manually if new minor versions with changes in the docs of Trixi2Vtk were released but no new version of Trixi.jl was released afterward.
You can build the documentation of Trixi.jl locally by running
julia --project=docs -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
julia --project=docs --color=yes docs/make.jlfrom the Trixi.jl main directory. Then, you can look at the html files generated in
docs/build.
For PRs triggered from branches inside the Trixi.jl main repository previews of
the new documentation are generated at https://trixi-framework.github.io/TrixiDocumentation/previews/PRXXX,
where XXX is the number of the PR.
This does not work for PRs from forks for security reasons (since anyone could otherwise push
arbitrary stuff to the Trixi.jl website, including malicious code).
Trixi2Vtk has Trixi.jl as dependency and uses Trixi.jl's implementation to, e.g., load mesh files. When developing Trixi2Vtk, one may want to change functions in Trixi.jl to allow them to be reused in Trixi2Vtk. To use a locally modified Trixi.jl clone instead of a Trixi.jl release, one can tell Pkg to use the local source code of Trixi.jl instead of a registered version by running
(@v1.9) pkg> develop path/to/Trixi.jl