Differentiating through a QP - order of constraints

Thanks for the reply. I am not sure this is the problem, I don’t want to differentiate simultaneously. What I think is happening is when I do this:

    for cs in constr
        MOI.set(
            model,
            DiffOpt.ForwardConstraintFunction(),
            cs,
            0.0 * index(model[:x][1]) - 1.0,  # to indicate the direction vector to get directional derivatives
        )
        DiffOpt.forward_differentiate!(model)
        dwdb = MOI.get.(model, DiffOpt.ForwardVariablePrimal(), model[:x])
        push!(dwdbOut, dwdb)
    end

in every iteration DiffOpt wants to differentiate through the current cs and that works in the first iteration. In the second iteration I would like to differentiate through the second constraints in a given direction, but DiffOpt keeps the direction for the first constraint that I set in the first iteration. This would explain why changing the order of constraints in the differentiation changes the results.

My current workaround (inspired by this example) is

MOI.set.(
    model,
    DiffOpt.ForwardConstraintFunction(),
    [cons1;cons2],
    [0.0 * index(x[1]) - 1.0;0.0 * index(x[1]) ],  # to indicate the direction vector to get directional derivatives
)

DiffOpt.forward_differentiate!(model)
dxh1 = MOI.get.(model, DiffOpt.ForwardVariablePrimal(), x)

MOI.set.(
    model,
    DiffOpt.ForwardConstraintFunction(),
    [cons1;cons2],
    [0.0 * index(x[1]) ;0.0 * index(x[1]) - 1.0 ],  # to indicate the direction vector to get directional derivatives
)

DiffOpt.forward_differentiate!(model)
dxh3 = MOI.get.(model, DiffOpt.ForwardVariablePrimal(), x)