alpaqa 0.0.1
Nonconvex constrained optimization
Classes | Variables
alpaqa.test Namespace Reference

Classes

class  CustomInnerSolver
 
class  Dir
 

Variables

 solver = pa.PANOCSolver(pa.PANOCParams(), pa.LBFGSDirection(pa.LBFGSParams()))
 
 l = pa.LBFGSParams(cbfgs=pa.LBFGSParamsCBFGS(α=5))
 
 α
 
 hess_prod = lambda L, x, v: cs.gradient(cs.jtimes(L, x, v, False), x)
 
int n = 2
 
int m = 2
 
 x = cs.SX.sym("x", n)
 
 λ = cs.SX.sym("λ", m)
 
 v = cs.SX.sym("v", n)
 
 Q = np.array([[1.5, 0.5], [0.5, 1.5]])
 
 f_ = x.T @ Q @ x
 
 g_ = x
 
int L = f_ + cs.dot(λ, g_) if m > 0 else f_
 
 f = cs.Function("f", [x], [f_])
 
 grad_f = cs.Function("grad_f", [x], [cs.gradient(f_, x)])
 
 g = cs.Function("g", [x], [g_])
 
 grad_g_prod = cs.Function("grad_g_prod", [x, λ], [cs.jtimes(g_, x, λ, True)])
 
 grad_gi = lambda x, i: grad_g_prod(x, np.eye(1, m, i))
 
 Hess_L = cs.Function("Hess_L", [x, λ], [cs.hessian(L, x)[0]])
 
 Hess_L_prod = cs.Function("Hess_L_prod", [x, λ, v], [hess_prod(L, x, v)])
 
 p = pa.Problem(n, m)
 
 hess_L
 
 hess_L_prod
 
 lowerbound
 
 upperbound
 
 x0 = np.array([3, 3])
 
 y0 = np.zeros((m,))
 
int Σ = 1e3 * np.ones((m,))
 
int ε = 1e-8
 
 y
 
 err_z
 
 stats
 
 almparams = pa.ALMParams(max_iter=20, print_interval=1, preconditioning=False)
 
 almsolver = pa.ALMSolver(almparams, solver)
 
 old_x0 = x0
 
 sol = almsolver(p, x=x0, y=y0)
 
string name = "testproblem"
 
 p0 = np.array([1.5, 0.5, 1.5])
 
 prob = pa.generate_and_compile_casadi_problem(f, g, name=name)
 
 param
 
 prob1 = pa.ProblemWithParamWithCounters(prob)
 
 prob2 = pa.ProblemWithCounters(prob)
 
 C = pa.Box([10], [-2.5])
 
 params
 
 max_iter
 

Variable Documentation

◆ solver

solver = pa.PANOCSolver(pa.PANOCParams(), pa.LBFGSDirection(pa.LBFGSParams()))

Definition at line 10 of file test.py.

◆ l

l = pa.LBFGSParams(cbfgs=pa.LBFGSParamsCBFGS(α=5))

Definition at line 31 of file test.py.

◆ α

α

Definition at line 33 of file test.py.

◆ hess_prod

hess_prod = lambda L, x, v: cs.gradient(cs.jtimes(L, x, v, False), x)

Definition at line 38 of file test.py.

◆ n

int n = 2

Definition at line 40 of file test.py.

◆ m

int m = 2

Definition at line 41 of file test.py.

◆ x

x = cs.SX.sym("x", n)

Definition at line 42 of file test.py.

◆ λ

λ = cs.SX.sym("λ", m)

Definition at line 43 of file test.py.

◆ v

v = cs.SX.sym("v", n)

Definition at line 44 of file test.py.

◆ Q

Q = np.array([[1.5, 0.5], [0.5, 1.5]])

Definition at line 46 of file test.py.

◆ f_

float f_ = x.T @ Q @ x

Definition at line 47 of file test.py.

◆ g_

g_ = x

Definition at line 48 of file test.py.

◆ L

int L = f_ + cs.dot(λ, g_) if m > 0 else f_

Definition at line 49 of file test.py.

◆ f

f = cs.Function("f", [x], [f_])

Definition at line 51 of file test.py.

◆ grad_f

int grad_f = cs.Function("grad_f", [x], [cs.gradient(f_, x)])

Definition at line 52 of file test.py.

◆ g

g = cs.Function("g", [x], [g_])

Definition at line 53 of file test.py.

◆ grad_g_prod

grad_g_prod = cs.Function("grad_g_prod", [x, λ], [cs.jtimes(g_, x, λ, True)])

Definition at line 54 of file test.py.

◆ grad_gi

grad_gi = lambda x, i: grad_g_prod(x, np.eye(1, m, i))

Definition at line 55 of file test.py.

◆ Hess_L

Hess_L = cs.Function("Hess_L", [x, λ], [cs.hessian(L, x)[0]])

Definition at line 56 of file test.py.

◆ Hess_L_prod

Hess_L_prod = cs.Function("Hess_L_prod", [x, λ, v], [hess_prod(L, x, v)])

Definition at line 57 of file test.py.

◆ p

p = pa.Problem(n, m)

Definition at line 59 of file test.py.

◆ hess_L

hess_L

Definition at line 65 of file test.py.

◆ hess_L_prod

hess_L_prod

Definition at line 66 of file test.py.

◆ lowerbound

lowerbound

Definition at line 67 of file test.py.

◆ upperbound

upperbound

Definition at line 68 of file test.py.

◆ x0

list x0 = np.array([3, 3])

Definition at line 70 of file test.py.

◆ y0

y0 = np.zeros((m,))

Definition at line 71 of file test.py.

◆ Σ

int Σ = 1e3 * np.ones((m,))

Definition at line 72 of file test.py.

◆ ε

int ε = 1e-8

Definition at line 73 of file test.py.

◆ y

y

Definition at line 78 of file test.py.

◆ err_z

err_z

Definition at line 78 of file test.py.

◆ stats

stats

Definition at line 78 of file test.py.

◆ almparams

almparams = pa.ALMParams(max_iter=20, print_interval=1, preconditioning=False)

Definition at line 88 of file test.py.

◆ almsolver

almsolver = pa.ALMSolver(almparams, solver)

Definition at line 89 of file test.py.

◆ old_x0

old_x0 = x0

Definition at line 142 of file test.py.

◆ sol

sol = almsolver(p, x=x0, y=y0)

Definition at line 144 of file test.py.

◆ name

string name = "testproblem"

Definition at line 164 of file test.py.

◆ p0

p0 = np.array([1.5, 0.5, 1.5])

Definition at line 187 of file test.py.

◆ prob

prob = pa.generate_and_compile_casadi_problem(f, g, name=name)

Definition at line 196 of file test.py.

◆ param

param

Definition at line 199 of file test.py.

◆ prob1

prob1 = pa.ProblemWithParamWithCounters(prob)

Definition at line 216 of file test.py.

◆ prob2

prob2 = pa.ProblemWithCounters(prob)

Definition at line 232 of file test.py.

◆ C

C = pa.Box([10], [-2.5])

Definition at line 262 of file test.py.

◆ params

params

Definition at line 275 of file test.py.

◆ max_iter

max_iter

Definition at line 282 of file test.py.