optiland.rays.ray_aiming.cached#

Cached Ray Aiming Module

This module implements a caching wrapper for ray aiming algorithms. It stores previous results to speed up repetitive calculations, especially during optimization or tolerance analysis where system changes might be small.

Retained for backward compatibility (explicit cache=True) but no longer the default warm-start mechanism for "robust", which has its own intrinsic, always-on PupilMapCache (see pupil_map.py and robust.py).

Kramer Harrison, 2025

Classes

CachedRayAimer(optic, wrapped_aimer[, ...])

Cached ray aiming strategy.

class CachedRayAimer(optic: Optic, wrapped_aimer: BaseRayAimer, max_cache_size: int = 128, **kwargs: Any)[source]#

Cached ray aiming strategy.

This class wraps another ray aimer and caches its results. It checks if the inputs and the optical system state have changed. If they match a cached entry, the result is returned immediately. If the system has changed but inputs match, the previous result is used as a starting guess.

Coordinate-frame note: cached entries are full launch states in global coordinates. The system hash covers every surface, so any rigid pose change (translation, fold reorientation) misses the exact-reuse path and the stale state is only ever passed as an initial_guess to the wrapped aimer, which re-solves (and, for the robust aimer, falls back to a fresh entry-frame calibration if the stale guess fails). A stale global-coordinate state can therefore cost time but never correctness.

Variables:
  • optic (Optic) – The optical system being traced.

  • wrapped_aimer (BaseRayAimer) – The actual aiming strategy being cached.

  • max_cache_size (int) – Maximum number of entries in the cache.

aim_rays(fields: tuple, wavelengths: Any, pupil_coords: tuple, initial_guess: tuple | None = None) tuple[source]#

Calculate ray starting coordinates, using cache if available.

Parameters:
  • fields (tuple) – Field coordinates.

  • wavelengths (Any) – Wavelengths.

  • pupil_coords (tuple) – Pupil coordinates.

  • initial_guess (tuple | None, optional) – Explicit starting guess.

Returns:

Ray parameters (x, y, z, L, M, N).

Return type:

tuple

clear_cache() None[source]#

Clear the internal cache.