sys-bio / roadrunner

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

Config setting causes RuntimeError: bad variant access #991

Open kirichoi opened 2 years ago

kirichoi commented 2 years ago

Hi all,

Today I have been fiddling with the latest libroadrunner release and found that whenever I try to configure parameters using something like:

roadrunner.Config.setValue(roadrunner.Config.ROADRUNNER_DISABLE_WARNINGS, 3)

it raises RuntimeError: bad variant access. Any call that uses roadrunner.Config.setValue() cause this problem. This error is specifically evoked by steadyState() for some reason. Any thoughts?

Here's a minimal example:

import tellurium as te
import roadrunner

roadrunner.Config.setValue(roadrunner.Config.ROADRUNNER_DISABLE_WARNINGS, 3)

testModel = """
var S1, S2, S3;
const S0, S4;
J0: S0 -> S1; Kf0*S0/(1 + S0);
J1: S1 -> S2; Kf1*S1/(1 + S1);
J2: S2 -> S3; Kf2*S2/(1 + S2);
J3: S3 -> S4; Kf3*S3/(1 + S3);
J4: S1 -> S3; Kf4*S1/(1 + S1);

Kf0 = 0.285822003905
Kf1 = 0.571954691013
Kf2 = 0.393173236422
Kf3 = 0.75830845241
Kf4 = 0.148522702962

S0 = 3
S4 = 5
S1 = 1
S2 = 1
S3 = 1
"""

r = te.loada(testModel)
r.steadyState()

and here's my version info:

[('tellurium', '2.2.2.1'),
 ('roadrunner', '2.2.0'),
 ('rrplugins', '2.2.0'),
 ('antimony', '2.12.0.3'),
 ('libsbml', '5.19.4'),
 ('libsedml', '2.0.30'),
 ('phrasedml', '1.1.1')]
kirichoi commented 2 years ago

I found that this only happens to a subset of configuration parameters. ROADRUNNER_DISABLE_WARNINGS is one, STEADYSTATE_APPROX_MAX_STEPS is another, but STEADYSTATE_APPROX works fine when I tried to run steadyState() with approximation routine.

luciansmith commented 2 years ago

I've investigated and discovered that ROADRUNNER_DIABLE_WARNINGS is supposed to be a Boolean value, and will throw an error if you set it to something else and then try to get it as a Boolean. So you can fix your most immediate problem by changing:

roadrunner.Config.setValue(roadrunner.Config.ROADRUNNER_DISABLE_WARNINGS, 3)

to:

roadrunner.Config.setValue(roadrunner.Config.ROADRUNNER_DISABLE_WARNINGS, True)

However, we clearly need to do some type checking if this sort of error is the result, so I'm leaving this issue open until we can do that.

luciansmith commented 2 years ago

Further investigation shows that the option used to be a bitfield/int, but later was changed to a bool, perhaps out of ignorance. I have to say that the option is very confusing, and that bitfield options seem hard to follow from a user's perspective.

Do you know what the option was originally supposed to do, and how it worked?

kirichoi commented 2 years ago

Thanks for looking into this issue. ROADRUNNER_DISABLE_WARNINGS used to accept intergers from 1 to 3, each corresponding to different levels of disabling warnings and notices. You can find more from the old libroadrunner documentation. I'm guessing something similar happened to STEADYSTATE_APPROX_MAX_STEPS, which should take an integer. I think the documentation on the config parameters should be updated and perhaps we can implement some tests along with it.