sys-bio / roadrunner

libRoadRunner: A high-performance SBML simulator
http://libroadrunner.org/
Other
37 stars 24 forks source link

Bug when computing jacobian on a simple model #652

Open hsauro opened 4 years ago

hsauro commented 4 years ago

import tellurium as te import roadrunner

r = te.loada(""" x' = -k1*x

  x = 10; k1 = 0.1

""")

r.getFullJacobian()

Yields the following error

File "", line 1, in r.getFullJacobian()

File "C:\Tellurium-Winpython-3.7\python-3.7.4.amd64\lib\site-packages\roadrunner\roadrunner.py", line 2847, in getFullJacobian return _roadrunner.RoadRunner_getFullJacobian(self)

RuntimeError: attempted to access floating species id at index 0

luciansmith commented 3 years ago

Gary actually updated the error message for this in July. Here's what it says:

RuntimeError: cannot compute full Jacobian because there are fewer floating species (0) than rate rules (1). 
You may need to declare one or more of your variables as a species. See 
https://tellurium.readthedocs.io/en/latest/antimony.html#rate-rules if you are using Antimony.

Is that sufficient?

hsauro commented 3 years ago

There is a Jacobian with respect to the rate rules, it’s just that roadrunner is not computing it. In the long term we should be merging the rate rules and odes from reactions so that the complete Jacobian can be computed. For now the message is ok but maybe next year we can revisit the fix this properly.

luciansmith commented 5 months ago

Looking through old issues...

The problem here is that 'x' is a parameter, not a species, and roadrunner insists that Jacobians only involve species. Do we want to relax that restriction at some point, so that parameters that change due to rate rules can be part of the Jacobian matrix?

Model that fails:

import tellurium as te
import roadrunner

r = te.loada("""
  x' = -k1*x
  x = 10
  k1 = 0.1
""")

r.getFullJacobian()

Model that succeeds:

import tellurium as te
import roadrunner

r = te.loada("""
  species x
  x' = -k1*x
  x = 10
  k1 = 0.1
""")

print(r.getFullJacobian())
hsauro commented 5 months ago

If defining variables as species fixes the problem then maybe it’s ok. Otherwise it will require some re-engineering of roadrunner which might cause other issues.

Probably better to add this to the Jacobian method documentation.

Herbert

Herbert Sauro, Professor Director: NIH Center for model reproducibility University of Washington, Bioengineering 206-685-2119, www.sys-bio.org, http://reproduciblebiomodels.org/ Mobile: 206-880-8093 @.*** Books: http://books.analogmachine.org/

On Fri, Feb 2, 2024 at 4:19 PM Lucian Smith @.***> wrote:

Looking through old issues...

The problem here is that 'x' is a parameter, not a species, and roadrunner insists that Jacobians only involve species. Do we want to relax that restriction at some point, so that parameters that change due to rate rules can be part of the Jacobian matrix?

Model that fails:

import tellurium as teimport roadrunner r = te.loada(""" x' = -k1*x x = 10 k1 = 0.1""") r.getFullJacobian()

Model that succeeds:

import tellurium as teimport roadrunner r = te.loada(""" species x x' = -k1*x x = 10 k1 = 0.1""") print(r.getFullJacobian())

— Reply to this email directly, view it on GitHub https://urldefense.com/v3/__https://github.com/sys-bio/roadrunner/issues/652*issuecomment-1924932570__;Iw!!K-Hz7m0Vt54!nPgdWeXwPR3yM5QimDa1mqCqEwgbe2-DhjXAhF-sVWu7qSKO20J3XJZIbcsiJesb8oh2YZ0IRnsD2C2TwlLtLcZtwHF51A$, or unsubscribe https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AAIBSDWJXI2KMGV4OZCI7ZDYRV7ABAVCNFSM4OR4VPNKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJSGQ4TGMRVG4YA__;!!K-Hz7m0Vt54!nPgdWeXwPR3yM5QimDa1mqCqEwgbe2-DhjXAhF-sVWu7qSKO20J3XJZIbcsiJesb8oh2YZ0IRnsD2C2TwlLtLcasq5jj0w$ . You are receiving this because you authored the thread.Message ID: @.***>