Skip to content

Feature: ObjectGroup is a container, no AbstractObject - #135

Merged
StackEnjoyer merged 6 commits into
masterfrom
refactor/issue-113-objectgroup
Oct 15, 2026
Merged

StackEnjoyer merged 6 commits into
masterfrom
refactor/issue-113-objectgroup

Conversation

@StackEnjoyer

Copy link
Copy Markdown
Owner

Features

  • Breaking: ObjectGroup is a kinematic container and no AbstractObject any more
  • Breaking: group members are read via BeamletOptics.objects(group), shape(group) is removed
  • System, push!, delete!, render! and live_render! take objects and groups via the internal ObjectOrGroup

Bugfixes

  • StaticSystem(object): a single object overflowed the stack

Doc changes

  • AbstractObjectGroup, ObjectGroup: docstrings state the container interface
  • Kinematics API, systems, components and live rendering pages name groups separately
  • Agent skill: components/systems-and-groups.md updated

Internal changes

  • BeamletOpticsGUI needs a follow-up for its BMO.AbstractObject signatures and BMO.shape(group) calls

Closes #113

AbstractObjectGroup no longer subtypes AbstractObject. A group has no shape
trait: its members are read via objects(group), and kinematics, intersect3d,
bounding spheres and rendering of groups are methods on the group type. The
internal alias ObjectOrGroup names what a System stores and render! draws.

StaticSystem(object) with a single object no longer overflows the stack.

BeamletOpticsGUI needs a follow-up for its AbstractObject signatures and its
shape(group) calls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codecov

codecov Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.77778% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.69%. Comparing base (9630be5) to head (cc8f35e).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/System.jl 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #135      +/-   ##
==========================================
+ Coverage   89.57%   89.69%   +0.12%     
==========================================
  Files          81       82       +1     
  Lines        4498     4504       +6     
==========================================
+ Hits         4029     4040      +11     
+ Misses        469      464       -5     

☔ 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.

TacHawkes added a commit that referenced this pull request Oct 11, 2026
A wider check of ForwardDiff against finite differences found further
failures, now fixed:

- Polarized rays and astigmatic beamlets at normal incidence threw an
  orthogonality error: `isparallel3d` took the `norm` of a cross product
  that vanishes but has a derivative, which is `NaN` (also its value)
  for dual numbers, hence the s-p basis was built from a zero vector. It
  now compares the squared norm. The Fresnel coefficients of lenses and
  polarizers are computed from the cosine of the angle of incidence
  (`_fresnel_coefficients`, `cos_angle3d`), since the derivative of the
  `acos` is not defined at normal incidence.
- `ThinBeamsplitter` (also within `CubeBeamsplitter`) required the
  reflectance in the number type of the shape; a constructor converts it.
- `CircularFlatMesh` built its vertices as `Float64`, which broke round
  plate beamsplitters, polarization filters and mirrors.

`test/TestAutoDiff.jl` now covers 68 cases: radius, thickness, tilt,
refractive index, polarized rays and astigmatic beamlets on the axis,
thin, plate and cube beamsplitters, total internal reflection, Malus'
law, the power on a detector and the power of a Michelson
interferometer vs. the position of a mirror.

New docs page "Automatic differentiation" (usage, covered components,
limitations: discrete events, edges, forward mode only, compile time,
`ObjectGroup(objects, T)`), and a section in the agent skill
(`WORKFLOW.md`). `ObjectGroup` still defaults to `Float64`; its
constructor is changed by #135.
Hugo Uittenbosch and others added 5 commits October 14, 2026 12:38
Docstrings, docs pages, the agent skill and test comments described object
groups by contrast to the former type tree. They now state the current API.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AbstractObjectGroup is no AbstractObject any more (#113), so its type,
ObjectOrGroup and the group methods move from AbstractObject.jl into
AbstractObjectGroup.jl, like AbstractBeamGroup.jl. No code changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A MultiShape object without interact3d stops every ray that hits it. The
warning now says to forward the beam to the part that was hit if the parts
interact as one, or to use an ObjectGroup or a subtype of AbstractObjectGroup
if they interact on their own. Objects with a single shape keep the old
warning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Separate parts form an ObjectGroup or an own subtype of AbstractObjectGroup,
which needs no interact3d; only parts that touch and interact as one form a
MultiShape object with its own interact3d. The rule is in the skill
(systems-and-groups.md, CHECKLIST.md, SKILL.md) and in the docs (moving
objects, geometry). Template 08 builds an own group type with named parts.

For that template, set_pivot3d! moves from ObjectGroup to
AbstractObjectGroup, and AbstractObjectGroup is declared public.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@StackEnjoyer
StackEnjoyer merged commit a797781 into master Oct 15, 2026
4 checks passed
@StackEnjoyer
StackEnjoyer deleted the refactor/issue-113-objectgroup branch October 15, 2026 08:33
StackEnjoyer pushed a commit that referenced this pull request Oct 27, 2026
* Speed up the aspheric SDFs: Horner sums, cached edge values

The distance field of an aspheric or acylindric surface evaluated the
asphere at its edge (sag and gradient) on every call, although both are
constant for a surface, and summed the even terms with integer powers.
The SDFs now store the edge values (`edge`, see `aspheric_edge`) and the
sums use Horner's scheme in r². An empty coefficient vector now gives
the conic surface instead of an error.

One `sdf` call of an asphere drops from ~107 ns to ~29 ns; a beam group
of 20000 rays through an aspheric lens solves in 83 ms instead of 163 ms
(1 thread). Distances agree with the previous code to ~3e-15 relative,
ray intersections are bit-identical.

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

* Automatic differentiation on the optical axis

ForwardDiff through `solve_system!` gave the correct derivative for
rays off the axis but 0 or a wrong value for rays on it, without a
warning, e.g. for the spot position behind a lens w.r.t. its lateral
shift: 0 instead of 1.90 (bi-convex), -0.97 instead of -1.98
(bi-concave), NaN for parabolic and conic mirrors. Rays on the axis,
e.g. the chief ray of a rotationally symmetric system, are the ones an
optimizer differentiates. The causes, all where the derivative of a
normal is taken, i.e. in nested automatic differentiation:

- The radius of revolution `norm(Point2(x, z))` is `NaN` on the axis in
  nested AD, which turned the comparisons of SDF branches, and the
  derivative of the radius is not defined there. `_radial` is exactly 0
  on the axis, and the surfaces that cross the axis are computed from
  smooth expressions: the 3D distance from the center of a sphere
  (`CutSphereSDF`, `ConvexSphericalSurfaceSDF`), the sag and slope of
  aspheres and conics as functions of r².
- Where a concave surface touches the face of the lens body at its
  vertex, both are equally close, and the flat face was taken, which
  has no curvature. `UnionSDF` now resolves such ties by the operand
  that is closest beside the point (`_closest_operand`), independent of
  the order of the operands; within the aspheric SDFs the surface wins
  ties with the segments that close the perimeter.
- A hit of `_raymarch_outside` that ends slightly within the shape has
  its normal evaluated outside, as the exits of the inside march.
- `refractive_index(optic, λ)` returned `Float64`, which dropped the
  derivative w.r.t. a refractive index or the wavelength; it returns the
  number type of the optic and the wavelength.

New `test/TestAutoDiff.jl`: ForwardDiff against central finite
differences for rays on and off the axis through spherical, meniscus,
aspheric and cylindrical lenses and spherical, parabolic and conic
mirrors, w.r.t. a refractive index and through a GaussianBeamlet
(ForwardDiff added to the test dependencies). SDF values, normals and
hit lengths agree with the previous code to ~1e-17 m. Built on the
aspheric changes of #137.

* Automatic differentiation: polarization, beamsplitters, docs

A wider check of ForwardDiff against finite differences found further
failures, now fixed:

- Polarized rays and astigmatic beamlets at normal incidence threw an
  orthogonality error: `isparallel3d` took the `norm` of a cross product
  that vanishes but has a derivative, which is `NaN` (also its value)
  for dual numbers, hence the s-p basis was built from a zero vector. It
  now compares the squared norm. The Fresnel coefficients of lenses and
  polarizers are computed from the cosine of the angle of incidence
  (`_fresnel_coefficients`, `cos_angle3d`), since the derivative of the
  `acos` is not defined at normal incidence.
- `ThinBeamsplitter` (also within `CubeBeamsplitter`) required the
  reflectance in the number type of the shape; a constructor converts it.
- `CircularFlatMesh` built its vertices as `Float64`, which broke round
  plate beamsplitters, polarization filters and mirrors.

`test/TestAutoDiff.jl` now covers 68 cases: radius, thickness, tilt,
refractive index, polarized rays and astigmatic beamlets on the axis,
thin, plate and cube beamsplitters, total internal reflection, Malus'
law, the power on a detector and the power of a Michelson
interferometer vs. the position of a mirror.

New docs page "Automatic differentiation" (usage, covered components,
limitations: discrete events, edges, forward mode only, compile time,
`ObjectGroup(objects, T)`), and a section in the agent skill
(`WORKFLOW.md`). `ObjectGroup` still defaults to `Float64`; its
constructor is changed by #135.

* Asphere SDFs: evaluate sag and slope once per sdf call

The surface distances computed the sag and the slope via the functions of r for the NaN guard and the branch conditions, then again via the functions of r^2 for the distance. They now evaluate both once, as functions of r^2, with the guard taken from the square root argument. gradient_aspheric_equation delegates to the same slope, so its formula exists once.

Review F1 on PR #148.

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

* UnionSDF: state the scale for which the tie-break offset holds

Review F2 on PR #148.

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

* AutoDiff tests: compare with paraxial ABCD references

For a ray on the axis and a laterally shifted lens or mirror, the derivative of the spot w.r.t. the shift is 1 - A of the paraxial ABCD matrix, built in the test from the parameters.

Review F3 on PR #148.

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

* AutoDiff tests: readouts with a RegularGrid sampling

Since #171, optical_power takes the sampling as an argument instead of the keywords n, x_min, ...

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

* Internal: the CI job on Julia pre does not fail the CI (#173)

Julia 1.14.0-alpha1 calls issubnormal in normalize, which ForwardDiff 1.4.6
does not define for Dual (JuliaDiff/ForwardDiff.jl#852, fix in #855). The
job keeps running and reporting, but no longer blocks merges.

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Hugo Uittenbosch <[email protected]>
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.

Remove ObjectGroup from AbstractObject type tree

1 participant