Skip to content

Add make_parameter_Q_independent to ModelBase - #298

Merged
henrikjacobsenfys merged 11 commits into
developfrom
issue-70-q-independent
Nov 24, 2026
Merged

henrikjacobsenfys merged 11 commits into
developfrom
issue-70-q-independent

Conversation

@henrikjacobsenfys

@henrikjacobsenfys henrikjacobsenfys commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Part of #70 (second of four PRs). Stacked on #297; review that one first.

Problem

To make a parameter take one value at all Q, users had to call EasyScience's make_dependent_on on each per-Q parameter by hand. Those hand-made dependencies were also lost whenever the per-Q collections were rebuilt.

Change

sample_model.make_parameter_Q_independent('Water Lorentzian', 'width')
analysis.fit(fit_method='simultaneous')

sample_model.remove_parameter_Q_constraint('Water Lorentzian', 'width')  # undo
  • How it ties: the parameter at every other Q is made dependent on the one at Q index 0, so only that one is varied in a fit. This only makes sense with fit_method='simultaneous'; in an independent fit the value comes from the fit of Q index 0 alone.
  • Rebuilds: the model stores the tie and reapplies it after the per-Q collections are rebuilt or patched in place, and when Q is set later. Removing the component drops the tie.
  • fix_parameter / free_parameter: on a Q-independent parameter they act on Q index 0 and the template, and the other Q follow.
  • Already-dependent parameters: raise ValueError, e.g. a parameter generated by a diffusion model.
  • Undo: remove_parameter_Q_constraint makes every Q independent again, each keeping its current value.

Tests

New # Q constraints (issue #70) section in test_model_base.py.

Review

Merge #301 first. With a Q constraint on a plain model, fix_all_parameters() and free_all_parameters() raise AttributeError: ... dependent parameters cannot be fixed until #301 is in.

An independent review reproduced two bugs, both fixed and covered:

  • A constraint on a component generated by a diffusion model outlived remove_diffusion_model, and remove_parameter_Q_constraint then raised a KeyError.
  • clear_components() with Q unset kept the constraint for a later component of the same name.

Things to be aware of:

  • remove_parameter_Q_constraint leaves mixed fixed flags. Q index 0 keeps its flag and the other Q come back free, since a dependent parameter has none.
  • normalize_area() raises on a tied area, as it does for the areas a diffusion model generates.
  • With a JointAnalysis (Add JointAnalysis for fitting several data sets together #290), a tie works when it is set on the model of the first analysis. On a following model the link overwrites it.

🤖 Generated with Claude Code

henrikjacobsenfys and others added 2 commits November 12, 2026 12:08
Address one Parameter of a named component at every Q, or at a single Q,
without looping over the per-Q component collections by hand. Fixing or
freeing at every Q also updates the template, so it survives a rebuild.

Part of #70.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Tie one Parameter of a named component to a single value across Q, by
making it at every other Q dependent on the one at Q index 0. The model
stores the tie and reapplies it whenever the per-Q collections are
rebuilt or patched. remove_parameter_Q_constraint undoes it.

Part of #70.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@henrikjacobsenfys henrikjacobsenfys added [scope] enhancement Adds/improves features (major.MINOR.patch) [priority] medium Normal/default priority labels Nov 12, 2026
@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.27%. Comparing base (56257cd) to head (f40583f).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #298      +/-   ##
===========================================
+ Coverage    98.26%   98.27%   +0.01%     
===========================================
  Files           65       65              
  Lines         6504     6548      +44     
  Branches      1094     1105      +11     
===========================================
+ Hits          6391     6435      +44     
  Misses          60       60              
  Partials        53       53              
Flag Coverage Δ
unittests 98.27% <100.00%> (+0.01%) ⬆️

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

Files with missing lines Coverage Δ
src/easydynamics/sample_model/model_base.py 100.00% <100.00%> (ø)
src/easydynamics/sample_model/sample_model.py 99.58% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

henrikjacobsenfys and others added 7 commits November 12, 2026 23:39
The description promises that fixing a dependent parameter raises the
EasyScience AttributeError; that is now tested. Two tests matched the
full text of an EasyScience KeyError and only need the missing name.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Found by an independent review, each reproduced with a script.

- A constraint on a component generated by a diffusion model outlived
  remove_diffusion_model, and remove_parameter_Q_constraint then raised
  a KeyError. SampleModel recorded the diffusion models' versions after
  the base class reapplied the constraints, which it skips while the
  collections count as stale. The two lines are swapped.
- clear_components without Q kept the constraint for a later component
  of the same name, since pruning only runs on per-Q collections.
  clear_components now clears the constraints.

Also: say in the docstring which fixed flags a removed constraint
leaves, and drop a test that repeated get_parameters' own.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…eter

# Conflicts:
#	tests/unit/easydynamics/sample_model/test_model_base.py
#	tests/unit/easydynamics/sample_model/test_sample_model.py
…ue-70-q-independent

# Conflicts:
#	tests/unit/easydynamics/sample_model/test_model_base.py
copy and to_dict/from_dict re-create a model from its __init__
arguments, so constraints added with make_parameter_Q_independent were
lost. to_dict now writes them under 'Q_independent_parameters', and
from_dict reapplies them after construction.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…dent

# Conflicts:
#	src/easydynamics/sample_model/model_base.py
#	tests/unit/easydynamics/sample_model/test_model_base.py
#	tests/unit/easydynamics/sample_model/test_sample_model.py
@henrikjacobsenfys
henrikjacobsenfys changed the base branch from issue-70-fix-parameter to develop November 24, 2026 10:23
@henrikjacobsenfys
henrikjacobsenfys merged commit 1fc0ce8 into develop Nov 24, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[priority] medium Normal/default priority [scope] enhancement Adds/improves features (major.MINOR.patch)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant