Skip to content

Commit

Permalink
Merge pull request #61 from polyfem/better-logging
Browse files Browse the repository at this point in the history
better logging
  • Loading branch information
teseoch authored Dec 13, 2023
2 parents 374f787 + f347cf9 commit eed521e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/polysolve/nonlinear/Solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ namespace polysolve::nonlinear
stop_watch.start();

m_logger.debug(
"Starting {} with {} solve f₀={:g} ‖∇f₀‖={:g} "
"Starting {} with {} solve f₀={:g} "
"(stopping criteria: max_iters={:d} Δf={:g} ‖∇f‖={:g} ‖Δx‖={:g})",
descent_strategy_name(), m_line_search->name(),
objFunc.value(x), this->m_current.gradNorm, this->m_stop.iterations,
objFunc.value(x), this->m_stop.iterations,
this->m_stop.fDelta, this->m_stop.gradNorm, this->m_stop.xDelta);

update_solver_info(objFunc.value(x));
Expand All @@ -294,6 +294,9 @@ namespace polysolve::nonlinear
int f_delta_step_cnt = 0;
double f_delta = 0;

// Used for logging
double xDelta = 0, gradNorm = 0;

do
{
m_line_search->set_is_final_strategy(m_descent_strategy == m_strategies.size() - 1);
Expand Down Expand Up @@ -340,7 +343,10 @@ namespace polysolve::nonlinear
log_and_throw_error(m_logger, "[{}][{}] Gradient is nan; stopping", descent_strategy_name(), m_line_search->name());
break;
}

this->m_current.gradNorm = grad_norm;
gradNorm = this->m_current.gradNorm;

this->m_status = checkConvergence(this->m_stop, this->m_current);
if (this->m_status != cppoptlib::Status::Continue)
break;
Expand Down Expand Up @@ -396,6 +402,7 @@ namespace polysolve::nonlinear

// Use the maximum absolute displacement value divided by the timestep,
this->m_current.xDelta = delta_x_norm;
xDelta = this->m_current.xDelta;
this->m_status = checkConvergence(this->m_stop, this->m_current);
if (this->m_status != cppoptlib::Status::Continue)
break;
Expand All @@ -404,6 +411,11 @@ namespace polysolve::nonlinear
// Variable update
// ---------------

m_logger.trace(
"[{}][{}] pre LS iter={:d} f={:g} ‖∇f‖={:g}",
descent_strategy_name(), m_line_search->name(),
this->m_current.iterations, energy, gradNorm);

// Perform a line_search to compute step scale
double rate = m_line_search->line_search(x, delta_x, objFunc);
if (std::isnan(rate))
Expand Down Expand Up @@ -473,7 +485,7 @@ namespace polysolve::nonlinear
" (stopping criteria: max_iters={:d} Δf={:g} ‖∇f‖={:g} ‖Δx‖={:g})",
descent_strategy_name(), m_line_search->name(),
this->m_current.iterations, energy, f_delta,
this->m_current.gradNorm, this->m_current.xDelta, delta_x.dot(grad), rate, step,
gradNorm, xDelta, delta_x.dot(grad), rate, step,
this->m_stop.iterations, this->m_stop.fDelta, this->m_stop.gradNorm, this->m_stop.xDelta);

if (++this->m_current.iterations >= this->m_stop.iterations)
Expand Down Expand Up @@ -502,7 +514,7 @@ namespace polysolve::nonlinear
" (stopping criteria: max_iters={:d} Δf={:g} ‖∇f‖={:g} ‖Δx‖={:g})",
descent_strategy_name(), m_line_search->name(),
this->m_status, tot_time, this->m_current.iterations,
old_energy, f_delta, this->m_current.gradNorm, this->m_current.xDelta,
old_energy, f_delta, gradNorm, xDelta,
this->m_stop.iterations, this->m_stop.fDelta, this->m_stop.gradNorm, this->m_stop.xDelta);

log_times();
Expand Down

0 comments on commit eed521e

Please sign in to comment.