@@ -67,6 +67,7 @@ def __init__(
6767 optimization_configuration : dict [str , Any ],
6868 dni : float | None = None ,
6969 reconstruction_method : str = config_dictionary .kinematics_reconstruction_raytracing ,
70+ bitmap_resolution : torch .Tensor = torch .tensor ([256 , 256 ]),
7071 ) -> None :
7172 """
7273 Initialize the kinematics optimizer.
@@ -86,6 +87,9 @@ def __init__(
8687 Direct normal irradiance in W/m^2 (default is None which leads to a ray magnitude of 1.0).
8788 reconstruction_method : str
8889 The reconstruction method. Currently, only reconstruction via ray tracing is implemented.
90+ bitmap_resolution : torch.Tensor
91+ The resolution of all bitmaps during reconstruction (default is ``torch.tensor([256, 256])``).
92+ Shape is ``[2]``.
8993 """
9094 rank = ddp_setup ["rank" ]
9195 if rank == 0 :
@@ -97,6 +101,7 @@ def __init__(
97101 self .optimizer_dict = optimization_configuration [config_dictionary .optimization ]
98102 self .scheduler_dict = optimization_configuration [config_dictionary .scheduler ]
99103 self .dni = dni
104+ self .bitmap_resolution = bitmap_resolution
100105
101106 if reconstruction_method in [
102107 config_dictionary .kinematics_reconstruction_raytracing ,
@@ -240,6 +245,7 @@ def _reconstruct_kinematics_parameters_with_raytracing(
240245 heliostat_data_mapping = heliostat_mapping ,
241246 heliostat_group = heliostat_group ,
242247 scenario = self .scenario ,
248+ bitmap_resolution = self .bitmap_resolution ,
243249 device = device ,
244250 )
245251
@@ -250,7 +256,7 @@ def _reconstruct_kinematics_parameters_with_raytracing(
250256 )
251257 focal_spots_measured = utils .bitmap_coordinates_to_target_coordinates (
252258 bitmap_coordinates = focal_spots_bitmap_coordinates ,
253- bitmap_resolution = torch . tensor ([ 256 , 256 ], device = device ) ,
259+ bitmap_resolution = self . bitmap_resolution ,
254260 solar_tower = self .scenario .solar_tower ,
255261 target_area_indices = target_area_indices ,
256262 device = device ,
@@ -260,70 +266,79 @@ def _reconstruct_kinematics_parameters_with_raytracing(
260266 initial_actuator_params = (
261267 heliostat_group .kinematics .actuators .optimizable_parameters .detach ()
262268 )
263-
264- angle_mean = initial_actuator_params [
265- :, index_mapping .actuator_params_initial_angle
266- ].mean ()
267- angle_std = (
268- initial_actuator_params [
269+ if initial_actuator_params is not None :
270+ angle_mean = initial_actuator_params [
269271 :, index_mapping .actuator_params_initial_angle
270- ]
271- .std ()
272- .clamp (min = 1e-3 )
273- )
272+ ].mean ()
273+ angle_std = (
274+ initial_actuator_params [
275+ :, index_mapping .actuator_params_initial_angle
276+ ]
277+ .std ()
278+ .clamp (min = 1e-3 )
279+ )
274280
275- stroke_mean = initial_actuator_params [
276- :, index_mapping .actuator_params_initial_stroke_length
277- ].mean ()
278- stroke_std = (
279- initial_actuator_params [
281+ stroke_mean = initial_actuator_params [
280282 :, index_mapping .actuator_params_initial_stroke_length
281- ]
282- .std ()
283- .clamp (min = 1e-3 )
284- )
285-
286- angle_normalized = (
287- initial_actuator_params [
288- :, index_mapping .actuator_params_initial_angle
289- ]
290- - angle_mean
291- ) / angle_std
292- stroke_length_normalized = (
293- initial_actuator_params [
294- :, index_mapping .actuator_params_initial_stroke_length
295- ]
296- - stroke_mean
297- ) / stroke_std
283+ ].mean ()
284+ stroke_std = (
285+ initial_actuator_params [
286+ :, index_mapping .actuator_params_initial_stroke_length
287+ ]
288+ .std ()
289+ .clamp (min = 1e-3 )
290+ )
298291
299- delta_angle = torch .zeros_like (angle_normalized , requires_grad = True )
300- delta_stroke = torch .zeros_like (
301- stroke_length_normalized , requires_grad = True
302- )
292+ angle_normalized = (
293+ initial_actuator_params [
294+ :, index_mapping .actuator_params_initial_angle
295+ ]
296+ - angle_mean
297+ ) / angle_std
298+ stroke_length_normalized = (
299+ initial_actuator_params [
300+ :, index_mapping .actuator_params_initial_stroke_length
301+ ]
302+ - stroke_mean
303+ ) / stroke_std
304+
305+ delta_angle = torch .zeros_like (angle_normalized , requires_grad = True )
306+ delta_stroke = torch .zeros_like (
307+ stroke_length_normalized , requires_grad = True
308+ )
309+ else :
310+ delta_angle = None
311+ delta_stroke = None
303312
304313 # Set up optimizer, scheduler, and early stopping.
305- optimizer = torch .optim .Adam (
306- [
307- {
308- "params" : heliostat_group .kinematics .rotation_deviation_parameters .requires_grad_ (),
309- "lr" : self .optimizer_dict [
310- config_dictionary .initial_learning_rate_rotation_deviation
311- ],
312- },
313- {
314- "params" : delta_angle ,
315- "lr" : self .optimizer_dict [
316- config_dictionary .initial_learning_rate_initial_angles
317- ],
318- },
319- {
320- "params" : delta_stroke ,
321- "lr" : self .optimizer_dict [
322- config_dictionary .initial_learning_rate_initial_stroke_length
323- ],
324- },
325- ]
326- )
314+ optimizer_params = [
315+ {
316+ "params" : heliostat_group .kinematics .rotation_deviation_parameters .requires_grad_ (),
317+ "lr" : self .optimizer_dict [
318+ config_dictionary .initial_learning_rate_rotation_deviation
319+ ],
320+ }
321+ ]
322+
323+ if initial_actuator_params is not None :
324+ optimizer_params .extend (
325+ [
326+ {
327+ "params" : delta_angle ,
328+ "lr" : self .optimizer_dict [
329+ config_dictionary .initial_learning_rate_initial_angles
330+ ],
331+ },
332+ {
333+ "params" : delta_stroke ,
334+ "lr" : self .optimizer_dict [
335+ config_dictionary .initial_learning_rate_initial_stroke_length
336+ ],
337+ },
338+ ]
339+ )
340+
341+ optimizer = torch .optim .Adam (optimizer_params )
327342
328343 # Create a learning rate scheduler.
329344 scheduler_fn = getattr (
@@ -408,6 +423,7 @@ def _reconstruct_kinematics_parameters_with_raytracing(
408423 batch_size = self .optimizer_dict [config_dictionary .batch_size ],
409424 random_seed = self .ddp_setup ["heliostat_group_rank" ],
410425 dni = self .dni ,
426+ bitmap_resolution = self .bitmap_resolution ,
411427 )
412428
413429 # Perform heliostat-based ray tracing.
0 commit comments