3

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:

  1. I installed the experimental Julia version 1.8.0-rc3 for macOS ARM (M-series Processor) from https://julialang.org/downloads/
  2. 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
  1. 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
  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).
  2. 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.
  3. 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 the OrdinaryDiffEq 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
Vanessa
  • 41
  • 2

2 Answers2

1

The provided binaries was missing the build for Mac M1/M2. It was now updated to have these binaries https://github.com/JuliaPackaging/Yggdrasil/pull/6918 and related threads have mentioned that solved it https://discourse.julialang.org/t/error-while-using-lsoda/100614/16. So if you update it should now be okay.

Chris Rackauckas
  • 18,645
  • 3
  • 50
  • 81
0
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:

That suggested that julia cannot actually find the underlying lsoda library.

eh, no, lsoda is not the underlying library or anything, just the lsoda() is not defined, most likely because LSODA.jl does not export it.

but in any case this works for me just fine


julia> using LSODA

julia> LSODA.lsoda
lsoda

julia> lsoda
lsoda

can you double check you have the correct pkg version installed?

jling
  • 2,160
  • 12
  • 20
  • Hi thanks for your answer. I managed to copy the wrong error above, so I edited the post. That would suggest that julia can't see the library, wouldn't it? Regarding your suggestion, I can run the three commands with exactly the same output as you ... no error, but actually using the solver causes the issue. As I showed under point 2, I installed LSODA.jl v0.7.0. But I also just tried with v0.6.2 and the same issue arises. – Vanessa Jul 31 '22 at 15:25
  • @Vanessa can you try the Rosetta version of the Julia instead of M-series? – jling Jul 31 '22 at 15:40
  • Just tried with Rosetta v1.7.3 and the above example works. Thanks for the tip. However, as I eventually need to call Julia from within Python code and that requires the PyCall package, I am now running into issues as the Julia Rosetta version doesn't seem to like the arm python installation. While I am trying to figure out if I can get that to work, could I ask if you know how to get Julia to recognise a specific library? As I said above, I built the library that Julia can't find from scratch. I just don't know how to tell Julia where exactly to find it. Do you know how to do that? – Vanessa Jul 31 '22 at 17:38
  • I think the cleanest solution is to add M-series support here: https://github.com/JuliaPackaging/Yggdrasil/blob/master/L/LSODA/build_tarballs.jl – jling Aug 01 '22 at 01:25
  • As I am new to julia, would you be able to explain what you mean by that? Or rather how to do that? Looking at the supported platforms at https://github.com/JuliaPackaging/BinaryBuilderBase.jl/blob/4b21cde2105830e287271c323d909b9ee8a64c5e/src/Rootfs.jl#L714 I thought this would mean that M1 support should already be included. – Vanessa Aug 01 '22 at 08:14
  • not in the recipe for LSODA – jling Aug 03 '22 at 01:03