Skip to content

Commit 374f787

Browse files
author
teseoch
authored
Merge pull request #60 from polyfem/custom-fallback
Custom fallback
2 parents b08ab23 + efd79f7 commit 374f787

File tree

14 files changed

+559
-122
lines changed

14 files changed

+559
-122
lines changed

nonlinear-solver-spec.json

Lines changed: 284 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
[{
1+
[
2+
{
23
"pointer": "/",
34
"default": null,
45
"type": "object",
@@ -11,8 +12,8 @@
1112
"iterations_per_strategy",
1213
"line_search",
1314
"allow_out_of_iterations",
14-
"LBFGS",
15-
"LBFGSB",
15+
"L-BFGS",
16+
"L-BFGS-B",
1617
"Newton",
1718
"ADAM",
1819
"StochasticADAM",
@@ -90,7 +91,7 @@
9091
"doc": "If false (default), an exception will be thrown when the nonlinear solver reaches the maximum number of iterations."
9192
},
9293
{
93-
"pointer": "/LBFGS",
94+
"pointer": "/L-BFGS",
9495
"default": null,
9596
"type": "object",
9697
"optional": [
@@ -99,22 +100,22 @@
99100
"doc": "Options for LBFGS."
100101
},
101102
{
102-
"pointer": "/LBFGS/history_size",
103+
"pointer": "/L-BFGS/history_size",
103104
"default": 6,
104105
"type": "int",
105106
"doc": "The number of corrections to approximate the inverse Hessian matrix."
106107
},
107108
{
108-
"pointer": "/LBFGSB",
109+
"pointer": "/L-BFGS-B",
109110
"default": null,
110111
"type": "object",
111112
"optional": [
112113
"history_size"
113114
],
114-
"doc": "Options for the boxed LBFGS."
115+
"doc": "Options for the boxed L-BFGS."
115116
},
116117
{
117-
"pointer": "/LBFGSB/history_size",
118+
"pointer": "/L-BFGS-B/history_size",
118119
"default": 6,
119120
"type": "int",
120121
"doc": "The number of corrections to approximate the inverse Hessian matrix."
@@ -129,7 +130,8 @@
129130
"reg_weight_max",
130131
"reg_weight_inc",
131132
"force_psd_projection",
132-
"use_psd_projection"
133+
"use_psd_projection",
134+
"use_psd_projection_in_regularized"
133135
],
134136
"doc": "Options for Newton."
135137
},
@@ -169,6 +171,12 @@
169171
"type": "bool",
170172
"doc": "Use PSD as fallback using second order solvers (i.e., Newton's method)."
171173
},
174+
{
175+
"pointer": "/Newton/use_psd_projection_in_regularized",
176+
"default": true,
177+
"type": "bool",
178+
"doc": "Use PSD in regularized Newton."
179+
},
172180
{
173181
"pointer": "/ADAM",
174182
"default": null,
@@ -263,6 +271,273 @@
263271
"type": "float",
264272
"doc": "Probability of erasing a component on the gradient for StochasticGradientDescent."
265273
},
274+
{
275+
"pointer": "/solver",
276+
"type": "list",
277+
"doc": "List of solvers for ballback. Eg, [{'type':'Newton'}, {'type':'L-BFGS'}, {'type':'GradientDescent'}] will solve using Newton, in case of failure will fallback to L-BFGS and eventually to GradientDescent"
278+
},
279+
{
280+
"pointer": "/solver/*",
281+
"type": "object",
282+
"type_name": "Newton",
283+
"required": [
284+
"type"
285+
],
286+
"optional": [
287+
"residual_tolerance"
288+
],
289+
"doc": "Options for Newton."
290+
},
291+
{
292+
"pointer": "/solver/*",
293+
"type": "object",
294+
"type_name": "ProjectedNewton",
295+
"required": [
296+
"type"
297+
],
298+
"optional": [
299+
"residual_tolerance"
300+
],
301+
"doc": "Options for projected Newton."
302+
},
303+
{
304+
"pointer": "/solver/*",
305+
"type": "object",
306+
"type_name": "RegularizedNewton",
307+
"required": [
308+
"type"
309+
],
310+
"optional": [
311+
"residual_tolerance",
312+
"reg_weight_min",
313+
"reg_weight_max",
314+
"reg_weight_inc"
315+
],
316+
"doc": "Options for regularized Newton."
317+
},
318+
{
319+
"pointer": "/solver/*",
320+
"type": "object",
321+
"type_name": "RegularizedProjectedNewton",
322+
"required": [
323+
"type"
324+
],
325+
"optional": [
326+
"residual_tolerance",
327+
"reg_weight_min",
328+
"reg_weight_max",
329+
"reg_weight_inc"
330+
],
331+
"doc": "Options for regularized projected Newton."
332+
},
333+
{
334+
"pointer": "/solver/*",
335+
"type": "object",
336+
"type_name": "DenseNewton",
337+
"required": [
338+
"type"
339+
],
340+
"optional": [
341+
"residual_tolerance"
342+
],
343+
"doc": "Options for Newton."
344+
},
345+
{
346+
"pointer": "/solver/*",
347+
"type": "object",
348+
"type_name": "DenseProjectedNewton",
349+
"required": [
350+
"type"
351+
],
352+
"optional": [
353+
"residual_tolerance"
354+
],
355+
"doc": "Options for projected Newton."
356+
},
357+
{
358+
"pointer": "/solver/*",
359+
"type": "object",
360+
"type_name": "DenseRegularizedNewton",
361+
"required": [
362+
"type"
363+
],
364+
"optional": [
365+
"residual_tolerance",
366+
"reg_weight_min",
367+
"reg_weight_max",
368+
"reg_weight_inc"
369+
],
370+
"doc": "Options for regularized Newton."
371+
},
372+
{
373+
"pointer": "/solver/*",
374+
"type": "object",
375+
"type_name": "DenseRegularizedProjectedNewton",
376+
"required": [
377+
"type"
378+
],
379+
"optional": [
380+
"residual_tolerance",
381+
"reg_weight_min",
382+
"reg_weight_max",
383+
"reg_weight_inc"
384+
],
385+
"doc": "Options for projected regularized Newton."
386+
},
387+
{
388+
"pointer": "/solver/*",
389+
"type": "object",
390+
"type_name": "GradientDescent",
391+
"required": [
392+
"type"
393+
],
394+
"doc": "Options for Gradient Descent."
395+
},
396+
{
397+
"pointer": "/solver/*",
398+
"type": "object",
399+
"type_name": "StochasticGradientDescent",
400+
"required": [
401+
"type"
402+
],
403+
"optional": [
404+
"erase_component_probability"
405+
],
406+
"doc": "Options for Stochastic Gradient Descent."
407+
},
408+
{
409+
"pointer": "/solver/*",
410+
"type": "object",
411+
"type_name": "L-BFGS",
412+
"required": [
413+
"type"
414+
],
415+
"optional": [
416+
"history_size"
417+
],
418+
"doc": "Options for L-BFGS."
419+
},
420+
{
421+
"pointer": "/solver/*",
422+
"type": "object",
423+
"type_name": "BFGS",
424+
"required": [
425+
"type"
426+
],
427+
"doc": "Options for BFGS."
428+
},
429+
{
430+
"pointer": "/solver/*",
431+
"type": "object",
432+
"type_name": "ADAM",
433+
"required": [
434+
"type"
435+
],
436+
"optional": [
437+
"alpha",
438+
"beta_1",
439+
"beta_2",
440+
"epsilon"
441+
],
442+
"doc": "Options for ADAM."
443+
},
444+
{
445+
"pointer": "/solver/*",
446+
"type": "object",
447+
"type_name": "StochasticADAM",
448+
"required": [
449+
"type"
450+
],
451+
"optional": [
452+
"alpha",
453+
"beta_1",
454+
"beta_2",
455+
"epsilon",
456+
"erase_component_probability"
457+
],
458+
"doc": "Options for ADAM."
459+
},
460+
{
461+
"pointer": "/solver/*/type",
462+
"type": "string",
463+
"options": [
464+
"Newton",
465+
"DenseNewton",
466+
"ProjectedNewton",
467+
"DenseProjectedNewton",
468+
"RegularizedNewton",
469+
"DenseRegularizedNewton",
470+
"RegularizedProjectedNewton",
471+
"DenseRegularizedProjectedNewton",
472+
"GradientDescent",
473+
"StochasticGradientDescent",
474+
"ADAM",
475+
"StochasticADAM",
476+
"L-BFGS",
477+
"BFGS"
478+
],
479+
"doc": "Nonlinear solver type"
480+
},
481+
{
482+
"pointer": "/solver/*/residual_tolerance",
483+
"default": 1e-5,
484+
"type": "float",
485+
"doc": "Tolerance of the linear system residual. If residual is above, the direction is rejected."
486+
},
487+
{
488+
"pointer": "/solver/*/reg_weight_min",
489+
"default": 1e-8,
490+
"type": "float",
491+
"doc": "Minimum regulariztion weight."
492+
},
493+
{
494+
"pointer": "/solver/*/reg_weight_max",
495+
"default": 1e8,
496+
"type": "float",
497+
"doc": "Maximum regulariztion weight."
498+
},
499+
{
500+
"pointer": "/solver/*/reg_weight_inc",
501+
"default": 10,
502+
"type": "float",
503+
"doc": "Regulariztion weight increment."
504+
},
505+
{
506+
"pointer": "/solver/*/erase_component_probability",
507+
"default": 0.3,
508+
"type": "float",
509+
"doc": "Probability of erasing a component on the gradient for stochastic solvers."
510+
},
511+
{
512+
"pointer": "/solver/*/history_size",
513+
"default": 6,
514+
"type": "int",
515+
"doc": "The number of corrections to approximate the inverse Hessian matrix."
516+
},
517+
{
518+
"pointer": "/solver/*/alpha",
519+
"default": 0.001,
520+
"type": "float",
521+
"doc": "Parameter alpha for ADAM."
522+
},
523+
{
524+
"pointer": "/solver/*/beta_1",
525+
"default": 0.9,
526+
"type": "float",
527+
"doc": "Parameter beta_1 for ADAM."
528+
},
529+
{
530+
"pointer": "/solver/*/beta_2",
531+
"default": 0.999,
532+
"type": "float",
533+
"doc": "Parameter beta_2 for ADAM."
534+
},
535+
{
536+
"pointer": "/solver/*/epsilon",
537+
"default": 1e-8,
538+
"type": "float",
539+
"doc": "Parameter epsilon for ADAM."
540+
},
266541
{
267542
"pointer": "/line_search",
268543
"default": null,

src/polysolve/Utils.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,12 @@ namespace polysolve
7171
return I;
7272
}
7373

74+
double extract_param(const std::string &key, const std::string &name, const json &json)
75+
{
76+
if (json.find(key) != json.end())
77+
return json[key][name];
78+
79+
return json[name];
80+
}
81+
7482
} // namespace polysolve

src/polysolve/Utils.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,6 @@ namespace polysolve
6060

6161
Eigen::SparseMatrix<double> sparse_identity(int rows, int cols);
6262

63+
double extract_param(const std::string &key, const std::string &name, const json &json);
64+
6365
} // namespace polysolve

0 commit comments

Comments
 (0)