@@ -302,7 +302,7 @@ float PlacementAnnealer::estimate_starting_temperature_() {
302302 switch (placer_opts_.anneal_init_t_estimator ) {
303303 case e_anneal_init_t_estimator::COST_VARIANCE:
304304 return estimate_starting_temp_using_cost_variance_ ();
305- case e_anneal_init_t_estimator::EQUILIBRIUM_EST :
305+ case e_anneal_init_t_estimator::EQUILIBRIUM :
306306 return estimate_equilibrium_temp_ ();
307307 default :
308308 VPR_FATAL_ERROR (VPR_ERROR_PLACE,
@@ -328,18 +328,9 @@ float PlacementAnnealer::estimate_equilibrium_temp_() {
328328 accepted_swaps.reserve (move_lim);
329329 rejected_swaps.reserve (move_lim);
330330 for (int i = 0 ; i < move_lim; i++) {
331- bool manual_move_enabled = false ;
332- #ifndef NO_GRAPHICS
333- // Checks manual move flag for manual move feature
334- t_draw_state* draw_state = get_draw_state_vars ();
335- if (draw_state->show_graphics ) {
336- manual_move_enabled = manual_move_is_selected ();
337- }
338- #endif /* NO_GRAPHICS*/
339-
340331 t_swap_result swap_result = try_swap_ (*move_generator_1_,
341332 placer_opts_.place_algorithm ,
342- manual_move_enabled);
333+ false /* manual_move_enabled*/ );
343334
344335 if (swap_result.move_result == e_move_result::ACCEPTED) {
345336 accepted_swaps.push_back (swap_result.delta_c );
@@ -361,6 +352,14 @@ float PlacementAnnealer::estimate_equilibrium_temp_() {
361352 total_accepted_cost += accepted_cost;
362353 }
363354
355+ // Find the magnitude of the largest reject swap cost. This is useful for
356+ // picking a worst-case initial temperature.
357+ double max_rejected_swap_cost = 0.0 ;
358+ for (double rejected_cost : rejected_swaps) {
359+ max_rejected_swap_cost = std::max (max_rejected_swap_cost,
360+ std::abs (rejected_cost));
361+ }
362+
364363 // Perform a binary search to try and find the equilibrium temperature for
365364 // this placement. This is the temperature that we expect would lead to no
366365 // overall change in temperature. We do this by computing the expected
@@ -372,43 +371,46 @@ float PlacementAnnealer::estimate_equilibrium_temp_() {
372371 // Initialize the lower bound temperature to 0. The temperature cannot
373372 // be less than 0.
374373 double lower_bound_temp = 0.0 ;
375- // Initialize the upper bound temperature to 1e10 . It is possible for
374+ // Initialize the upper bound temperature. It is possible for
376375 // the equilibrium temperature to be infinite if the initial placement
377376 // is so bad that no swaps are accepted. In that case this value will
378377 // be returned instead of infinity.
379- // TODO: Find what a reasonable value for this should be.
380- double upper_bound_temp = 1e10 ;
378+ // At this temperature, the probability of accepting this worst rejected
379+ // swap would be 71.655% (e^(-1/3)).
380+ // TODO: Investigate if this is a good initial temperature for these
381+ // cases.
382+ double upper_bound_temp = 3.0 * max_rejected_swap_cost;
381383 // The max search iterations should never be hit, but it is here as an
382384 // exit condition to prevent infinite loops.
383385 constexpr unsigned max_search_iters = 100 ;
384386 for (unsigned binary_search_iter = 0 ; binary_search_iter < max_search_iters; binary_search_iter++) {
385387 // Exit condition for binary search. Could be hit if the lower and upper
386388 // bounds are arbitrarily close.
387- if (lower_bound_temp > upper_bound_temp)
389+ if (lower_bound_temp >= upper_bound_temp)
388390 break ;
389391
390392 // Try the temperature in the middle of the lower and upper bounds.
391393 double trial_temp = (lower_bound_temp + upper_bound_temp) / 2.0 ;
392394
395+ // Return the trial temperature if it is within 6 decimal-points of precision.
396+ // NOTE: This is arbitrary.
397+ // TODO: We could stop this early and then use Newton's Method to quickly
398+ // touch it up to a more accurate value.
399+ if (std::abs (upper_bound_temp - lower_bound_temp) / trial_temp < 1e-6 )
400+ return trial_temp;
401+
393402 // Calculate the expected change in cost at this temperature (which we
394403 // call the residual here).
395404 double expected_total_post_rejected_cost = 0.0 ;
396405 for (double rejected_cost : rejected_swaps) {
397406 // Expected change in cost after a rejected swap is the change in
398407 // cost multiplied by the probability that this swap is accepted at
399408 // this temperature.
400- double accpetance_prob = std::exp ((-1.0 * rejected_cost) / trial_temp);
401- expected_total_post_rejected_cost += rejected_cost * accpetance_prob ;
409+ double acceptance_prob = std::exp ((-1.0 * rejected_cost) / trial_temp);
410+ expected_total_post_rejected_cost += rejected_cost * acceptance_prob ;
402411 }
403412 double residual = expected_total_post_rejected_cost + total_accepted_cost;
404413
405- // Return the trial temperature if it is within 6 decimal-points of precision.
406- // NOTE: This is arbitrary.
407- // TODO: We could stop this early and then use Newton's Method to quickly
408- // touch it up to a more accurate value.
409- if (std::abs (upper_bound_temp - lower_bound_temp) / trial_temp < 1e-6 )
410- return trial_temp;
411-
412414 if (residual < 0 ) {
413415 // Since the function is monotonically increasing, if the residual
414416 // is negative, then the lower bound should be raised to the trial
0 commit comments