SciML / Catalyst.jl

Chemical reaction network and systems biology interface for scientific machine learning (SciML). High performance, GPU-parallelized, and O(1) solvers in open source software.
https://docs.sciml.ai/Catalyst/stable/
Other
443 stars 71 forks source link

Making g a sparse matrix #41

Closed TorkelE closed 6 years ago

TorkelE commented 6 years ago

I was reading the documentations today after the latest update and noticed that g could be a sparse matrix like:

A = zeros(2,4)
A[1,1] = 1
A[1,4] = 1
A[2,4] = 1
sparse(A)

# Make `g` write the sparse matrix values
function g(du,u,p,t)
  du[1,1] = 0.3u[1]
  du[1,4] = 0.12u[2]
  du[2,4] = 1.8u[2]
end

# Make `g` use the sparse matrix
prob = SDEProblem(f,g,ones(2),(0.0,1.0),noise_rate_prototype=A)

Right now we make a g including all combinations du[i,j] =, which might be quite a few. It should be very possible to instead make this g a sparse matrix with much less entries (e.g. if we have n components being degraded that will add n squared entries to g, only of which n is non zero).

Could this be an advantage? Would there be a non trivial performance gain by using such a matrix. If that is not the case we probably shouldn't bother.

ChrisRackauckas commented 6 years ago

There would be a performance gain only when this gets large, like hundreds of reactants? Also, you'd need to take advantage of the structure. Instead of du[1,1], you'd want to generate this using the component array of the sprase matrix, i.e. du.data[i] and then have it all hardcoded in sparse-linear indexes.

TorkelE commented 6 years ago

Ok, that is good to hear. Sounds like something for the real perfectionist, but I don't think we are there yet. Lets close this for now?

ChrisRackauckas commented 6 years ago

It's something for when you're computationally generating large systems of SDEs, like for discretizations of SPDEs. I'm not sure chemical reaction networks without space will ever need this.