Skip to content

Dispersion error propagation was using wrong values#579

Open
mattiastefanelli wants to merge 2 commits into
masterfrom
fixed_propagated_errdisp
Open

Dispersion error propagation was using wrong values#579
mattiastefanelli wants to merge 2 commits into
masterfrom
fixed_propagated_errdisp

Conversation

@mattiastefanelli
Copy link
Copy Markdown
Contributor

In Dispersion._compute_elements, the call to propagate_error_dispersion was incorrectly passing model_disp (the model dispersion) as its first argument. According to the propagation formula (see below), this argument must be the model beta function. The fix replaces model_disp with model_beta extracted from the segment model.

image

The current implementation covers only the first term of the full dispersion uncertainty.

@mattiastefanelli mattiastefanelli requested a review from a team as a code owner April 29, 2026 15:58
@github-actions
Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  omc3/segment_by_segment/propagables
  dispersion.py 117-125
Project Total  

This report was generated by python-coverage-comment-action

@mattiastefanelli mattiastefanelli self-assigned this Apr 30, 2026
@mattiastefanelli mattiastefanelli added Estimate: Easy Good first issue for newcomers. Straightforward fixes. Priority: Low Work on this if you have some spare time. Status: In Progress Currently being worked on. Domain: Physics The implementation is closely related to new physics to be used. labels Apr 30, 2026
@jgray-19
Copy link
Copy Markdown
Contributor

Nice PR. I assume you have some checks that proves this is correct? If so, could be nice to include.

@fsoubelet. If adding tests is not a priority would you be happy to merge despite the coverage failure?? I'm hesitant to do this especially if the fix isn't very urgent.

Also I haven't looked in the code, but please make sure all the equations used are documented.

@jgray-19 jgray-19 added the Type: Bug Something isn't working as it should. label Apr 30, 2026
Copy link
Copy Markdown
Member

@JoschD JoschD left a comment

Choose a reason for hiding this comment

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

  • Remove comment in fixed line
  • Fix function arguments in the other places

@mattiastefanelli
Copy link
Copy Markdown
Contributor Author

def propagate_error_dispersion(beta: ArrayLike, dphi: ArrayLike, init: SegmentBoundaryConditions) -> ArrayLike:
    """Propagates the dispersion error with dphi phase-advance.

    Args:
        beta (ArrayLike): Beta function at the observation point(s).
        dphi (ArrayLike): Phase advances from the initial position to the observation point(s), in units of 2pi radians.
        init (PropagableBoundaryConditions): Initial conditions for alpha and beta and the dispersion uncertainty.
    """
    _, errdispersion0 = init.dispersion
    beta0, _ = init.beta
    alpha0, _ = init.alpha

    return np.abs(
        errdispersion0 * np.sqrt(beta / beta0) *
        (np.cos(2 * np.pi * dphi) + alpha0 * np.sin(2 * np.pi * dphi))
    )

the main function for the dispersion error was already expecting beta (beta (ArrayLike): Beta function at the observation point(s)), I removed the comment in fixed code line.

@fsoubelet
Copy link
Copy Markdown
Member

I'd be interested in seeing a before and after if possible, this should be a big change of the error bars considering the values difference in beta vs disp.

This does not feel urgent (especially with the schedule this year) so I would like to see a test added with new truth values.

Also, thanks @mattiastefanelli for re-deriving the expressions, we can already see that it was useful beyong safekeeping :)

@mattiastefanelli
Copy link
Copy Markdown
Contributor Author

I am also preparing some notes for the error propagation equations. So that we have a document to use as reference for future works. @jgray-19

@jgray-19
Copy link
Copy Markdown
Contributor

Yes I think a test would be nice. You could create a finite difference test, which would also test the accuracy of your derivations?

@mattiastefanelli
Copy link
Copy Markdown
Contributor Author

Thanks @fsoubelet! The errors indeed increase considering the betas instead of the dispersions in the equation. But the main thing for which I noticed the bug is the fact that we were getting NaNs when the dispersion become negative which was strange. In the plot the red 'x' are pointing to points with NaN as errors for a test segment. The screenshot gives an example of the increase in the error estimation.

dx_propagated Screenshot from 2026-04-30 15-44-25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Domain: Physics The implementation is closely related to new physics to be used. Estimate: Easy Good first issue for newcomers. Straightforward fixes. Priority: Low Work on this if you have some spare time. Status: In Progress Currently being worked on. Type: Bug Something isn't working as it should.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants