Skip to content

Rescaled tolerances#93

Merged
maxpaik16 merged 30 commits intopolyfem:mainfrom
maxpaik16:rescaled-tolerances
Apr 15, 2026
Merged

Rescaled tolerances#93
maxpaik16 merged 30 commits intopolyfem:mainfrom
maxpaik16:rescaled-tolerances

Conversation

@maxpaik16
Copy link
Copy Markdown
Contributor

Added functions to nonlinear Problem class to allow user-specified norms with appropriate rescaling functions

Updated nonlinear solver and line search logic to use these norms and custom rescalings

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 78.94737% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.46%. Comparing base (5d62b80) to head (65fe6a6).
⚠️ Report is 31 commits behind head on main.

Files with missing lines Patch % Lines
src/polysolve/nonlinear/Solver.cpp 73.68% 15 Missing ⚠️
src/polysolve/nonlinear/Criteria.cpp 72.22% 5 Missing ⚠️
src/polysolve/linear/AMGCL.hpp 0.00% 1 Missing ⚠️
src/polysolve/linear/EigenSolver.hpp 0.00% 1 Missing ⚠️
src/polysolve/linear/HypreSolver.hpp 0.00% 1 Missing ⚠️
src/polysolve/linear/Solver.hpp 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #93      +/-   ##
==========================================
- Coverage   81.67%   81.46%   -0.21%     
==========================================
  Files          49       49              
  Lines        2025     2083      +58     
  Branches      269      274       +5     
==========================================
+ Hits         1654     1697      +43     
- Misses        371      386      +15     
Flag Coverage Δ
polysolve 81.46% <78.94%> (-0.21%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/polysolve/nonlinear/Solver.hpp Outdated

virtual double compute_grad_norm(const Problem &objFunc, const TVector &x, const TVector &grad) const
{
return objFunc.grad_norm(grad, norm_type_);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so. Is there an issue I am overlooking?

default_init_step_size = params["line_search"]["default_init_step_size"];
step_ratio = params["line_search"]["step_ratio"];

try_interpolating_step = params["line_search"]["try_interpolating_step"];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why adding if not implemented?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted

Comment thread src/polysolve/nonlinear/Problem.hpp Outdated
virtual double step_norm_rescaling(const std::string &norm_type) const {return 1;}
virtual double energy_norm_rescaling(const std::string &norm_type) const {return 1;}

virtual double grad_norm(const TVector &x, const std::string &norm_type) const {return x.norm();}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is super misleading. x is the solution, now it is the grad. which one is it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread src/polysolve/nonlinear/Problem.hpp Outdated
/// @return True if the solver should stop, false otherwise.
virtual bool stop(const TVector &x) { return false; }

virtual double grad_norm_rescaling(const std::string &norm_type) const {return 1;}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string? enum?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed. I use an enum now. It feels a bit awkward as it seems like something that would be more natural to define in the code defining the problem completely (e.g., PolyFEM), but I don't see a better solution at the moment.

double grad_norm_rescaling = 1;
bool try_interpolating_step;
double rel_interpolation_accuracy_tol = 0;
std::string norm_type = "Euclidean";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where are these set?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solver::set_line_search

Comment thread src/polysolve/nonlinear/Criteria.cpp
Comment thread src/polysolve/nonlinear/Solver.cpp Outdated

m_descent_strategy = 0;

norm_type_ = solver_params["norm_type"];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the style here is m_

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread nonlinear-solver-spec.json
{
m_logger.debug("[{}] large (or nan) linear solve residual {}>{} (‖∇f‖={})",
name(), residual, residual_tolerance * characteristic_length, grad.norm());
name(), residual, current_residual_tolerance, objFunc.grad_norm(grad, "L2"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L2 hardcoded

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread src/polysolve/nonlinear/Problem.hpp Outdated
virtual double step_norm_rescaling(const std::string &norm_type) const {return 1;}
virtual double energy_norm_rescaling(const std::string &norm_type) const {return 1;}

virtual double grad_norm(const TVector &x, const std::string &norm_type) const {return x.norm();}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also why is the problem resposible for this?

@maxpaik16 maxpaik16 force-pushed the rescaled-tolerances branch from cbedb97 to f842fd4 Compare March 14, 2026 19:19
// Solve the linear system Ax = b
virtual void solve(const Ref<const VectorXd> b, Ref<VectorXd> x) override;

virtual void set_tolerance(const double tol) override {residual_error_ = tol;}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

enum class NormType
{
EUCLIDEAN = 0,
L2 = 1,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe but is this energy norm, right?

Comment thread src/polysolve/nonlinear/Solver.cpp Outdated

try
{
THessian hessian;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really expensive, we compute the Hessian twice every time?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and what if there is not hessian?

Copy link
Copy Markdown
Member

@teseoch teseoch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a comment left. still not happy with the norm computation in the problem

@maxpaik16 maxpaik16 merged commit 47dc48d into polyfem:main Apr 15, 2026
9 checks passed
@maxpaik16 maxpaik16 deleted the rescaled-tolerances branch April 15, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants