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

Enable setting constraints on state variables #2340

Merged
merged 17 commits into from
Mar 7, 2024

Conversation

dweindl
Copy link
Member

@dweindl dweindl commented Mar 4, 2024

In addition to the current Model.setStateIsNonNegative, this adds the option to set additional (non)negativity/positivity constraints to be enforced by the solver.

See CVodeSetConstraints for details.

Related to #2327.

In addition to the current `Model.setStateIsNonNegative`, this adds the option to set additional
(non)negativity/positivity constraints to be enforced by the solver.

See [CVodeSetConstraints](https://sundials.readthedocs.io/en/latest/cvode/Usage/index.html#c.CVodeSetConstraints) for details.

Related to AMICI-dev#2327.
Copy link

codecov bot commented Mar 4, 2024

Codecov Report

Attention: Patch coverage is 90.00000% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 77.70%. Comparing base (3dded5c) to head (897e9d1).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2340      +/-   ##
===========================================
+ Coverage    77.66%   77.70%   +0.04%     
===========================================
  Files          324      324              
  Lines        20824    20864      +40     
  Branches      1454     1458       +4     
===========================================
+ Hits         16173    16213      +40     
  Misses        4648     4648              
  Partials         3        3              
Flag Coverage Δ
cpp 73.48% <90.00%> (+0.05%) ⬆️
cpp_python 34.23% <22.50%> (-0.03%) ⬇️
petab 36.82% <20.00%> (-0.04%) ⬇️
python 72.25% <77.50%> (+0.02%) ⬆️
sbmlsuite ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
include/amici/serialization.h 96.78% <100.00%> (+0.12%) ⬆️
include/amici/solver.h 100.00% <100.00%> (ø)
include/amici/solver_cvodes.h 100.00% <ø> (ø)
include/amici/solver_idas.h 100.00% <ø> (ø)
include/amici/vector.h 83.33% <ø> (ø)
src/hdf5.cpp 89.98% <100.00%> (+0.07%) ⬆️
src/solver_cvodes.cpp 69.91% <83.33%> (+0.14%) ⬆️
src/solver_idas.cpp 37.69% <83.33%> (+0.48%) ⬆️
src/solver.cpp 75.71% <84.61%> (+0.13%) ⬆️

... and 1 file with indirect coverage changes

@dweindl dweindl marked this pull request as ready for review March 4, 2024 12:31
@dweindl dweindl requested a review from a team as a code owner March 4, 2024 12:31
@dweindl dweindl self-assigned this Mar 4, 2024
assert np.any(rdata.x < 0)

amici_solver.setRelativeTolerance(1e-14)
amici_solver.setConstraints([1.0, 1.0])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add an enum for 0.0/1.0/2.0/-1.0/-2.0 values for a bit more user convenience??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, probably makes sense to automatically add constraints when using Model::setStateIsNonNegative and add this behaviour to the documentation of setConstraints and setStateIsNonNegative.

Copy link
Member Author

@dweindl dweindl Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add an enum for 0.0/1.0/2.0/-1.0/-2.0 values for a bit more user convenience??

done

also, probably makes sense to automatically add constraints when using Model::setStateIsNonNegative and add this behaviour to the documentation of setConstraints and setStateIsNonNegative.

I am not completely sure about this one. While I agree that it makes sense to imply the constraints in setStateIsNonNegative True, this would lead to some funny behavior when disabling non-negativity.

# I want to enable constraints:
model.setConstraints([non_negative])
# I want to enable the max(0, state) in addition:
model.setStateIsNonNegative([True])
# I decide to disable the latter
model.setStateIsNonNegative([False]) # implies setConstraints([none]) ?!
# now it also cleared my original constraint

I think I'd prefer to keep them independent for now.

@dweindl dweindl merged commit 7a920e2 into AMICI-dev:develop Mar 7, 2024
20 checks passed
@dweindl dweindl deleted the feature_2327_constraints branch March 7, 2024 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants