CUTEst loader#
In this example, we load a CUTEst problem using the
alpaqa.CUTEstProblem
class. These problems can be used to run
benchmarks.
1import os
2import numpy as np
3import alpaqa as pa
4import contextlib
5import gc
6from pathlib import Path
7
8# Path containing the compiled CUTEst problems
9cutest_dir = Path(os.getenv("HOME")) / "opt" / "CUTEst" / "QP"
10problem_name = "CBS"
11
12# alpaqa currently only supports one instance of a CUTEst problem at a time 🙃
13with contextlib.suppress(NameError):
14 del prob
15gc.collect()
16# Load problem
17prob = pa.CUTEstProblem(str(cutest_dir / problem_name), sparse=True)
18
19# Extract the problem data
20n = prob.n
21m = prob.m
22Q, Q_sym = prob.eval_hess_L(np.zeros(n), np.zeros(m))
23c, q = prob.eval_f_grad_f(np.zeros(n))
24x_lb = prob.C.lowerbound
25x_ub = prob.C.upperbound
26A, A_sym = prob.eval_jac_g(np.zeros(n))
27g = prob.eval_g(np.zeros(n))
28g_lb = prob.D.lowerbound - g
29g_ub = prob.D.upperbound - g
30
31# You could now pass these matrices to a QP solver, for example.
32
33# Do note the symmetry of the sparse matrices:
34# - Q will usually only contain the elements in the upper triangular
35# (as indicated by Q_sym).
36# - A will usually be unsymmetric, and store all its elements explicitly
37# (as indicated by A_sym).
38print(n, m)
39print(A_sym)
40print(A.nnz)
41print(Q_sym)
42print(Q.nnz)