Repository navigation
Make the dependents of a copied model follow the copy - #304
Merged
Merged
Conversation
EasyScience's from_dict builds an object from its values and then swaps in the deserialised Parameters. Anything __init__ made dependent still follows the Parameters it created, which are then discarded. A copy, which goes through from_dict, therefore ignored changes to its own parameters: - StretchedExponential: the width did not follow beta and relaxation_time. - The diffusion models: the per-Q components did not follow the model's parameters; A_1 did not follow A_0 in DeltaLorentz and MittagLefflerDiffusion; and the EISF of a DeltaLorentz did not follow mean_u_squared. from_dict now rebuilds those dependents on the Parameters in place. Split out of the PR for issue #126. The mean_u_squared case was found by an independent review of that PR. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #304 +/- ##
===========================================
+ Coverage 98.21% 98.23% +0.02%
===========================================
Files 65 65
Lines 6399 6419 +20
Branches 1082 1082
===========================================
+ Hits 6285 6306 +21
Misses 60 60
+ Partials 54 53 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
Part of #126. Split out of #294, and best merged before it.
Problem
A copy of some objects silently ignored changes to its own parameters.
EasyScience's
from_dict, whichcopygoes through, builds an object from its values and then swaps in the deserialized Parameters. Anything__init__made dependent keeps following the Parameters it created, which are then discarded:StretchedExponential: the width of a copy did not follow itsbetaandrelaxation_time.DeltaLorentzandMittagLefflerDiffusion:A_1did not followA_0.DeltaLorentz: the EISF did not followmean_u_squared.A fit of such a copy would vary a parameter with no effect.
Change
from_dictrebuilds the dependents on the Parameters now in place:StretchedExponential.from_dictdrops the width, which thewidthproperty rebuilds on first use.DiffusionModelBase.from_dictcalls a new_on_parameters_replacedhook, which rebuilds the per-Q components.DeltaLorentzandMittagLefflerDiffusionre-tie their dependent parameters in it first.Review
An independent review of #294 found the
mean_u_squaredcase, which the original change missed, and reproduced it. It is fixed here and covered by theDeltaLorentztest.Tests
One test in each of
test_stretched_exponential.py,test_brownian_translational_diffusion.py,test_delta_lorentz.pyandtest_mittag_leffler_diffusion.py: change a parameter of a copy and compare with a model built with that value.🤖 Generated with Claude Code