solves

class BaseSolve[source]

Applies a solve operation.

This method should be implemented by subclasses to define the specific behavior of the solve operation.

Raises:

NotImplementedError – If the method is not implemented by the subclass.

abstract apply()[source]

Applies the solve operation to the optic.

classmethod from_dict(optic, data)[source]

Creates a solve from a dictionary representation.

Parameters:
  • optic (Optic) – The optic object.

  • data (dict) – The dictionary representation of the solve.

Returns:

The solve.

Return type:

BaseSolve

to_dict()[source]

Returns a dictionary representation of the solve.

Returns:

A dictionary representation of the solve.

Return type:

dict

class ChiefRayAngleCurvatureSolve(optic, surface_idx: int, angle: float)[source]

Adjusts surface curvature to achieve a target chief ray exit angle.

This solve uses the paraxial refraction equation:

n’u’ - nu = -y(n’ - n)c

to solve for curvature c:

c = (nu - n’u’) / (y(n’ - n))

optic

The optic object.

Type:

Optic

surface_idx

The index of the surface.

Type:

int

angle

The target exit angle (u’) of the chief ray.

Type:

float

apply()[source]

Applies the chief ray angle solve.

Since changing the system affects the chief ray path (it must pass through the stop), this solve is iterative.

classmethod from_dict(optic, data)

Creates a solve instance from a dictionary representation.

to_dict()[source]

Returns a dictionary representation of the solve.

ChiefRayAngleSolve

alias of ChiefRayAngleCurvatureSolve

ChiefRayHeightSolve

alias of ChiefRayHeightThicknessSolve

class ChiefRayHeightThicknessSolve(optic, surface_idx: int, height: float)[source]

Solves for a target chief ray height on a specific surface.

apply()

Applies the thickness solve to the optic.

This method calculates the necessary shift in z-position for the target surface and all subsequent surfaces to achieve the desired ray height.

classmethod from_dict(optic, data)

Creates a solve instance from a dictionary representation.

to_dict()

Returns a dictionary representation of the solve.

class CurvatureSolve(optic, surface_idx: int)[source]

Abstract base class for curvature solves.

This class provides the common structure for solves that aim to satisfy a condition by adjusting the curvature of a specific surface.

optic

The optic object.

Type:

Optic

surface_idx

The index of the surface where the curvature is to be controlled.

Type:

int

abstract apply()[source]

Applies the curvature solve to the optic.

classmethod from_dict(optic, data)[source]

Creates a solve instance from a dictionary representation.

to_dict()[source]

Returns a dictionary representation of the solve.

class MarginalRayAngleCurvatureSolve(optic, surface_idx: int, angle: float)[source]

Adjusts surface curvature to achieve a target marginal ray exit angle.

This solve uses the paraxial refraction equation:

n’u’ - nu = -y(n’ - n)c

to solve for curvature c:

c = (nu - n’u’) / (y(n’ - n))

optic

The optic object.

Type:

Optic

surface_idx

The index of the surface.

Type:

int

angle

The target exit angle (u’) of the marginal ray.

Type:

float

apply()[source]

Applies the marginal ray angle solve.

classmethod from_dict(optic, data)

Creates a solve instance from a dictionary representation.

to_dict()[source]

Returns a dictionary representation of the solve.

MarginalRayAngleSolve

alias of MarginalRayAngleCurvatureSolve

MarginalRayHeightSolve

alias of MarginalRayHeightThicknessSolve

class MarginalRayHeightThicknessSolve(optic, surface_idx: int, height: float)[source]

Solves for a target marginal ray height on a specific surface.

apply()

Applies the thickness solve to the optic.

This method calculates the necessary shift in z-position for the target surface and all subsequent surfaces to achieve the desired ray height.

classmethod from_dict(optic, data)

Creates a solve instance from a dictionary representation.

to_dict()

Returns a dictionary representation of the solve.

class QuickFocusSolve(optic, *args)[source]

Quick Focus :param optic: The optic object. :type optic: Optic

Raises:

ValueError – If the optical system is not defined.

apply()[source]

Applies the QuickFocusSolve to the optic.

This method calculates the optimal focus distance and sets the z-position of the last surface (image plane) accordingly.

classmethod from_dict(optic, data)

Creates a solve from a dictionary representation.

Parameters:
  • optic (Optic) – The optic object.

  • data (dict) – The dictionary representation of the solve.

Returns:

The solve.

Return type:

BaseSolve

optimal_focus_distance(Hx=0, Hy=0, wavelength=0.55, num_rays=5, distribution='hexapolar')[source]

Compute the optimal location of the image plane where the RMS spot size is minimized. This is based on solving the quadratic equation that describes the RMS spot size as a function of the propagation distance.

Parameters:
  • Hx (float) – The normalized x field.

  • Hy (float) – The normalized y field.

  • wavelength (float) – The wavelength of the light.

  • num_rays (int) – The number of rays to trace.

  • distribution (str) – The distribution of rays to trace.

Returns:

The optimal axial position (z-coordinate) of the image plane

that minimizes the RMS spot size.

Return type:

float

to_dict()

Returns a dictionary representation of the solve.

Returns:

A dictionary representation of the solve.

Return type:

dict

RayHeightSolveBase

alias of ThicknessSolve

class SolveFactory[source]

Factory class for creating solves.

This factory uses a predefined map to find and instantiate the appropriate solve class based on the provided solve_type.

static create_solve(optic, solve_type: str, surface_idx, *args, **kwargs)[source]

Creates a solve instance based on the given solve type.

Parameters:
  • optic (Optic) – The optic object to which the solve will be applied.

  • solve_type (str) – The type of solve to create (e.g., ‘marginal_ray_height’, ‘quick_focus’, ‘chief_ray_height’).

  • surface_idx (int) – The index of the surface relevant to the solve. May not be used by all solve types (e.g., ‘quick_focus’).

  • *args – Variable length argument list. For height-based solves, the first argument (args[0]) is expected to be the height.

  • **kwargs – Arbitrary keyword arguments. (Currently unused in favor of positional arguments for height).

Returns:

An instance of the solve class corresponding to the given solve type.

Raises:

ValueError – If the solve type is invalid or if required arguments for a specific solve type are missing or invalid.

class SolveManager(optic)[source]

Manages the application of solves to an optic.

Parameters:

optic (Optic) – The optic object

solves

A list of solve instances.

Type:

list

add(solve_type, surface_idx, *args, **kwargs)[source]

Adds a solve instance to the list of solves.

apply()[source]

Applies all solves in the list.

add(solve_type, surface_idx=None, *args, **kwargs)[source]

Adds a solve instance to the list of solves.

Parameters:
  • solve_type (str) – The type of solve to create.

  • surface_idx (int) – The index of the surface.

  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

apply()[source]

Applies all solves in the list.

clear()[source]

Clears the list of solves.

classmethod from_dict(optic, data)[source]

Creates a SolveManager from a dictionary representation.

Parameters:
  • optic (Optic) – The optic object.

  • data (dict) – The dictionary representation of the solve manager.

Returns:

The solve manager.

Return type:

SolveManager

remap_surface_indices(remap_func)[source]

Remaps the surface indices of all relevant solves.

Parameters:

remap_func (callable) – A function that takes an old surface index and returns a new surface index.

to_dict()[source]

Returns a dictionary representation of the solve manager.

Returns:

A dictionary representation of the solve manager.

Return type:

dict

class ThicknessSolve(optic, surface_idx: int, height: float)[source]

Abstract base class for thickness solves.

This class provides the common structure for solves that aim to achieve a specific ray height at a given surface by adjusting the z-position of that surface and subsequent surfaces.

optic

The optic object.

Type:

Optic

surface_idx

The index of the surface where the ray height is to be controlled.

Type:

int

height

The target height of the ray on the specified surface.

Type:

float

apply()[source]

Applies the thickness solve to the optic.

This method calculates the necessary shift in z-position for the target surface and all subsequent surfaces to achieve the desired ray height.

classmethod from_dict(optic, data)[source]

Creates a solve instance from a dictionary representation.

to_dict()[source]

Returns a dictionary representation of the solve.