Skip to content

Allow using SampleModels as resolution#196

Open
henrikjacobsenfys wants to merge 5 commits into
developfrom
resolution-model-from-sample-model
Open

Allow using SampleModels as resolution#196
henrikjacobsenfys wants to merge 5 commits into
developfrom
resolution-model-from-sample-model

Conversation

@henrikjacobsenfys
Copy link
Copy Markdown
Member

Closes #193

@henrikjacobsenfys henrikjacobsenfys added [scope] enhancement Adds/improves features (major.MINOR.patch) [priority] medium Normal/default priority labels May 29, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.14%. Comparing base (556b95f) to head (0ac389b).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #196      +/-   ##
===========================================
+ Coverage    98.13%   98.14%   +0.01%     
===========================================
  Files           51       51              
  Lines         3542     3567      +25     
  Branches       652      661       +9     
===========================================
+ Hits          3476     3501      +25     
  Misses          36       36              
  Partials        30       30              
Flag Coverage Δ
integration 44.77% <24.13%> (-0.15%) ⬇️
unittests 98.03% <100.00%> (+0.01%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@henrikjacobsenfys henrikjacobsenfys linked an issue May 30, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Member

@rozyczko rozyczko left a comment

Choose a reason for hiding this comment

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

Good code. Minor comments added for consideration.

Q=sample_model.Q,
)

from copy import copy
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be a top-level import like elsewhere. No need to import it every time you call this method

Comment on lines 405 to 406
"instrument_model.resolution_model.fix_all_parameters()\n",
"instrument_model.normalize_resolution()\n",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

are these still needed?

Comment on lines +123 to +128
resolution_model = cls(
display_name=sample_model.display_name,
unit=sample_model.unit,
components=sample_model.components,
Q=sample_model.Q,
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

cls(components=sample_model.components, Q=sample_model.Q, ...) invokes ModelBase._generate_component_collections, which calls the base append_component, not ResolutionModel.append_component.
This means the check for DeltaFunction, Polynomial, and Exponential is never done.

If someone passes a SampleModel that contains a DeltaFunction, it will silently find its way to the ResolutionModel. Consider adding an explicit check at the top of from_sample_model:

for comp in sample_model.components:
    if isinstance(comp, (DeltaFunction, Polynomial, Exponential)):
        raise TypeError(
            f'SampleModel contains a {comp.__class__.__name__}, '
            f'which is not allowed in a ResolutionModel.'
        )

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I added a test that this isn't the case :) It does use the append_component from ResolutionModel, not from the base class.

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.

Make it possible to fit the resolution to a sample model

2 participants