artist.optim.aim_point_optimizer
Attributes
A logger for the aim point optimizer. |
Classes
Initialize the aim points optimizer. |
Module Contents
- artist.optim.aim_point_optimizer.log
A logger for the aim point optimizer.
- class artist.optim.aim_point_optimizer.AimPointOptimizer(ddp_setup: artist.util.env.DdpSetup, scenario: artist.scenario.scenario.Scenario, optimization_configuration: dict[str, Any], incident_ray_direction: torch.Tensor, target_area_index: int, ground_truth: torch.Tensor, dni: float, bitmap_resolution: torch.Tensor = torch.tensor([256, 256]), epsilon: float = 1e-12, device: torch.device | None = None)
Initialize the aim points optimizer.
Parameters
- ddp_setupDdpSetup
Information about the distributed environment, process groups, devices, ranks, world size, and heliostat-group-to-ranks mapping.
- scenarioScenario
The scenario.
- optimization_configurationdict[str, Any]
Parameters for the optimizer, learning rate scheduler, regularizers, and early stopping.
- incident_ray_directiontorch.Tensor
Incident ray direction during the optimization. Shape is
[4].- target_area_indexint
Index of the target used for the optimization.
- ground_truthtorch.Tensor
Desired focal spot or distribution. Shape is
[4]or[bitmap_resolution_e, bitmap_resolution_u].- dnifloat
Direct normal irradiance in W/m^2.
- bitmap_resolutiontorch.Tensor
Resolution of all bitmaps during optimization (default is
torch.tensor([256,256])). Shape is[2].- epsilonfloat
A small value to avoid division by zero (default is 1e-12).
- devicetorch.device | None
The device on which to perform computations or load tensors and models (default is None). If None,
ARTISTwill automatically select the most appropriate device (CUDA or CPU) based on availability and OS.
- ddp_setup
- scenario
- optimizer_dict
- scheduler_dict
- constraint_dict
- incident_ray_direction
- target_area_index
- ground_truth
- dni
- bitmap_resolution
- epsilon = 1e-12
- _initialize_group_parameters(device: torch.device) tuple[list[torch.nn.Parameter], list[torch.Tensor], list[torch.Tensor], list[torch.Tensor], list[torch.Tensor], list[torch.Tensor], torch.Tensor]
Pre-align all heliostat groups and set up their reparameterized motor positions.
Each group is aligned once to the given incident ray direction and target to obtain the initial motor positions. The optimizable parameter is a zero-initialized reparameterization of the motor positions (see
optimize()).Parameters
- devicetorch.device
The device on which to perform computations or load tensors and models.
Returns
- list[torch.nn.Parameter]
The optimizable reparameterized motor position parameters per group.
- list[torch.Tensor]
The reparameterization scales per group.
- list[torch.Tensor]
The initial motor positions per group.
- list[torch.Tensor]
The active heliostats masks per group.
- list[torch.Tensor]
The target area indices per group.
- list[torch.Tensor]
The incident ray directions per group.
- torch.Tensor
Offsets mapping group-local heliostat indices to global-flat index positions.
- _setup_optimizer_scheduler_early_stopping(optimizable_parameters_all_groups: list[torch.nn.Parameter]) tuple[torch.optim.Optimizer, torch.optim.lr_scheduler.LRScheduler, artist.optim.training.EarlyStopping]
Create the optimizer, learning rate scheduler, and early stopping.
Parameters
- optimizable_parameters_all_groupslist[torch.nn.Parameter]
The optimizable reparameterized motor position parameters per group.
Returns
- torch.optim.Optimizer
The Adam optimizer over all group parameter tensors.
- LRScheduler
The learning rate scheduler.
- training.EarlyStopping
The early stopping monitor.
- _get_target_plane_dimensions(device: torch.device) torch.Tensor
Determine the target plane dimensions for the optimization target.
Handles both planar and cylindrical target areas.
Parameters
- devicetorch.device
The device on which to perform computations or load tensors and models.
Returns
- torch.Tensor
The width and height of the target plane. Shape is
[2].
- _align_all_groups(optimizer: torch.optim.Optimizer, initial_motor_positions_all_groups: list[torch.Tensor], scales_all_groups: list[torch.Tensor], active_heliostats_masks_all_groups: list[torch.Tensor], device: torch.device) None
Align all heliostat groups on this rank from the reparameterized motor positions.
The true motor positions are reconstructed from the
tanh-reparameterized parameters.Parameters
- optimizertorch.optim.Optimizer
The optimizer holding the reparameterized motor position parameters.
- initial_motor_positions_all_groupslist[torch.Tensor]
The initial motor positions per group.
- scales_all_groupslist[torch.Tensor]
The reparameterization scales per group.
- active_heliostats_masks_all_groupslist[torch.Tensor]
The active heliostats masks per group.
- devicetorch.device
The device on which to perform computations or load tensors and models.
- _trace_and_accumulate_flux(active_heliostats_masks_all_groups: list[torch.Tensor], target_area_indices_all_groups: list[torch.Tensor], incident_ray_directions_all_groups: list[torch.Tensor], group_offsets: torch.Tensor, device: torch.device) tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]
Ray trace all heliostat groups on this rank and accumulate the flux on the target.
Parameters
- active_heliostats_masks_all_groupslist[torch.Tensor]
The active heliostats masks per group.
- target_area_indices_all_groupslist[torch.Tensor]
The target area indices per group.
- incident_ray_directions_all_groupslist[torch.Tensor]
The incident ray directions per group.
- group_offsetstorch.Tensor
Offsets mapping group-local heliostat indices to global-flat index positions.
- devicetorch.device
The device on which to perform computations or load tensors and models.
Returns
- torch.Tensor
The accumulated flux distribution on the target.
- torch.Tensor
The intercept factors per heliostat.
- torch.Tensor
The on-target factors per heliostat.
- torch.Tensor
The blocking factors per heliostat.
- _compute_kl_constraints(flux_loss: torch.Tensor, total_flux: torch.Tensor, intercept_factors: torch.Tensor, epoch: int, flux_integral_reference: torch.Tensor | float, intercept_factors_reference: torch.Tensor | float, lambda_flux_integral: torch.Tensor | float, lambda_intercept: torch.Tensor | float, lambda_local_flux: torch.Tensor | float, rho_flux_integral: float, rho_intercept: float, rho_local_flux: float, max_flux_density_per_pixel: torch.Tensor) tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor | float, torch.Tensor | float, torch.Tensor | float, torch.Tensor | float, torch.Tensor | float]
Compute the Augmented-Lagrangian constraints and the total loss for a KL-divergence loss.
Three constraints are added: one that maximizes the flux integral, one that maximizes the intercept factor, and one that constrains the local maximum intensity. The Augmented-Lagrangian multipliers are updated and returned so that their state persists across epochs.
Parameters
- flux_losstorch.Tensor
The flux loss between predicted and target flux.
- total_fluxtorch.Tensor
The accumulated flux distribution on the target.
- intercept_factorstorch.Tensor
The intercept factors per heliostat.
- epochint
The current epoch. References are captured in the first epoch.
- flux_integral_referencetorch.Tensor | float
The reference flux integral captured in the first epoch.
- intercept_factors_referencetorch.Tensor | float
The reference intercept factors captured in the first epoch.
- lambda_flux_integraltorch.Tensor | float
The current flux integral multiplier.
- lambda_intercepttorch.Tensor | float
The current intercept multiplier.
- lambda_local_fluxtorch.Tensor | float
The current local flux multiplier.
- rho_flux_integralfloat
The penalty parameter of the flux integral constraint.
- rho_interceptfloat
The penalty parameter of the intercept constraint.
- rho_local_fluxfloat
The penalty parameter of the local flux constraint.
- max_flux_density_per_pixeltorch.Tensor
The maximum allowed flux density per pixel.
Returns
- torch.Tensor
The total loss.
- torch.Tensor
The flux integral constraint.
- torch.Tensor
The intercept factor constraint.
- torch.Tensor
The local flux constraint.
- torch.Tensor | float
The (possibly updated) reference flux integral.
- torch.Tensor | float
The (possibly updated) reference intercept factors.
- torch.Tensor | float
The updated flux integral multiplier.
- torch.Tensor | float
The updated intercept multiplier.
- torch.Tensor | float
The updated local flux multiplier.
- _synchronize_distributed_gradients(optimizer: torch.optim.Optimizer) None
Reduce and average gradients across all ranks in the global process group.
This is a no-op when not running in distributed mode.
Parameters
- optimizertorch.optim.Optimizer
The optimizer whose parameter gradients are synchronized.
- _broadcast_motor_positions() None
Broadcast the final motor positions of each heliostat group from its source rank.
This is a no-op when not running in distributed mode.
- optimize(loss_definition: artist.optim.loss.Loss, device: torch.device | None = None) tuple[torch.Tensor, dict[str, list], torch.Tensor, torch.Tensor, torch.Tensor]
Optimize the motor positions for optimal aim points.
The motor positions are optimized through a reparameterization to ensure stable training across different heliostats with widely varying initial motor positions and ranges. Motor positions can range from 0 to up to ~80000. Instead of directly optimizing the absolute motor positions, which can differ in magnitudes, an unconstrained parameter is optimized. Directly optimizing the absolute motor positions would have very different effects depending on the scale of the motors. For small initial motor positions (e.g. ~100), a gradient update of size 10 may cause a ~10% relative change, drastically altering the motor positions of this heliostat. For large initial motor positions (e.g. ~50000), the same optimizer step would correspond to only a 0.02% relative change in motor positions, effectively freezing the optimization of this heliostat. This mismatch makes it impossible to choose a single learning rate that works robustly across all heliostats. Reparameterizing the motor positions to be optimized defines the optimizable parameter as:
\[\text{motor\_positions\_optimized} = \tanh( \text{torch.nn.Parameter(optimizable\_parameter)} )\]The true motor positions can be reconstructed by:
\[\text{motor\_positions} = \text{initial\_motor\_positions} + \text{motor\_positions\_normalized} \cdot \text{scale}\]where scale defines the range (e.g. up to ~80000) for adjustments. By optimizing reparameterized instead of raw motor positions, every heliostat sees updates of comparable relative magnitude, regardless of the absolute size of its motors positions.
Parameters
- loss_definitionLoss
The definition of the loss function and pre-processing of the prediction.
- devicetorch.device | None
The device on which to perform computations or load tensors and models (default is None). If None,
ARTISTwill automatically select the most appropriate device (CUDA or CPU) based on availability and OS.
Returns
- torch.Tensor
Final loss of the aim point optimization.
- dict[str, list]
Loss history over epochs, with keys
"total_loss","flux_loss","local_flux_constraint","intercept_constraint","flux_integral_constraint", and"flux_integral". Each value is a list of per-epoch scalar floats.- torch.Tensor
Final intercept factors for each heliostat.
- torch.Tensor
Final fraction of rays hitting the target, neglecting blocking effects, for each heliostat.
- torch.Tensor
Final fraction of rays not being blocked, for each heliostat.