Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow enabling/disabling state reinitialization for individual states #1345

Closed
dweindl opened this issue Nov 30, 2020 · 14 comments · Fixed by #1417
Closed

Allow enabling/disabling state reinitialization for individual states #1345

dweindl opened this issue Nov 30, 2020 · 14 comments · Fixed by #1417
Assignees

Comments

@dweindl
Copy link
Member

dweindl commented Nov 30, 2020

So far, state-reinitialization can is only be switched on/off for all states (whose initial state depends on fixedParameters) at once.
Would be convenient, it this could be handled more dynamically by ignoring any reinitialization for the states for which x0 evaluates to NaN.

@dweindl
Copy link
Member Author

dweindl commented Dec 9, 2020

Turns out my original plan doesn't work out as smoothly as hoped for (started on #1344). The inconvenience is, that one would have to add one additional constant to the model for each state (or group of states) that one may want to conditionally reinitialize or not.

Not completely sure how the ideal interface for that would look like. Would be good if one could enable/disable state reinitialization for individual states via ExpData, and without adding additional model parameters/constants. Any ideas comments on how to best handle that?

Ideally that would be also easily adaptable to more complex setups than preequilibration+simulation, where one might want to specify multiple (time-dependent) state reinitializations (independently of SBML events).

@paulstapor
Copy link
Contributor

The problem is how the functions x0_fixedParameters and sx0_fixedParameters work, right?

@dweindl
Copy link
Member Author

dweindl commented Dec 9, 2020

The problem is how the functions x0_fixedParameters and sx0_fixedParameters work, right?

Yes, the overall problem/motivation is that you can't use x0_fixedParameters to reinitialize varying sets of states. Either you reinitialize all states from x0_fixedParameters (with reinitializeFixedParameterInitialStates=true) or none (with reinitializeFixedParameterInitialStates=false), but nothing inbetween.

@paulstapor
Copy link
Contributor

well, obviously one could hack this by saving the old state and wrapping around the current code in C++. But this is cumbersome and error-prone. Better would be to add an "ix" variable to the headers of those two functions/files, implementing a switch statement in the files themselves, like this is already done for sensitivity function files with ip or event function files now with ie. So, we already have a very comparable concept for similar cases...
Obviously, this would break Matlab vs Python version and we would need another "if (python_generated)" in AMICI... But that would be fine from my side... Implementable in 2 roughly days, I'd say, including tests and code review. Pure coding time should be less...

Btw.: This functionality would also be highly welcome when dealing with adjoint preequilibration...

@dweindl
Copy link
Member Author

dweindl commented Feb 2, 2021

Oh, somehow I overlooked your reply @paulstapor . Sounds good, either some index list, or a boolean array. Maybe the former is better, as it's more in line with plist as you pointed out.

@FFroehlich - works for you? Any other suggestions?

@FFroehlich
Copy link
Member

Sounds good!

@dweindl
Copy link
Member Author

dweindl commented Feb 4, 2021

Just to make sure we are talking about the same thing. We would:

  • add a list of state indices that are to be reinitialized after preequilibration to Model+ExpData (also for after presimulation?)
  • change (s)x0_fixedParameters to initialize only those states whose index is on said list (or did you mean x0?)

For PEtab import that would mean that for constant initial values in the condition table, that for any state there, we would add a constant parameter that we would set to that value of the respective condition. If any condition has an estimated parameter there, we'd have to add a non-constant parameter there (or two, one for beforepreequilibration and one for afterwards).

@FFroehlich
Copy link
Member

Just to make sure we are talking about the same thing. We would:

  • add a list of state indices that are to be reinitialized after preequilibration to Model+ExpData (also for after presimulation?)
  • change (s)x0_fixedParameters to initialize only those states whose index is on said list (or did you mean x0?)

For PEtab import that would mean that for constant initial values in the condition table, that for any state there, we would add a constant parameter that we would set to that value of the respective condition. If any condition has an estimated parameter there, we'd have to add a non-constant parameter there (or two, one for beforepreequilibration and one for afterwards).

Yes, sounds good!

@paulstapor
Copy link
Contributor

paulstapor commented Feb 9, 2021

Just to make sure we are talking about the same thing. We would:

  • add a list of state indices that are to be reinitialized after preequilibration to Model+ExpData (also for after presimulation?)
  • change (s)x0_fixedParameters to initialize only those states whose index is on said list (or did you mean x0?)

Should indeed be (s)x0_fixedParameters, I think..

For PEtab import that would mean that for constant initial values in the condition table, that for any state there, we would add a constant parameter that we would set to that value of the respective condition. If any condition has an estimated parameter there, we'd have to add a non-constant parameter there (or two, one for beforepreequilibration and one for afterwards).

Somehow not completely sure whether I got that...

@dweindl
Copy link
Member Author

dweindl commented Feb 12, 2021

  • add a list of state indices that are to be reinitialized after preequilibration to Model+ExpData (also for after presimulation?)

  • change (s)x0_fixedParameters to initialize only those states whose index is on said list (or did you mean x0?)

How should that interact with the existing reinitializeFixedParameterInitialStates?

A) If reinitializeFixedParameterInitialStates == true, then all are reinitialized, otherwise only those on said list
B) If reinitializeFixedParameterInitialStates == true, then said index list is used, otherwise it's ignored.
C) Remove reinitializeFixedParameterInitialStates

A is the only backward compatible solution, but C seems more reasonable.

@FFroehlich
Copy link
Member

  • add a list of state indices that are to be reinitialized after preequilibration to Model+ExpData (also for after presimulation?)
  • change (s)x0_fixedParameters to initialize only those states whose index is on said list (or did you mean x0?)

How should that interact with the existing reinitializeFixedParameterInitialStates?

A) If reinitializeFixedParameterInitialStates == true, then all are reinitialized, otherwise only those on said list
B) If reinitializeFixedParameterInitialStates == true, then said index list is used, otherwise it's ignored.
C) Remove reinitializeFixedParameterInitialStates

A is the only backward compatible solution, but C seems more reasonable.

I agree that A sounds pretty counterintuitive and B is impractical. The issue that I have with C is that we effectively lose the option to easily specify that everything depending on fixedParameters is to be reinitialized.

I am currently under the impression that debugging anything in AMICI has become very tedious, particularly with the changes to ExpData and think we should keep this in mind that ease of use outside PEtab applications is still important.

What about turning the boolean into enums with x0_reinit_list (or something along those lines), fixedParameters and off, where booleans map to these enums such that backwards compatibility is kept?

@dweindl
Copy link
Member Author

dweindl commented Feb 12, 2021

I am currently under the impression that debugging anything in AMICI has become very tedious, particularly with the changes to ExpData and think we should keep this in mind that ease of use outside PEtab applications is still important.

Which changes do you mean exactly? Agreed with the last point. (If it's easy to use without PEtab, it also makes PEtab import easier to implement...)

What about turning the boolean into enums with x0_reinit_list (or something along those lines), fixedParameters and off, where booleans map to these enums such that backwards compatibility is kept?

Would be an option. It's only slightly annoying and a potential source of error if one needs to flip two switches instead of one. Alternatively something corresponding to Model::requireSensitivitiesForAllParameters() which we have for that case for plist.

@FFroehlich
Copy link
Member

I am currently under the impression that debugging anything in AMICI has become very tedious, particularly with the changes to ExpData and think we should keep this in mind that ease of use outside PEtab applications is still important.

Which changes do you mean exactly? Agreed with the last point. (If it's easy to use without PEtab, it also makes PEtab import easier to implement...)

ExpData is really super cumbersome to modify, so what I usually have to do is move all simulation specs to model, remove them from ExpData and then perturb them to figure out whats going on.

What about turning the boolean into enums with x0_reinit_list (or something along those lines), fixedParameters and off, where booleans map to these enums such that backwards compatibility is kept?

Would be an option. It's only slightly annoying and a potential source of error if one needs to flip two switches instead of one. Alternatively something corresponding to Model::requireSensitivitiesForAllParameters() which we have for that case for plist.

I see your point, going with something along the lines of Model::requireSensitivitiesForAllParameters() sounds good to me.

dweindl added a commit that referenced this issue Feb 18, 2021
…fixes (#1417)

Adds possibility to provide state indices for selective reinitialization based on fixed parameters.

The previous `ExpData::reinitializeFixedParameterInitialStates` is still there, but will be removed in an upcoming version.


Addresses #1345, #1396, #1319

Supersedes #1344 

Include new test cases from PEtab-dev/petab_test_suite#35
@dweindl
Copy link
Member Author

dweindl commented Feb 20, 2021

Included in 0.11.13

@dweindl dweindl closed this as completed Feb 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants