How explicit solutions for QPs work
masterFor QPs where all parameters are vectors (no matrix parameters), the solution is a piecewise affine function of the parameters. CVXPYgen integrates with PDAQP to precompute this map offline, allowing for extremely fast online evaluation.
Requirements & Best Practices:
- Constraint Limits: To keep the number of affine pieces tractable, limit parameters with standard CVXPY constraints (e.g., use
l <= p, p <= uwherepis a parameter). - Solver Selection: Use
solver='explicit'ingenerate_code. - Dual Variables: To compute dual variables, set
solver_opts={'dual': True}. - Complexity Control: Use
solver_optsto control'max_floats'(default1e6) and'max_regions'(default500). - Precision: Use
'fp16': Trueinsolver_optsto store the solution in half precision.
# Example of generating an explicit solver with constraints
prob = cp.Problem(obj, constr + [l <= p, p <= u])
cpg.generate_code(prob, code_dir='code_explicit', solver='explicit')