Writing a Julia project
Table of Contents
The Julia language has always fascinated me, it seemed pretty perfect for someone like me. It’s a maths-heavy language with a relatively simple syntax and a wicked fast execution – seems like a great idea, but how does it work in practice?
First steps with Julia as a Matlab programmer
I first used Julia during my mathematical neuroscience PhD in 2019. I was
building off someone elses code to solve a partial differential equation for
2,000,000 different parameter configurations which was originally implemented
in Matlab. Using the ode45 solver, this script would take over 3 days to
finish. I don’t remember how I came across DifferentialEquations.jl, but
looking at the documentation it seemed extremely thorough. I had heard that
Julia was fast, so surely it was worth a shot?
I focussed on the differential equation solver in this pipeline, and using a
fairly naive approach in a Julia script (matching the ode45 solver) this
computed the results in 3 minutes! I thought surely this must be a bug, but I
plotted some of the curves and it was legitimate!
Now, did I save time? It probably took a day or two to get up to speed with Julia and get this working, but it felt like I got much more out of the experience than just running the Matlab code. However, this experience wasn’t without difficulties:
- I was a Matlab veteran, but relatively new to Python so a lot of Programming concepts in Julia were somewhat assumed knowledge,
- Documentation was relatively sparse at the time,
- 3rd party packages were a bit fiddly (using a package to generate a latin hypercube was the difficult part of that task from what I remember)
Unfortunately I didn’t have the capacity to pursue Julia further at the time – I didn’t have the time, nor did I have someone to learn it from/with. So I continued with the more well-trodden trails of Python and Matlab, but I’ve kept an eye on developments in Julia over the years.
Returning to Julia as a Python programmer
Now in 2025, Julia has come a long way (and so have I). I re-learned Julia by plotting fractals and having a go at Advent of Code (which went well until I got quite ill on holiday). At this point I was a Python veteran with 4 years of machine learning engineering experience, and the Julia documentation made much more sense.
However, I still had many difficulties with this:
- The community is passionate, but adoption is still relatively low, learning Julia from posts and threads is much much harder than doing so with Python
- The types system made sense in theory, but I still struggled with using abstract types in practice
- Setting up a project was weirdly difficult?
I returned to that first project from my PhD, I wondered if I could implement the entire thing in Julia instead of just the single component. I learned a bit on how Julia code is organised from various sources, here I’ll summarise on what I settled on:
$ tree .
.
├── LICENSE
├── Manifest.toml
├── Project.toml
├── README.md
├── run.jl # Entrypoint for my project
├── scratch.jl # A notebook/script for experimenting
└── src
├── NfmParamRanking.jl # Top-level module
├── AnalyseResults.jl # Submodules
├── GenerateData.jl # ...
├── Types.jl
└── Utils.jlMy run.jl looks like this:
using Pkg
Pkg.activate(".") # Ensures the environment is active
using NfmParamRanking
function main()
NfmParamRanking.main()
end
if !isdefined(Base, :active_repl)
main()
endThis way, I can run my project as $ julia run.jl
The top-level module NfmParamRanking.jl has this structure:
module NfmParamRanking
include("./Types.jl") # Annoyingly, order matters here
include("./AnalyseResults.jl")
include("./GenerateData.jl")
include("./Utils.jl")
using CSV
using DataFrames
using DecisionTree
using .Types
using .AnalyseResults
using .GenerateData
using .Utils
function main()
config = Config(...)
param_configs, labels, simulations = GenerateData.main(config)
output = AnalyseResults.main(simulations, ...)
print(output)
endI break this project into the major steps GenerateData.jl, and
AnalyseResults.jl, with Types.jl being a dependency across the top-level
module and GenerateData.jl.
The types are defined and exported in Types.jl:
module Types
export ParameterRange, SimulationConfig, ModelConfig, Config
import Base: ==
using Parameters
@with_kw struct ParameterRange
name::Symbol
min::Float64
max::Float64
end
function ==(a::ParameterRange, b::ParameterRange)
a.name == b.name && a.min == b.min && a.max == b.max
end
...
end moduleAnd then I can refer to these types in the parent module (which is why we need
to include("Types.jl") before include("GenerateData.jl")):
module GenerateData
# %%
using QuasiMonteCarlo
using Random
using LinearAlgebra
using DifferentialEquations
using FFTW
using Peaks
using DataFrames
using ..Types
function main(
config::Config,
)::Tuple{Matrix{Float64}, Matrix{Float64}, Vector{Vector{Float64}}}
@info "Generating parameter space"
param_configs = generate_hypercube(
config.param_ranges,
config.N
)
@info "Solving model for each configuration"
simulations = []
for i = 1:config.N
Y = solve_eq(
jansen_ritt_wendling!,
param_configs[i, :],
config.simulation_config,
)
...
push!(data, characteristics)
end
@info "labelling simluations"
labels = ...
return param_configs, labels, simulations
end
...
endExporting and importing namespaces feels unintuitive from a Python perspective, but I can see how this fits with multiple dispatch, I think this is something that will just take practice.
You can check out the full source of this project here.
If I were to do this again, I would avoid using a top-level module and I’d
reserve the package namespace for storing functions that I’ve designed and
pulled out of my notebook during development, then put the content of the
top-level module in run.jl instead.
Recommending Julia
Would I recommend Julia? I still don’t really have a definitive answer in all honesty.
Julia absolutely slams Python for CPU-limited workloads, but packages such as
torch don’t have this limitations since the Python code calls out to C++ code
under the hood. Also while Julia is fast, the pre-compile times are slow, so
I’m not sure if any time is saved in the prototyping stage of the project.
The syntax is relatively friendly, but it still has sharp edges. The type system is fantastic, but this was definitely a hurdle when learning this from the perspective of a Matlab programmer.
Also the scope of do blocks in Julia was still a bit unclear, but once I
figured it out from the documentation, it was fantastic! Nonetheless, I would
recommend Julia to Matlab programmer with the caveat of “the syntax is
deceptively simple, read the documentation and then read it again”.
As a Python programmer, it’s pretty simple (just index from 1 instead of 0, of course). The package manager and the virtual environments work so intuitively, it just gets out of your way which is fantastic. As discussed above, organising code with modules can be unintuitive. For an established programmer, I’m not sure why you wouldn’t use C++ or Rust and with Python bindings? I suppose using Julia is more accessible to data scientists than either of those languages.
But I have to say, multiple dispatch and functional programming gives a nice perspective on designing systems and solving problems. One quote I read (I cannot find the original source, email me if you find it) that really stuck with me:
Object oriented programming in Python is like adding pages to a cookbook, you have to implement new recipes when you add new ingredients. Julia on the other hand, is like adding notes to the existing recipes, multiple dispatch essentially allows you to re-define functions to use your new ingredients.
I’m still on the fence with Julia. I love the philosophy and the design, but I
think it’s still struggling with widespread adoption outside of niche circles.
Some packages such as DifferentialEquations.jl are absolutely fantastic, and
it’s worth learning to use these tools. But for general-purpose programming I
don’t think it’s practical in many cases… yet. I’ll still be keeping an eye
on developments, but for now I’ll be sticking with Python (and maybe figuring
out how to call Julia from Python!).
If you’re a Julia programmer, or if you’d like to share your thoughts on this topic, I’d love to hear from you!
#performance-comparison #julia #package-ecosystem #performance-optimization #programming #scientific-computing #multiple-dispatch #programming-languages #matlab #high-performance-computing #python #software-engineering #differential-equations #julia-programming-language #mathematics
Reply to this post by email blZake@proZbableodyssey.blog (remove Z characters) ↪