sys-bio / roadrunner

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

removeInitialAssignment results in many variables changing #1195

Open dalbabur opened 3 months ago

dalbabur commented 3 months ago

Context I have a model with many InitialAssignments, such as C12214= v1*0.001*dilution_factor where C12214 is a species and v1 and dilution_factor are variables. In some instances, I'd like to override the InitialAssignment and set the species concentration to a fixed value, say C12214= 1.0.

Issue I'm looping through the variables and species initial concentrations that I want to override and calling r.setValue('init('+var+')', new_value). Everything works as expected when setting variables, but when setting species initial concentrations other variables in the model are changing as well. This happens regardless of which species I'm changing, and it always affects the same variables. The issue seems to be with r.removeInitialAssignment()

Workaround Setting the concentration, r.setValue('['+var+']', new_value), as opposed to the initial concentration works as expected. In this case I don't need to change the initial concentration so this is okay.

luciansmith commented 3 months ago

The way things are supposed to work is that if you have two initial assignments:

a = b+2 b = c+3 c = 5

and then you set init(b) to 4, a will change to 6, because its initial assignment is still 'b+2'.

Is that what you're seeing? Or is something else going on?

dalbabur commented 3 months ago

yup that makes sense, and I also see that behavior. my issue is more like this:

model definition:

C12214= v1*0.001*dilution_factor
...
C00356= v275*0.002*dilution_factor
v1 = 876
v275 = 756
dilution_factor = 1 

change initial concentrations:

r.setValue('init([C12214])', 3.0)

results in: r['init([C12214])'] = 3.0 and suddenly r['v275'] = 1

luciansmith commented 3 months ago

Well, that's probably a bug, then! Can you provide a working example? A large one is fine if that's what you have.