artist.optim.kinematics_reconstructor
Attributes
A logger for the kinematic reconstructor. |
Classes
Initialize the kinematics optimizer. |
Module Contents
- artist.optim.kinematics_reconstructor.log
A logger for the kinematic reconstructor.
- class artist.optim.kinematics_reconstructor.KinematicsReconstructor(ddp_setup: artist.util.env.DdpSetup, scenario: artist.scenario.scenario.Scenario, data: dict[str, artist.io.calibration_parser.CalibrationDataParser | list[tuple[str, list[pathlib.Path], list[pathlib.Path]]]], optimization_configuration: dict[str, Any], dni: float | None = None, reconstruction_method: str = constants.kinematics_reconstruction_raytracing, bitmap_resolution: torch.Tensor = torch.tensor([256, 256]))
Initialize the kinematics optimizer.
Parameters
- ddp_setupDdpSetup
Information about the distributed environment, process groups, devices, ranks, world size, and heliostat-group-to-ranks mapping.
- scenarioScenario
The scenario.
- datadict[str, CalibrationDataParser | list[tuple[str, list[pathlib.Path], list[pathlib.Path]]]]
The data parser and the mapping of heliostat name and calibration data.
- optimization_configurationdict[str, Any]
Parameters for the optimizer, learning rate scheduler, regularizers, and early stopping.
- dnifloat | None
Direct normal irradiance in W/m^2 (default is None which leads to a ray magnitude of 1.0).
- reconstruction_methodstr
The reconstruction method. Currently, only reconstruction via ray tracing is implemented.
- bitmap_resolutiontorch.Tensor
The resolution of all bitmaps during reconstruction (default is
torch.tensor([256, 256])). Shape is[2].
- ddp_setup
- scenario
- data
- optimizer_dict
- scheduler_dict
- dni = None
- bitmap_resolution
- validation_loss_focal_spot
- validation_loss_pixel
- validation_loss_kl_div
- reconstruct_kinematics(loss_definition: artist.optim.loss.Loss, device: torch.device | None = None) tuple[torch.Tensor, list[list[dict[str, list[float] | dict[str, torch.Tensor]]]]]
Reconstruct the kinematic parameters.
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, ARTIST will automatically select the most appropriate device (CUDA or CPU) based on availability and OS.
Returns
- torch.Tensor
The final loss of the kinematics reconstruction for each heliostat in each group. Shape is
[total_number_of_heliostats_in_scenario].- list[list[dict[str, list[float] | dict[str, torch.Tensor]]]]
Loss histories over epochs grouped by rank. Outer list: one entry per rank. Inner list: one entry per heliostat group processed on that rank. Each group entry is a dict with key
"total_loss"mapping to a list of per-epoch scalar loss values. In non-distributed mode, this is a single-rank container:[local_group_histories].
- _validate(heliostat_group: artist.field.heliostat_group.HeliostatGroup, data_split: artist.optim.training.TrainTestSplit, reduction: Callable[..., Any], device: torch.device | None = None) dict[str, torch.Tensor]
Validate the kinematic reconstruction for a specified heliostat group on the test data.
Parameters
- heliostat_groupHeliostatGroup
Heliostat group to validate.
- data_splittraining.TrainTestSplit
Train/test split containing all test tensors and metadata.
- reductionCallable[…, Any]
Reduction function applied across the sample dimension for each heliostat.
- devicetorch.device | None
The device on which to perform computations or load tensors and models (default is None). If None, ARTIST will automatically select the most appropriate device (CUDA or CPU) based on availability and OS.
Returns
- dict[str, torch.Tensor]
Test losses per sample.
- _initialize_reconstruction_bookkeeping(device: torch.device) tuple[torch.Tensor, torch.Tensor]
Initialize the per-heliostat loss container and group index offsets.
Parameters
- devicetorch.device
The device on which to perform computations or load tensors and models.
Returns
- torch.Tensor
Final loss per heliostat over all groups, initialized with positive infinity. Shape is
[total_number_of_heliostats_in_scenario].- torch.Tensor
Prefix sums mapping group-local heliostat indices to global heliostat indices. Shape is
[number_of_heliostat_groups + 1].
- _parse_group_calibration_data(heliostat_group: artist.field.heliostat_group.HeliostatGroup, device: torch.device) tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]
Load and parse the calibration data for a single heliostat group.
Parameters
- heliostat_groupHeliostatGroup
The heliostat group whose calibration data is parsed.
- devicetorch.device
The device on which to perform computations or load tensors and models.
Returns
- tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]
The measured flux, measured focal spots, incident ray directions, motor positions, active heliostats mask, and target area indices.
- _setup_optimizer_scheduler_early_stopping(heliostat_group: artist.field.heliostat_group.HeliostatGroup) tuple[torch.optim.Optimizer, torch.optim.lr_scheduler.LRScheduler, artist.optim.training.EarlyStopping]
Create the optimizer, learning rate scheduler, and early stopping for a group.
The optimizer learns the rotation deviation parameters of the group’s kinematics.
Parameters
- heliostat_groupHeliostatGroup
The heliostat group whose kinematics parameters are optimized.
Returns
- torch.optim.Optimizer
The Adam optimizer over the rotation deviation parameters.
- LRScheduler
The learning rate scheduler.
- training.EarlyStopping
The early stopping monitor.
- _compute_measured_normals(heliostat_group: artist.field.heliostat_group.HeliostatGroup, focal_spots_measured: torch.Tensor, incident_ray_directions: torch.Tensor, active_heliostats_mask: torch.Tensor, device: torch.device) torch.Tensor
Compute the measured surface normals from the measured focal spots.
The preferred reflection directions are derived from the measured focal spots and the heliostat positions and combined with the incident ray directions to obtain the normals.
Parameters
- heliostat_groupHeliostatGroup
The heliostat group whose normals are computed.
- focal_spots_measuredtorch.Tensor
The measured focal spots.
- incident_ray_directionstorch.Tensor
The incident ray directions.
- active_heliostats_masktorch.Tensor
Mask for active samples available per heliostat.
- devicetorch.device
The device on which to perform computations or load tensors and models.
Returns
- torch.Tensor
The measured normals in 4D format.
- _compute_alignment_loss(heliostat_group: artist.field.heliostat_group.HeliostatGroup, data_split: artist.optim.training.TrainTestSplit, loss_definition: artist.optim.loss.Loss, normals_measured: torch.Tensor, device: torch.device) tuple[torch.Tensor, torch.Tensor]
Compute the alignment reconstruction loss for a single epoch.
The heliostats are activated and their predicted normals are obtained from the motor positions and compared against the measured normals.
Parameters
- heliostat_groupHeliostatGroup
The heliostat group to align.
- data_splittraining.TrainTestSplit
Train/test split containing all training tensors and metadata.
- loss_definitionLoss
The definition of the loss function and pre-processing of the prediction.
- normals_measuredtorch.Tensor
The measured normals in 4D format.
- devicetorch.device
The device on which to perform computations or load tensors and models.
Returns
- torch.Tensor
The mean loss over all heliostats.
- torch.Tensor
The loss per heliostat.
- _compute_raytracing_loss(heliostat_group: artist.field.heliostat_group.HeliostatGroup, data_split: artist.optim.training.TrainTestSplit, loss_definition: artist.optim.loss.Loss, device: torch.device) tuple[torch.Tensor, torch.Tensor, torch.Tensor]
Compute the ray-tracing reconstruction loss for a single epoch.
The heliostats are activated, aligned, and ray traced to predict flux distributions which are compared against the measured flux.
Parameters
- heliostat_groupHeliostatGroup
The heliostat group to trace.
- data_splittraining.TrainTestSplit
Train/test split containing all training tensors and metadata.
- loss_definitionLoss
The definition of the loss function and pre-processing of the prediction.
- devicetorch.device
The device on which to perform computations or load tensors and models.
Returns
- torch.Tensor
The mean loss over all heliostats.
- torch.Tensor
The loss per heliostat.
- torch.Tensor
The sample indices processed on the local rank.
- _synchronize_gradients_nested_ddp(optimizer: torch.optim.Optimizer) None
Synchronize gradients within a nested heliostat-group subgroup.
In nested distributed data parallel mode the gradients are summed across the ranks that process the same heliostat group and then averaged. This is a no-op when not nested.
Parameters
- optimizertorch.optim.Optimizer
The optimizer whose parameter gradients are synchronized.
- _synchronize_reconstruction_across_ranks(final_loss_per_heliostat: torch.Tensor, loss_history: list[dict[str, list[float] | dict[str, torch.Tensor]]]) list[list[dict[str, list[float] | dict[str, torch.Tensor]]]]
Synchronize the reconstruction results across all distributed ranks.
Broadcasts the reconstructed kinematics parameters, reduces the final loss to its minimum across ranks, and gathers the loss histories of all ranks.
Parameters
- final_loss_per_heliostattorch.Tensor
The final loss per heliostat on the local rank. Shape is
[total_number_of_heliostats_in_scenario].- loss_historylist[dict[str, list[float] | dict[str, torch.Tensor]]]
The local rank’s loss histories per heliostat group.
Returns
- list[list[dict[str, list[float] | dict[str, torch.Tensor]]]]
Loss histories grouped by rank.
- _reconstruct_kinematics_alignment_driven(loss_definition: artist.optim.loss.Loss, device: torch.device | None = None) tuple[torch.Tensor, list[list[dict[str, list[float] | dict[str, torch.Tensor]]]]]
Reconstruct the kinematics parameters using alignment and geometry data.
This reconstruction method optimizes the kinematics parameters by iteratively aligning heliostats to reach a defined flux focal spot.
Parameters
- loss_definitionLoss
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, ARTIST will automatically select the most appropriate device (CUDA or CPU) based on availability and OS.
Returns
- torch.Tensor
The final loss of the kinematics reconstruction for each heliostat in each group. Shape is
[total_number_of_heliostats_in_scenario].- list[list[dict[str, list[float] | dict[str, torch.Tensor]]]]
Loss histories over epochs grouped by rank. Outer list: one entry per rank. Inner list: one entry per heliostat group processed on that rank. Each group entry is a dict with key
"total_loss"mapping to a list of per-epoch scalar loss values. In non-distributed mode, this is a single-rank container:[local_group_histories].
- _reconstruct_kinematics_flux_driven(loss_definition: artist.optim.loss.Loss, device: torch.device | None = None) tuple[torch.Tensor, list[list[dict[str, list[float] | dict[str, torch.Tensor]]]]]
Reconstruct the kinematics parameters using ray tracing and comparing fluxes.
This reconstruction method optimizes the kinematics parameters by extracting the focal points of calibration images and using heliostat-tracing.
Parameters
- loss_definitionLoss
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, ARTIST will automatically select the most appropriate device (CUDA or CPU) based on availability and OS.
Returns
- torch.Tensor
The final loss of the kinematics reconstruction for each heliostat in each group. Shape is
[total_number_of_heliostats_in_scenario].- list[list[dict[str, list[float] | dict[str, torch.Tensor]]]]
Loss histories over epochs grouped by rank. Outer list: one entry per rank. Inner list: one entry per heliostat group processed on that rank. Each group entry is a dict with key
"total_loss"mapping to a list of per-epoch scalar loss values. In non-distributed mode, this is a single-rank container:[local_group_histories].