smiths / caseStudies

Case studies of (manual) documentation for scientific computing software
3 stars 2 forks source link

Added a Julia ODE example #251

Closed B-rando1 closed 3 months ago

B-rando1 commented 3 months ago

This should help with #3918. It took a bit of trial and error to understand how the library works, but it makes sense now that I've got it working.

You can run the code by calling make run RUNARGS=input.txt, and the results will be stored in output.txt. Note that you need DifferentialEquations.jl installed in your Julia workspace (see here for an install guide).

The output is basically identical to Python's (source code here). It deviates a little bit, but the first ~10 digits are the same.

smiths commented 3 months ago

@B-rando1, the code looks good, but I don't want to merge until I can run it. I followed your instructions for the Differential Equations package, but it doesn't seem to have loaded properly. I don't have time to debug it now. My Julia version is 1.10.4. DifferentialEquations is v7.13.0. Here is a portion of the error message that I get:

ERROR: LoadError: TypeError: in new, expected Union{}, got a value of type SparseArrays.SparseMatrixCSC{Float64, Int64}
Stacktrace:
 [1] Sparspak.SpkSparseSolver.SparseSolver(p::SparseArrays.SparseMatrixCSC{Float64, Int64}, slvr::Sparspak.SpkSparseBase._SparseBase{Int64, Float64}, n::Int64, ma::Int64, na::Int64, mc::Int64, nc::Int64, _inmatrixdone::Bool, _orderdone::Bool, _symbolicdone::Bool, _factordone::Bool, _trisolvedone::Bool, _refinedone::Bool, _condestdone::Bool)
   @ Sparspak.SpkSparseSolver ~/.julia/packages/Sparspak/oqBYl/src/SparseMethod/SpkSparseSolver.jl:18
 [2] Sparspak.SpkSparseSolver.SparseSolver(m::SparseArrays.SparseMatrixCSC{Float64, Int64})
   @ Sparspak.SparseCSCInterface ~/.julia/packages/Sparspak/oqBYl/src/SparseCSCInterface/SparseCSCInterface.jl:189
 [3] sparspaklu(m::SparseArrays.SparseMatrixCSC{Float64, Int64}; factorize::Bool)
   @ Sparspak.SparseCSCInterface ~/.julia/packages/Sparspak/oqBYl/src/SparseCSCInterface/SparseCSCInterface.jl:219
 [4] top-level scope
   @ ~/.julia/packages/LinearSolve/WmS9C/src/factorization.jl:1336
 [5] include(x::String)
   @ LinearSolve ~/.julia/packages/LinearSolve/WmS9C/src/LinearSolve.jl:1
 [6] top-level scope
   @ ~/.julia/packages/LinearSolve/WmS9C/src/LinearSolve.jl:127
 [7] top-level scope
   @ stdin:3
in expression starting at /Users/smiths/.julia/packages/LinearSolve/WmS9C/src/factorization.jl:1336
in expression starting at /Users/smiths/.julia/packages/LinearSolve/WmS9C/src/LinearSolve.jl:1
in expression starting at stdin:3
B-rando1 commented 3 months ago

Hmm, that's odd. I'm on Julia v1.10.3, with DifferentialEquations v7.13.0.

My Julia configuration doesn't have Sparspak installed, so it's surprising that you're getting an error with it. I'm not exactly sure what would be going on there.

Other than that, I'm not really sure what you can try. I checked their issue tracker, but didn't see anything related to this. I hope you can get it working!

smiths commented 3 months ago

I figured out the problem. The homebrew version of Julia is not very good. :smile: I uninstalled by homebrew version of Julia and installed the regular version. After installing the differential equation package the code ran without any problems. :smile: