Skip to content

Conversation

@jgray-19
Copy link
Contributor

No one asked for this, but it was quite a simple implementation and is very informative to me and potentially others.

Still a draft as the test on the error is just testing if the error exists, not actually testing that the error is calculated correctly.

Also, ruffed these files.

Also: Refactor code style and improve readability in handler.py and test_global_correction.py
@github-actions
Copy link

github-actions bot commented Oct 17, 2025

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
11595 10038 87% 80% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
omc3/correction/handler.py 96% 🟢
TOTAL 96% 🟢

updated for commit: 98db5d6 by action🐍

@jgray-19 jgray-19 requested a review from Copilot October 28, 2025 22:50
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements error propagation in the global correction algorithm and applies code formatting improvements (black/ruff) across test and handler files. The key functional change is the addition of error calculation and propagation for correction parameters, particularly for DPP (momentum deviation) corrections.

  • Error propagation added to the correction calculations using standard error propagation formulas
  • Error column added to delta DataFrames and properly propagated through iterations
  • Code formatting standardized (quotes, line breaks, spacing) throughout test and handler files

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/accuracy/test_global_correction.py Added ERROR import, test assertion for DPP error, and formatting improvements (quotes, line breaks, spacing)
omc3/correction/handler.py Implemented error propagation in delta calculations, updated optimization methods to return errors, and code formatting improvements

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

raise ValueError("svd_cut setting needed for pseudo inverse method.")
return np.dot(np.linalg.pinv(response_mat, opt.svd_cut), diff_vec)
pinv_mat = np.linalg.pinv(response_mat, opt.svd_cut)
return np.dot(pinv_mat, diff_vec), np.dot(pinv_mat**2, err_vec)
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

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

The error propagation formula is incorrect. For a linear transformation y = A*x where x has variances σ²_x, the variance of y should be σ²_y = A * σ²_x * A^T (matrix form) or element-wise σ²_y = sum((A²) * σ²_x). The current formula np.dot(pinv_mat**2, err_vec) is computing element-wise squaring of the matrix, which is incorrect. It should be np.dot(pinv_mat**2, err_vec) where the squaring is element-wise on the matrix, but this doesn't properly account for the covariance structure. The correct formula should be np.einsum('ij,j->i', pinv_mat**2, err_vec) or (pinv_mat**2 @ err_vec) to properly sum the squared contributions.

Suggested change
return np.dot(pinv_mat, diff_vec), np.dot(pinv_mat**2, err_vec)
return np.dot(pinv_mat, diff_vec), np.einsum('ij,j->i', pinv_mat**2, err_vec)

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  omc3/correction
  handler.py 86, 98, 383, 391
Project Total  

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants