I need to get the constraint Jacobian for a model which contains linear, quadratic, and nonlinear constraints. For the nonlinear constraints, I can use the NLPEvaluator with function eval_constraint_jacobian. For the linear constraints, my current strategy is to get the constraint coefficients as follows:
linear_constraint_references = all_constraints(model, AffExpr, MOI.EqualTo{Float64})
x = all_variables(model)
linear_jacobian = zeros(length(linear_constraint_references), length(x))
for r = 1:length(linear_constraint_references)
for v = 1:length(x)
linear_jacobian[r,v] = normalized_coefficient(linear_constraint_references[r], x[v])
end
end
However, I’m getting stuck on the quadratic constraints. I can get the coefficient for any linear terms in the quadratic expression using the normalized_coefficient method, but I don’t know how to query the quadratic constraint to find the coefficient of any quadratic terms. Is there a way to do this? Or is there another method to take the gradient of the quadratic constraint?