Unable to reproduce Catalyst.jl Example

I am running Julia 1.9.3 using jupyter notebooks, and cannot reproduce the following example: Home · Catalyst.jl. I am simply copying and pasting the code. However, when I graph the reaction network I get the following diagram, which does not match up exactly as the one given in the example. Everything is identical to the diagram produced in the example with the only difference being that the rates of change are labeled. But I don’t know why the diagram produced isn’t identical to the one in the example. I would like to know why this difference is occurring, but the real issue is the following error when trying to define the ODE problem:

From what I understand, I have added and updated all the relevant packages, and jupyter is setup to the best of knowledge. I don’t think there is a scoping issue, because I got the same error when I defined the reaction net and ran defined the ODE in the same cell. I am completely stuck, since this is my first run through numerical ODEs in Julia.

Any thoughts or guidance would be much appreciated.

What version are you using? Can you show ]st?

When I run that command I get: IJulia v1.24.2. I was under the impression that installing Julia 1.9.3 meant that you were using version 1.9.3. Have I not updated the version of Julia that jupyter notebooks is actually looking at?

How did you install the package? That should show your installed packages if you do it on the right Project.toml.

Is this not sufficient to install the packages in Julia? I am under the impression that example in Home · Catalyst.jl is self contained. The only assumption is that I have the correct version of Julia installed and jupyter notebooks is looking at that version. Also a few quick questions about the output of the ]st command. How do I know if the relationship between the output of ]st and the version of Julia I have installed is correct? Or are they not related at all? Will installing a version of Julia update that environment appropriately?

Can you do ]st in the notebook? Or if in the REPL, do it on the same environment as you’re using here.

If you look on the bottom left you see the version of Catalyst that the documentation is referring to. If you have a different version of Catalyst then you’d need to update or use the docs for the different version. My running assumption is that you’re on something older like v12 because maybe you didn’t update your registry before installing packages.

1 Like

And can you please share the full code that you actually ran as text, not a screenshot? I just ran the code just fine:

using Catalyst, OrdinaryDiffEq
rn = @reaction_network begin
    α, S + I --> 2I
    β, I --> R
end
u0 = [:S => 990.0, :I => 1.0, :R => 0.0]
tspan = (0.0, 250.0)
p = [:α => 0.1/1000, :β => 0.1]
prob = ODEProblem(rn, u0, tspan, p)
sol = solve(prob, Tsit5())

gives:

julia> sol = solve(prob, Tsit5())
retcode: Success
Interpolation: specialized 4th order "free" interpolation
t: 9-element Vector{Float64}:
   0.0
   0.014135066238276477
   0.15548572862104124
   1.5689923524486886
  15.704058590725163
  59.090169376339844
 136.60311536977474
 235.03070390559344
 250.0
u: 9-element Vector{Vector{Float64}}:
 [990.0, 1.0, 0.0]
 [989.9986006393219, 0.9999858640446699, 0.0014134966334038547]
 [989.9846082297721, 0.9998444067138262, 0.015547363514026248]
 [989.8448043450596, 0.998420078473321, 0.1567755764670593]
 [988.4592645215671, 0.9832247249614143, 1.5575107534715067]
 [984.3671574973882, 0.9268543671734841, 5.705988135438275]
 [977.785522472754, 0.7998781032069555, 12.414599424039093]
 [970.9718385037306, 0.6206834123135646, 19.40747808395581]
 [970.0896048802567, 0.5938951320950598, 20.31649998764821]

with package versions

(@v1.10) pkg> st
Status `~/.julia/environments/v1.10/Project.toml`
  [479239e8] Catalyst v13.5.1
  [1dea7af3] OrdinaryDiffEq v6.59.0

After updating all the packages, when I run the code in the example verbatim directly on the terminal it does work. That means the issue is that jupyter is not looking at the right version of Julia. How do I get those to match up? (I also do not know how to check the package versions that jupyter is looking at. I can see that when I open Julia in the terminal, but not when I am using jupyter notebooks.)

IJulia supports the Pkg REPL mode so ] st will tell you what’s in your current environment. Julia versions can be selected from the menu at the top where you’ll find an orion to change kernels.

All of these errors are occurring with the correct version of Julia.
image The issue is now that I can reproduce the example in the terminal that opens when I use the Julia app directly, but not when using jupyter notebooks. I ran ] up and that did update all my packages. Then in the same terminal I ran all the code in the example and it did work. But when I ran using IJulia notebook() and ran the same code as the example, again, I got the same error: "ArgumentError: Any[S(t), I(t), R(t), α(t), β(t)] are missing from the variable map.". This means the issue is probably with the versions of the packages that jupyter notebooks is looking at, but I don’t know how to make those agree with the versions used in the terminal (which do work).

In a Notebook cell can you type and run the following, and then give us the full output you see?

using Pkg
Pkg.status()

This is the full output I see:

Notice you have Catalyst v10, which is where the issue is coming from. PerceptualColorMaps.jl hasn’t been updated in a long time and is likely holding everything back https://github.com/peterkovesi/PerceptualColourMaps.jl/blob/master/Project.toml . I would remove that package and update.

I ran using Pkg Pkg.rm("Catalyst") and added it back and the version updated to 12.1.1, but now I am having a different issue where Julia is complaining when pre-compiling Catalyst.

I didn’t mean remove Catalyst, I said remove PerceptualColorMaps.jl

1 Like

@amaritm1 Julia packages have to specify their compatibility with packages they depend on. If you have even one package that is very out of date and setup to only declare compatibility with older versions of widely used packages it will block you from being to use newer versions of most actively maintained packages.

As Chris mentioned that seems to be what is going on here. Adding and removing Catalyst won’t fix the issue; you need to remove the older package that is preventing newer versions of so many packages from being installed when you update (notice how many of the packages in your status have a “^” indicating they are not the latest version).

If you remove PerceptualColorMaps as Chris suggested hopefully you will then be able to run Pkg.update() and get the newest versions of your remaining packages (note that GraphViz.jl has also not been updated in a long time, but it only has a few dependencies and they aren’t capped, so hopefully it won’t cause issues).

An alternative to all this is to make a new, empty environment, and just add the minimal set of packages you need to it:

using Pkg
Pkg.add("name_you_want_for_your_environment")
# or Pkg.(; temp = true) if you just want a temp environment
Pkg.add("Catalyst")
Pkg.add("DifferentialEquations")
...
``

Wow that’s good to know. I will remove that package and give it a try. The minimal environment is also a good suggestion. That one should work because I assume that is what happens when I copy and paste the code into the Julia terminal. However as I was about to remove PerceptualColorMaps jupyter cannot connect to the kernel, and I do not why, because I have made no changes to the environment. I already ran ] build IJulia and did not see any issues. Are there any other obvious thing to check?

Sorry, when I have Jupyter issues I do what you said you did; I restart the Julia REPL, rebuild IJulia, and restart the notebook server. That usually fixes things.

As an alternative, you could try opening your notebook in Visual Studio Code (just make sure to have installed the Julia and Jupyter notebook extensions).

I got it to work. Thank you @isaacsas, @nilshg, and @ChrisRackauckas for all your help. I just used a completely fresh environment and it worked. My only remaining question is how did @ChrisRackauckas look at the output of Pkg.status() and know that it was PerceptualColorMaps.jl was holding everyone back? I see that a lot of packages have newer versions available in that screenshot, but it is not obvious to me why PerceptualColorMaps.jl is the culprit. I see in the github link that it has not been updated for about a year. Is that very old by Julia package standards?