visisipy.optiland.backend#

Optiland backend for Visisipy.

Classes#

OptilandSettings

Backend settings that are specific to the Optiland backend.

OptilandBackend

Optiland backend.

Module Contents#

class visisipy.optiland.backend.OptilandSettings#

Bases: visisipy.backend.BackendSettings

Backend settings that are specific to the Optiland backend.

computation_backend: ComputationBackend#

Backend used for numerical operations. Must be one of ‘numpy’ or ‘torch’. See https://optiland.readthedocs.io/en/latest/developers_guide/configurable_backend.html for more details.

When using ‘torch’, the ‘torch’ package must be installed manually.

torch_device: TorchDevice#

Device to use for torch backend. Must be one of ‘cpu’ or ‘cuda’. Only used if computation_backend is ‘torch’.

torch_precision: TorchPrecision#

Precision to use for torch backend. Must be one of ‘float32’ or ‘float64’. Only used if computation_backend is ‘torch’.

torch_use_grad_mode: bool#

Globally enable or disable autodifferentiation for the ‘torch’ backend. Only used if computation_backend is ‘torch’.

class visisipy.optiland.backend.OptilandBackend#

Bases: visisipy.backend.BaseBackend

Optiland backend.

property analysis: visisipy.optiland.analysis.OptilandAnalysisRegistry#

Provides access to the OptilandAnalysisRegistry instance.

This property provides access to the OptilandAnalysisRegistry instance for performing various analyses on the optical system.

Returns#

OpticStudioAnalysisRegistry

The OptilandAnalysisRegistry instance.

Raises#

RuntimeError

If the Optiland backend has not been initialized.

classmethod initialize(**settings: visisipy.backend.Unpack[OptilandSettings]) None#

Initialize the Optiland backend.

This method initializes the Optiland backend with the given settings and creates a new model.

Parameters#

settingsOptilandSettings | None, optional

The settings to be used for the Optiland backend. If None, the default settings are used.

classmethod update_settings(**settings: visisipy.backend.Unpack[OptilandSettings]) None#

Apply the provided settings to the Optiland backend.

This method applies the provided settings to the Optiland backend.

classmethod new_model(*, save_old_model: bool = False, save_filename: os.PathLike | str | None = None) None#

Initialize a new optical system.

This method initializes a new, empty optical system.

classmethod build_model(model: visisipy.EyeModel, *, start_from_index: int = 0, replace_existing: bool = False, object_distance: float = float('inf'), **kwargs) visisipy.optiland.models.OptilandEye#

Builds an optical system based on the provided eye model.

This method creates an OptilandEye instance from the provided eye model and builds the optical system. If replace_existing is True, any existing model is updated instead of building a completely new system.

Parameters#

modelEyeModel

The eye model to be used for building the optical system model.

start_from_indexint, optional

The index of the surface after which the eye model will be built. The cornea front surface will be located at start_from_index + 1.

replace_existingbool, optional

Whether to replace any existing model before building the new one. Defaults to False.

object_distancefloat

Distance between the cornea front and the surface preceding the eye model.

**kwargs

Additional keyword arguments to be passed to the OptilandEye build method.

Returns#

OptilandEye

The built optical system model.

classmethod clear_model() None#

Clear the current optical system model.

This method initializes a new optical system, discarding any existing model.

classmethod save_model(path: str | os.PathLike | None = None) None#

Save the current optical system model.

This method saves the current optical system model to the specified path. If no path is provided, it saves the model to the current working directory with the default name (model.json).

Parameters#

pathstr | PathLike | None, optional

The path where the model should be saved. If None, the model is saved in the current working directory. The file extension must be .json.

classmethod get_optic() optiland.optic.Optic#

Get the optic object.

Returns#

Optic

The optic object.

Raises#

RuntimeError

If the optic object is not initialized.

classmethod get_aperture() tuple[visisipy.types.ApertureType, float]#

Get the current aperture type and value.

Returns#

tuple[str, float]

A tuple containing the aperture type and value.

classmethod get_fields() list[tuple[float, float]]#

Get the fields in the optical system.

Returns#

list[tuple[float, float]]

List of field coordinates.

classmethod set_fields(coordinates: collections.abc.Iterable[tuple[float, float]], field_type: Literal['angle', 'object_height'] = 'angle')#

Set the fields for the optical system.

This method removes any existing fields and adds the new ones provided.

Parameters#

coordinatesIterable[tuple[float, float]]

An iterable of tuples representing the coordinates for the fields.

field_typeLiteral[“angle”, “object_height”], optional

The type of field to be used in the optical system. Can be either “angle” or “object_height”. Defaults to “angle”.

classmethod get_wavelengths() list[float]#

Get the wavelengths in the optical system.

Returns#

list[float]

List of wavelengths.

classmethod set_wavelengths(wavelengths: collections.abc.Iterable[float])#

Set the wavelengths for the optical system.

This method removes any existing wavelengths and adds the new ones provided. The weight for each wavelength is set to 1.0.

Parameters#

wavelengthsIterable[float]

An iterable of wavelengths to be set for the optical system.

classmethod iter_fields() collections.abc.Generator[tuple[int, tuple[float, float]], Any, None]#

Iterate over the fields in the optical system.

Yields#

int

Field index.

tuple[float, float]

Field X and Y coordinates.

classmethod iter_wavelengths() collections.abc.Generator[tuple[int, float], Any, None]#

Iterate over the wavelengths in the optical system.

Yields#

int

Wavelength index.

float

Wavelength value.

classmethod set_computation_backend(backend: ComputationBackend, *, torch_device: TorchDevice = 'cpu', torch_precision: TorchPrecision = 'float32', torch_use_grad_mode: bool = False) None#

Set the computation backend for Optiland.

Parameters#

backendComputationBackend

The computation backend to use. Must be one of ‘numpy’ or ‘torch’.

torch_devicestr, optional

The device to use for the ‘torch’ backend. Must be one of ‘cpu’ or ‘cuda’. Defaults to ‘cpu’.

torch_precisionstr, optional

The precision to use for the ‘torch’ backend. Must be one of ‘float32’ or ‘float64’. Defaults to ‘float32’.

torch_use_grad_modebool, optional

Whether to enable gradient mode for the ‘torch’ backend. Defaults to False.

classmethod update_pupil(new_value: float) None#

Update the pupil size in the optical system.

Parameters#

new_valuefloat

The new pupil size to be set.