proxsuite-nlp  0.10.0
A primal-dual augmented Lagrangian-type solver for nonlinear programming on manifolds.
Loading...
Searching...
No Matches
utils.py
Go to the documentation of this file.
1"""
2Copyright (C) 2022 LAAS-CNRS, INRIA
3"""
4
5import numpy as np
6
7
8_ROOT_10 = 10.0**0.5
9
10
11def plot_pd_errs(ax0, prim_errs, dual_errs):
12 import matplotlib.pyplot as plt
13
14 ax0: plt.Axes
15 prim_errs = np.asarray(prim_errs)
16 dual_errs = np.asarray(dual_errs)
17 ax0.plot(prim_errs, c="tab:blue")
18 ax0.set_xlabel("Iterations")
19 col2 = "tab:orange"
20 ax0.plot(dual_errs, c=col2)
21 ax0.spines["top"].set_visible(False)
22 ax0.spines["right"].set_color(col2)
23 ax0.yaxis.label.set_color(col2)
24 ax0.set_yscale("log")
25 ax0.legend(["Primal error $p$", "Dual error $d$"])
26 ax0.set_title("Solver primal-dual residuals")
27
28 # handle scaling
29 yhigh = ax0.get_ylim()[1]
30 if len(prim_errs) == 0 or len(dual_errs) == 0:
31 return
32 mach_eps = np.finfo(float).eps
33 dmask = dual_errs > 2 * mach_eps
34 pmask = prim_errs > 2 * mach_eps
35 ymin = np.finfo(float).max
36 if dmask.any():
37 ymin = np.min(dual_errs[dmask])
38 if pmask.any() and sum(prim_errs > 0) > 0:
39 ymin = min(np.min(prim_errs[pmask]), ymin)
40 ax0.set_ylim(ymin / _ROOT_10, yhigh)
plot_pd_errs(ax0, prim_errs, dual_errs)
Definition utils.py:11