I am trying to run some code in Julia that solves ODEs using LSODA on my M1 macbook pro. Everything works fine on my linux machine, but despite a lot of googling I cannot figure out how to solve this on my mac. The issue already appears trying to run the simple examples from the LSODA.jl Readme.
So here is what I have done so far:
- I installed the experimental Julia version 1.8.0-rc3 for macOS ARM (M-series Processor) from https://julialang.org/downloads/
- In a Julia console, I tried installing the LSODA.jl package running
] add LSODA
, which produces:
(@v1.8) pkg> add LSODA
Resolving package versions...
Updating `~/.julia/environments/v1.8/Project.toml`
[7f56f5a3] + LSODA v0.7.0
Updating `~/.julia/environments/v1.8/Manifest.toml`
[9e28174c] + BinDeps v1.0.2
[7f56f5a3] + LSODA v0.7.0
[30578b45] + URIParser v0.4.1
[aae0fff6] + LSODA_jll v0.1.1+0
- If I then try to run the minimal example from the LSODA Readme, I get the following output (see the edit at the bottom as I copied the wrong error):
julia> using LSODA
julia> function rhs!(t, x, ydot, data)
ydot[1]=1.0E4 * x[2] * x[3] - .04E0 * x[1]
ydot[3]=3.0E7 * x[2] * x[2]
ydot[2]=-ydot[1] - ydot[3]
nothing
end
rhs! (generic function with 1 method)
julia> y0 = [1.,0.,0.]
3-element Vector{Float64}:
1.0
0.0
0.0
julia> tspan = [0., 0.4]
2-element Vector{Float64}:
0.0
0.4
julia> res = lsoda(rhs!, y0, tspan, reltol= 1e-4, abstol = Vector([1.e-6,1.e-10,1.e-6]))
ERROR: UndefVarError: lsoda not defined
Stacktrace:
[1] top-level scope
@ REPL[7]:1
- That suggested that julia cannot actually find the underlying lsoda library. So I followed the instructions to build the library from scratch. That seemed to work as the generated
liblsoda.dylib
library allowed me to run the tests successfully (I got the same output as mentioned on the LSODA github). - At this point I have no idea how to tell julia to actually use this library. I have tried to rebuild the julia LSODA package running
] build LSODA
(running] test LSODA
produces the same error as above btw), launching julia from within the library directory, setting the LD_LIBRARY_PATH environment variable to the location of the library ... BUT NOTHING WORKS. I still get the same output as shown above, when running the example. - Just to check that I didn't mess up something with the julia installation itself, I ran the following ODE solving example using a different solver (
Tsit5()
from theOrdinaryDiffEq
package) and that works without issues, giving the following output:
julia> using OrdinaryDiffEq
julia> function rhs!(du, u, p, t)
du[1]=1.0E4 * u[2] * u[3] - .04E0 * u[1]
du[3]=3.0E7 * u[2] * u[2]
du[2]=-du[1] - du[3]
nothing
end
rhs! (generic function with 1 method)
julia> y0 = [1.,0.,0.]
3-element Vector{Float64}:
1.0
0.0
0.0
julia> tspan = (0., 0.4)
(0.0, 0.4)
julia> prob = ODEProblem(rhs!,y0,tspan)
ODEProblem with uType Vector{Float64} and tType Float64. In-place: true
timespan: (0.0, 0.4)
u0: 3-element Vector{Float64}:
1.0
0.0
0.0
julia> sol = solve(prob, Tsit5())
retcode: Success
Interpolation: specialized 4th order "free" interpolation
t: 281-element Vector{Float64}:
0.0
0.0014148463701573728
0.002044917824570354
0.0031082395219656383
0.004077786184478819
0.005515331547111039
0.007190039901585917
0.009125371178864151
0.011053910882556455
0.012779075887510953
⋮
0.38962386292571205
0.39105986979707663
0.3924964595438138
0.39393300822861893
0.3953689357731328
0.39680395859574674
0.3982382036135917
0.3996721389859908
0.4
u: 281-element Vector{Vector{Float64}}:
[1.0, 0.0, 0.0]
[0.9999434113374243, 3.283958368828848e-5, 2.3749078887421564e-5]
[0.9999182177955453, 3.554267892392701e-5, 4.623952553065492e-5]
[0.9998757150665857, 3.630246922738996e-5, 8.798246418685756e-5]
[0.9998369766423073, 3.6462803069599716e-5, 0.00012656055462304005]
[0.9997795672802454, 3.646643085493869e-5, 0.00018396628889956693]
[0.9997127287562698, 3.6447280004319005e-5, 0.00025082396372578164]
[0.9996355450580071, 3.636681631277154e-5, 0.00032808812568000767]
[0.99955869263762, 3.601892856283502e-5, 0.0004052884338170678]
[0.9994899965749859, 3.4686952113841286e-5, 0.00047531647290014134]
⋮
[0.9855287248204975, 3.3380535729784715e-5, 0.01443789464377367]
[0.9854791547754341, 3.3371763645216536e-5, 0.01448747346092161]
[0.985429589879464, 3.3361195969757255e-5, 0.014537048924567189]
[0.9853800515675893, 3.3349731795215403e-5, 0.014586598700616432]
[0.9853305597195883, 3.3338642943875154e-5, 0.014636101637468868]
[0.9852811239988389, 3.33290122744337e-5, 0.014685546988887663]
[0.9852317399743383, 3.332125091318715e-5, 0.014734938774749495]
[0.9851823915340508, 3.331492718519977e-5, 0.014784293538765007]
[0.985171094472304, 3.359314691926523e-5, 0.01479531238077784]
At this point, I am rather lost, so any help would be appreciated.
EDIT: I managed to copy the wrong error in the above description of the problem. Point 3 gives the following error output:
ERROR: UndefVarError: liblsoda not defined
Stacktrace:
[1] lsoda_prepare
@ ~/.julia/packages/LSODA/En9TK/src/types_and_consts.jl:88 [inlined]
[2] lsoda(f::Function, y0::Vector{Float64}, tspan::Vector{Float64}; userdata::Nothing, reltol::Float64, abstol::Vector{Float64}, nbsteps::Int64)
@ LSODA ~/.julia/packages/LSODA/En9TK/src/solver.jl:97
[3] top-level scope
@ REPL[5]:1