artist.optim.surface_reconstructor
Attributes
A logger for the surface reconstructor. |
Classes
Initialize the surface reconstructor. |
Module Contents
- artist.optim.surface_reconstructor.log
A logger for the surface reconstructor.
- class artist.optim.surface_reconstructor.SurfaceReconstructor(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, number_of_surface_points: torch.Tensor = torch.tensor([50, 50]), bitmap_resolution: torch.Tensor = torch.tensor([256, 256]), epsilon: float | None = 1e-12, plot_results: bool = False, device: torch.device | None = None)
Initialize the surface reconstructor.
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]
The parameters for the optimizer, learning rate scheduler, early stopping, and constraints.
- dnifloat | None
Direct normal irradiance in W/m² used to scale the ray-traced flux (default is None). If None, the
HeliostatRayTraceruses its own default.- number_of_surface_pointstorch.Tensor
The number of surface points of the reconstructed surfaces (default is
torch.tensor([50, 50])). Shape is[2].- bitmap_resolutiontorch.Tensor
The resolution of all bitmaps during reconstruction (default is
torch.tensor([256, 256])). Shape is[2].- epsilonfloat | None
Small numerical offset used to avoid division by zero in the energy constraint (default is 1e-12).
- plot_resultsbool
Create flux plots in the last epoch of training for each heliostat and all its samples (slow!, default is
False).- 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
- data
- optimizer_dict
- scheduler_dict
- constraint_dict
- number_of_surface_points
- dni = None
- bitmap_resolution
- epsilon = 1e-12
- plot_results = False
- validation_loss_pixel
- validation_loss_kl_div
- _validate(heliostat_group: artist.field.heliostat_group.HeliostatGroup, data_split: artist.optim.training.TrainTestSplit, evaluation_points: torch.Tensor, device: torch.device | None = None) dict[str, torch.Tensor]
Validate the surface reconstruction for a specified heliostat group on the test data.
This validates a surface reconstruction (NURBS-based mirror surface shape + alignment) for a given heliostat group on the test set:
It builds NURBS surfaces from control points.
Samples surface points and normals.
Aligns those surfaces to incident rays and aim points.
Runs ray tracing to predict flux on the receiver.
Compares predicted vs measured flux for the test samples and computes several test losses.
It returns the predicted flux images (for the local rank’s test samples) and a dict with per‑heliostat test losses (pixel loss and KL divergence).
Parameters
- heliostat_groupHeliostatGroup
Heliostat group to validate.
- data_splittraining.TrainTestSplit
Train/test split containing all test tensors and metadata.
- evaluation_pointstorch.Tensor
Evaluation points for the NURBS surface sampling.
- 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.
- _create_evaluation_grid_and_reference_points(heliostat_group: artist.field.heliostat_group.HeliostatGroup, active_heliostats_mask: torch.Tensor, device: torch.device) tuple[torch.Tensor, torch.Tensor]
Create the NURBS evaluation grid and a frozen copy of the control points.
Parameters
- heliostat_groupHeliostatGroup
The heliostat group whose surfaces are reconstructed.
- 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 evaluation points for the NURBS surface sampling.
- torch.Tensor
A frozen copy of the original control points used by the regularizers.
- _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 NURBS control points of the group’s surfaces.
Parameters
- heliostat_groupHeliostatGroup
The heliostat group whose surfaces are reconstructed.
Returns
- torch.optim.Optimizer
The Adam optimizer over the NURBS control points.
- LRScheduler
The learning rate scheduler.
- training.EarlyStopping
The early stopping monitor.
- _predict_flux(heliostat_group: artist.field.heliostat_group.HeliostatGroup, evaluation_points: torch.Tensor, data_split: artist.optim.training.TrainTestSplit, device: torch.device) tuple[torch.Tensor, torch.Tensor, torch.Tensor]
Predict the cropped flux distributions for the training samples of one epoch.
The current NURBS surfaces are built and sampled, aligned toward the targets, ray traced, and the resulting flux distributions are cropped around their center.
Parameters
- heliostat_groupHeliostatGroup
The heliostat group to reconstruct.
- evaluation_pointstorch.Tensor
Evaluation points for the NURBS surface sampling.
- data_splittraining.TrainTestSplit
Train/test split containing all training tensors and metadata.
- devicetorch.device
The device on which to perform computations or load tensors and models.
Returns
- torch.Tensor
The cropped predicted flux distributions of the training samples.
- torch.Tensor
The sample indices processed on the local rank.
- torch.Tensor
The local heliostat indices processed on the local rank.
- _compute_flux_integral_constraint(cropped_flux_predictions: torch.Tensor, flux_integrals_reference: torch.Tensor, lambda_flux_integral: torch.Tensor | float, rho_flux_integral: float, energy_tolerance: float, data_split: artist.optim.training.TrainTestSplit) tuple[torch.Tensor, torch.Tensor, torch.Tensor]
Compute the Augmented-Lagrangian flux integral constraint.
The constraint ensures that the flux integral is conserved, i.e., intensity does not get lost relative to the reference captured in the first epoch.
Parameters
- cropped_flux_predictionstorch.Tensor
The cropped predicted flux distributions of the training samples.
- flux_integrals_referencetorch.Tensor
The reference flux integrals captured in the first epoch.
- lambda_flux_integraltorch.Tensor | float
The current Augmented-Lagrangian multiplier.
- rho_flux_integralfloat
The penalty parameter of the constraint.
- energy_tolerancefloat
The tolerance below which the flux integral may drop without penalty.
- data_splittraining.TrainTestSplit
Train/test split containing all training tensors and metadata.
Returns
- torch.Tensor
The flux integral constraint per heliostat.
- torch.Tensor
The relative differences of the flux integrals per sample.
- torch.Tensor
The clamped flux constraint per heliostat.
- _compute_regularization_terms(heliostat_group: artist.field.heliostat_group.HeliostatGroup, original_control_points: torch.Tensor, local_indices: torch.Tensor, data_split: artist.optim.training.TrainTestSplit, flux_loss_per_heliostat: torch.Tensor, smoothness_regularizer: artist.optim.regularizers.SmoothnessRegularizer, ideal_surface_regularizer: artist.optim.regularizers.IdealSurfaceRegularizer, weight_smoothness: float, weight_ideal_surface: float, device: torch.device) tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]
Compute the smoothness and ideal-surface regularization terms.
The regularizers keep the reconstructed surface smooth and close to the ideal/original surface. Their magnitudes are dynamically balanced relative to the data term.
Parameters
- heliostat_groupHeliostatGroup
The heliostat group whose surfaces are reconstructed.
- original_control_pointstorch.Tensor
A frozen copy of the original control points.
- local_indicestorch.Tensor
The local heliostat indices processed on the local rank.
- data_splittraining.TrainTestSplit
Train/test split containing all training tensors and metadata.
- flux_loss_per_heliostattorch.Tensor
The flux loss per heliostat used for the dynamic balancing.
- smoothness_regularizerSmoothnessRegularizer
The smoothness regularizer.
- ideal_surface_regularizerIdealSurfaceRegularizer
The ideal-surface regularizer.
- weight_smoothnessfloat
The weight of the smoothness regularizer.
- weight_ideal_surfacefloat
The weight of the ideal-surface regularizer.
- devicetorch.device
The device on which to perform computations or load tensors and models.
Returns
- torch.Tensor
The dynamic balancing factor
alphafor the smoothness term.- torch.Tensor
The smoothness loss per heliostat.
- torch.Tensor
The dynamic balancing factor
betafor the ideal-surface term.- torch.Tensor
The ideal-surface loss per heliostat.
- _synchronize_and_lock_gradients(optimizer: torch.optim.Optimizer, device: torch.device) None
Synchronize gradients in nested-DDP mode and lock outer-edge control points.
In nested distributed data parallel mode the gradients are averaged across the ranks that process the same heliostat group. The gradients of the outer-edge control points are then zeroed to preserve the rectangular surface shape.
Parameters
- optimizertorch.optim.Optimizer
The optimizer whose parameter gradients are synchronized and locked.
- devicetorch.device
The device on which to perform computations or load tensors and models.
- _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 NURBS control points, 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_surfaces(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 NURBS surfaces from bitmaps.
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
The final reconstruction loss per heliostat, one entry per heliostat in the scenario. 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 keys:
"total_loss","flux_loss","smoothness_regularizer","ideal_regularizer","flux_integral", and"flux_integral_constraint". Each value is a list of per-epoch scalar floats.In non-distributed mode, this is a single-rank container:
[local_group_histories].
- static lock_control_points_on_outer_edges(gradients: torch.Tensor, device: torch.device | None = None) torch.Tensor
Lock the u and v values of the control points on the outer edges of each facet.
As the knots of the first and last knots on each facet have full multiplicity, the NURBS surfaces all start and end in control points. If the outer control points are not fixed in their u and v values, the reconstructed surfaces may not be rectangular anymore. To keep them rectangular, this function zeros the gradients of the u and v coordinates of all outer control points.
Parameters
- gradientstorch.Tensor
The full control point gradient tensor for all active heliostats. Gradients on the outer edges will be zeroed; interior gradients are returned unchanged. Shape is
[number_of_active_heliostats, number_of_facets_per_surface, number_of_control_points_u_direction, number_of_control_points_v_direction, 3].- 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
The updated gradients. Shape is
[number_of_active_heliostats, number_of_facets_per_surface, number_of_control_points_u_direction, number_of_control_points_v_direction, 3].