Fitters return a copy of the model #1564
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As discussed in #1330 and #979 fitters should return a modified copy of the model instead of modifying it in place.
This PR is not completed yet but I am submitting it to get opinions on a side effect which breaks the current constraints API.
As a reminder of how the constraints code evolved, initially constraints were attributes on fitters but it was felt largely that it would be better to move them to models and in particular be attributes on parameters (
~astropy.modeling.parameters.Parameter
) which is what they currently are. This facilitates interactive use of~astropy.modeling
, so it's possible to do something like:The second call to
gfit
will pick up the change in the constraints.In this PR fitters make a copy of the model and don't hold a reference to the initial model any more so the above code does not work as expected. This means that changing the constraints interactively will have to use the copy of the model too.
Since this is an end user API change I wanted to see how others felt about it.