Skip to content

Detector hits keep a copy of the traced beam, not the live beam - #138

Closed
TacHawkes wants to merge 2 commits into
masterfrom
fix/beamlet-hit-aliasing
Closed

TacHawkes wants to merge 2 commits into
masterfrom
fix/beamlet-hit-aliasing

Conversation

@TacHawkes

Copy link
Copy Markdown
Collaborator

A detector keeps the hits of earlier solves, such that several sources solved one after another superpose. The hits however referred to the traced beam: RayHit/PolarizedRayHit to its ray, the beamlet hits to the beamlet and a segment index. solve_system! reuses the beam, its first ray and its vectors of rays, and moving a beam moves its first ray, hence solving the same beam again without initializing changed the stored hits: e.g. the field of a GaussianBeamletHit on the second segment of a beamlet dropped from 690 to 17 V/m after the beamlet was solved again with a moved mirror. Affected were hits on the first ray of every beam type and hits of beamlets on later rays.

The hits now store detached_copys: of the ray for ray hits, of the whole beamlet (with copies of its parent beamlets) for beamlet hits. The copies share the Intersections, which are not changed after the tracing step that computes them. Copying the whole beamlet, not only the segments up to the hit, keeps the hits of intermediate segments (e.g. built by the OpticsBase extension) as they were.

Solving a beamlet onto a detector through three lenses takes 1-4 % longer and allocates 29 % more for beamlets.

Fixes #42.

A detector keeps the hits of earlier solves, such that several sources
solved one after another superpose. The hits however referred to the
traced beam: `RayHit`/`PolarizedRayHit` to its ray, the beamlet hits to
the beamlet and a segment index. `solve_system!` reuses the beam, its
first ray and its vectors of rays, and moving a beam moves its first
ray, hence solving the same beam again without initializing changed
the stored hits: e.g. the field of a `GaussianBeamletHit` on the second
segment of a beamlet dropped from 690 to 17 V/m after the beamlet was
solved again with a moved mirror. Affected were hits on the first ray
of every beam type and hits of beamlets on later rays.

The hits now store `detached_copy`s: of the ray for ray hits, of the
whole beamlet (with copies of its parent beamlets) for beamlet hits.
The copies share the `Intersection`s, which are not changed after the
tracing step that computes them. Copying the whole beamlet, not only
the segments up to the hit, keeps the hits of intermediate segments
(e.g. built by the OpticsBase extension) as they were.

Solving a beamlet onto a detector through three lenses takes 1-4 %
longer and allocates 29 % more for beamlets.

Fixes #42
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T20:23:51.429391Z bd7ba00 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bd7ba007eb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

struct RayHit{T} <: AbstractRayHit{T}
ray::Ray{T}
opl::T
RayHit(ray::Ray{T}, opl::Real) where {T} = new{T}(detached_copy(ray), opl)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Update detector-hit lifecycle guidance

The snapshotting introduced here makes the statement in skills/beamletoptics/WORKFLOW.md:46 that detector hits “reference beam state” and must be read before solving again false; the Detector docstring retains the same obsolete warning. Update that user-facing guidance to distinguish safe re-solves from the remaining caveat about evaluating old hits after moving the detector, otherwise the version-matched agent skill teaches behavior this commit intentionally removed.

AGENTS.md reference: AGENTS.md:L103-L112

Useful? React with 👍 / 👎.

The hits are copies since the previous commit: solving again or moving
a beam or another object no longer changes them. What remains is that
the hits are stored in world coordinates while `spot_diagram`,
`electric_field` and `PlaneField(detector)` evaluate them in the current
pose of the detector, hence they are read before the detector itself is
moved. Updated: the `Detector` docstring, the `PlaneField(detector)`
docstring of the OpticsBase extension and the agent skill
(`WORKFLOW.md`).
@codecov

codecov Bot commented Oct 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.34%. Comparing base (66b711e) to head (b38316c).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #138      +/-   ##
==========================================
+ Coverage   89.22%   89.34%   +0.12%     
==========================================
  Files          81       81              
  Lines        4500     4516      +16     
==========================================
+ Hits         4015     4035      +20     
+ Misses        485      481       -4     

☔ View full report in Codecov by Harness.
📢 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.

@StackEnjoyer

Copy link
Copy Markdown
Owner

Replaced by #164

@StackEnjoyer
StackEnjoyer deleted the fix/beamlet-hit-aliasing branch October 21, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Detector hits change when their beam is solved again

2 participants