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
463 stars 77 forks source link

@add_constraints gives error when ODEs verified conservation classes are correct #150

Closed danielchen26 closed 4 years ago

danielchen26 commented 5 years ago

`tsst= @reaction_network begin (a₁, Kda₁), N + T ↔ NT
(r₁, Kₒ
r₁ ), O + Dₒ ↔ Dᵒ
α₁, Dᵒ → Dᵒ + O
δₒ, O → ∅
a0, Dₒ → D̄
β, Dₕ → Dₒ
(r₁,Kₒr₁), Dₜ + O ↔ Dᵗ
α₁, Dᵗ → Dᵗ + T
δₒ, T → ∅
(r₁, Kₒ
r₁ ), N + Dₙ ↔ Dᴺ
α₁, Dᴺ → Dᴺ + N
δₒ, N → ∅
(ζ₁, Kₒ*ζ₁), O + Dₙ ↔ Dᴺ
k₃, NT + D̄ → Dₕ + NT
k₄, NT + Dₜ → Dᵗ + NT
end Kₒ Kd r₁ α₁ δₒ a0 β ζ₁ k₃, k₄

@add_constraints test begin Dₒ + Dᵒ + D̄ + Dₕ = 10 Dₜ + Dᵗ = 1 Dₙ + Dᴺ = 1 end`

gives an error : " some reaction rate must contain non-polynomial terms"

However, I check ODE that corresponds to this crn, the conservation classes (3 of them) are there and there are no non-polynomial terms.

Can someone help me fix this issue?

TorkelE commented 5 years ago

Not at a computer right now, but have you tried having a '' between parameters in reaction rates? E. G. Kda1, and not kDa1?

danielchen26 commented 5 years ago

It is not about parameters, I have not yet assign parameters. All I have done is set up a CRN and then add constraints, that's it. Adding constraints give me this error which does not make sense after I manually checked ODEs

danielchen26 commented 5 years ago

I think I just found where the issue is, there is \alpha1 and a1 in Juno which look extremely similar. I miss one of them in declaring the parameters. Now everything works fine. But the error message seems not very intuitive for the debugging. Is it possible to pop up a more descriptive warning in the future when someone miss an undefined reaction rate parameter?

TorkelE commented 5 years ago

So the problem is in the declaration. Basically it assumes all symbols that you use are reactants, except for those explicitly designated to be parameters. Then when one starts to do stuff with the system (solving it, adding constraints) one might start to get errors.

The problem is that it is one cannot be 100% sure whenever something is just ta missed-to-be-mentioned parameter, or something else. However you are right that there probably are cases where it is very likely, and a warning message might be useful. I'll try to see if I can add something in when I got time. It would have helped here.

TorkelE commented 4 years ago

Never got around to adding that warning message before the functionality got deprecated.

isaacsas commented 4 years ago

I still think we should somehow have add_constraints to generate DAE models, and allow model reduction using conservation laws.

TorkelE commented 4 years ago

Yes, we probably should. I presume that would make solving faster as well? I kept https://github.com/SciML/DiffEqBiological.jl/issues/137 up until we figure this one out.

ChrisRackauckas commented 4 years ago

We'll need a bit more to fully support this, because just adding the constraints will make the system overdetermined. It then needs to be algebraically reduced to a determined set.