Merged
Conversation
Contributor
Author
|
NOTE this should not negatively affect the uncertainties calculations done at the end of the fit. In that case, for each fitter If the covariance matrix is being distorted by the error introduced in #3375 (I'm not sure if it is), then the current PR should fix that as well. |
krzywon
approved these changes
Dec 9, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
The compiled constraints are supposed to be a function that takes the parameters as input, and updates the values of the parameters based on the constraint expressions supplied, after each call to
problem.setp(pvec), through thesetp_hook()function.The existing code (introduced in #3375) was incorrectly replacing the parameter names with
f"{name}.slot", which is wrong for 2 reasons:P1 = P2, it was instead executingP1.slot = P2.slot, which replaces theVariablein the slot ofP1with the actualVariableinstance inP2, so that theP1is essentially an alias forP2after that. This will "work" and the fit will complete, but the parameter structure of the model is changed in an unintended way.M1.scale = M2.scale * 1.2you end up with this expression to evaluate:M1.scale.slot = M2.scale.slot * 1.2, which doesn't work becauseM2.scale.slotis an instance ofVariable, on which we can't directly do arithmetic.To achieve the goal of the compiled constraint functions, we should instead use the
.valueattribute; on the LHS of the equality, it will trigger the.valuesetter which pushes the new value down into the slot, and on the RHS it will use the getter to pull the value back out of the slot for (as a float) for doing expression math on it.This fixes a sub-issue in #3793 (comment)
How Has This Been Tested?
Ran the constrained fit in this project:
6-1-2-constrained-fit-expr.json
Review Checklist:
[if using the editor, use
[x]in place of[ ]to check a box]Documentation (check at least one)
Installers
Licensing (untick if necessary)