Skip to content

Refactor evaluation and optics APIs with enhanced documentation#112

Merged
singer-yang merged 12 commits intodevfrom
refactor_func
Mar 4, 2026
Merged

Refactor evaluation and optics APIs with enhanced documentation#112
singer-yang merged 12 commits intodevfrom
refactor_func

Conversation

@singer-yang
Copy link
Copy Markdown
Collaborator

This pull request refactors and modernizes the ray sampling and constraint logic in the lens design codebase. The most significant changes are the unification of ray sampling methods under a new, more flexible API (sample_from_fov), deprecation of older methods, and updates to constraint and loss functions to better reflect physical lens properties. These changes improve code clarity, maintainability, and extendibility.

Ray Sampling API Refactor:

  • Introduced a unified sample_from_fov method that handles both collimated (infinite-depth) and point-source (finite-depth) ray bundles, replacing the previous sample_parallel and sample_point_source methods and updating all internal calls to use the new API (deeplens/optics/geolens.py). [1] [2] [3] [4] [5] [6] [7] [8]
  • Added sample_from_points_by_fov for sampling point-source rays specified by field angles and depth, and extended sample_radial_rays to support sampling along the x, y, or diagonal directions (deeplens/optics/geolens.py). [1] [2]

Constraint and Loss Function Updates:

  • Replaced the loss_gap function and its references with a new loss_thickness function, which penalizes excessive air gaps, lens thickness, and total track length. Updated related parameter names and documentation (deeplens/optics/geolens_pkg/optim.py). [1] [2] [3] [4] [5]
  • Added and updated constraint parameters for air gap, thickness, and total track length limits (ttl_max) in the optimizer initialization (deeplens/optics/geolens_pkg/optim.py). [1] [2]

Diffractive Lens Initialization Consistency:

  • Ensured that the focal length (foclen) is always set based on the sensor distance (d_sensor) and that the field of view is recalculated in diffractive lens examples and initialization (deeplens/optics/diffraclens.py). [1] [2] [3]

Minor Fixes and Cleanups:

  • Updated a function call in unwarp to use the correct method name calc_distortion_map (deeplens/optics/geolens.py).
  • Improved docstrings and argument descriptions for clarity in several methods (deeplens/optics/geolens.py). [1] [2]

These changes collectively modernize the codebase, making it more robust, easier to use, and ready for further extension.

singer-yang and others added 12 commits February 28, 2026 22:43
…pment

Enrich all 20 function docstrings in GeoLensEval with physics context,
algorithm descriptions, typed args with units/shapes, and cross-references
so that AI models can understand and reimplement each evaluation function.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Replace calc_distortion_2D with calc_distortion_radial (derives field
  angles from self.rfov, consistent with draw_spot_radial pattern)
- Remove rfov param from draw_distortion_radial (now self-contained)
- Rename distortion_map -> calc_distortion_map, draw_distortion ->
  draw_distortion_map for naming consistency
- Add wavefront_error(), rms_wavefront_error(), draw_wavefront_error()
  for OPD-based wavefront analysis at the exit pupil
- Update callers in geolens.py and test files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
rms_map now accepts an optional `center` arg and returns (rms, centroid).
rms_map_rgb calls rms_map three times — green first to obtain the
reference centroid, then red and blue with center=green_centroid.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…core

Add spot_points() as the single ray-tracing entry point for spot diagrams
and RMS maps. Refactor draw_spot_radial, draw_spot_map, and rms_map to use
point_source_radial/point_source_grid for physical coordinates, then delegate
to spot_points. Add direction parameter (x/y/diagonal) to radial sampling
and tuple num_grid support for non-square grids.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Return Ray object from spot_points so callers can use Ray methods
directly. Replace the duplicated centroid calculation in rms_map with
ray.centroid()[..., :2].

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace sample_parallel and sample_point_source with a single
sample_from_fov method that handles both collimated (depth=inf)
and diverging (depth=finite) ray bundles. Simplify sample_grid_rays
and sample_radial_rays to delegate to the unified API.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Separate the finite-depth (point-source) logic into its own method
sample_from_points_by_fov, which converts FOV angles to physical
coordinates and delegates to sample_from_points. sample_from_fov
now delegates to it for finite depth.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
scale_pupil=1.5 inflated pre-aperture surface clear apertures to ~2x the
stop radius because oversampled rays passed front surfaces but were clipped
at the aperture. The expand_factor (5-10%) already provides manufacturing
margin, making the 1.5x pupil scaling redundant and harmful.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Set `foclen` to `d_sensor` (total track length) in DiffractiveLens
  initialization and example loaders, ensuring FOV is calculated.
- Propagate `foclen` from the underlying lens object in PSFNetLens.
…raint

- Rename loss_gap → loss_thickness with TTL (total track length) check
- Add ttl_max: 8mm for cellphone, 300mm for camera lenses
- Loosen air_max_center from 0.5mm to 1.5mm for cellphone lenses
- Increase w_reg from 0.05 to 0.1 for stronger regularization
- Fix NaN from invalid ray masking using torch.where (IEEE 754 safety)
- Clamp tmax2tmin denominator to prevent Inf from near-zero edge thickness
- Remove prune_surf step 4 (edge thickness enforcement) — handled by loss_reg
- Unify prune_surf expand_factor to 10% for all lenses

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Rename test_loss_gap_scalar to test_loss_thickness_scalar to match
  loss_gap → loss_thickness rename
- Add GeoLensSeidel and GeoLensSurfOps mixins to API reference and
  architecture docs
- Replace nonexistent prepare_optimization() with get_optimizer() in
  examples

Co-Authored-By: Claude <noreply@anthropic.com>
@singer-yang singer-yang merged commit 0cc8234 into dev Mar 4, 2026
@singer-yang singer-yang deleted the refactor_func branch April 4, 2026 14:11
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.

1 participant