Skip to content

Conversation

@klamike
Copy link

@klamike klamike commented Jan 8, 2026

dy is keyed by ConstraintIndex, but DiffOpt was unwrapping to int before calling haskey, so it was always false, silently zeroing the contribution.

Base.@kwdef mutable struct InputCache
dx::Dict{MOI.VariableIndex,Float64} = Dict{MOI.VariableIndex,Float64}()# dz for QP
dy::Dict{MOI.ConstraintIndex,Float64} = Dict{MOI.ConstraintIndex,Float64}()

MWE
using Pkg, Revise
Pkg.add("DiffOpt")
# Pkg.add(rev="mk/fix_nlp_bounds", url="[email protected]:klamike/DiffOpt.jl.git")
using JuMP, Ipopt, DiffOpt; const MOI = JuMP.MOI

model = DiffOpt.nonlinear_diff_model(Ipopt.Optimizer)
set_silent(model)
@variable(model, x[1:3] >= 0)
@variable(model, p in MOI.Parameter(4.5))
@constraint(model, 6x[1] + 3x[2] + 2x[3] == p)
@constraint(model, x[1] + x[2] - x[3] == 1)
@objective(model, Min, sum(x.^2))
optimize!(model)
value(x[3])  # ≈ 0 --> lower bound is active

MOI.set(model, DiffOpt.ReverseConstraintDual(), LowerBoundRef(x[3]), 1.0)
DiffOpt.reverse_differentiate!(model)
dp = MOI.get(model, DiffOpt.ReverseConstraintSet(), ParameterRef(p)).value
dp # before: dp ≈ 0.0, after: dp ≈ -2.888

cc @andrewrosemberg

@blegat
Copy link
Member

blegat commented Jan 8, 2026

Good catch, thanks, could you add a test ?

@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.93%. Comparing base (1b3cfe1) to head (73186f4).

Files with missing lines Patch % Lines
src/NonLinearProgram/NonLinearProgram.jl 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #332      +/-   ##
==========================================
+ Coverage   88.72%   88.93%   +0.20%     
==========================================
  Files          16       16              
  Lines        1960     1961       +1     
==========================================
+ Hits         1739     1744       +5     
+ Misses        221      217       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@blegat
Copy link
Member

blegat commented Jan 9, 2026

I would guess the documentation failure is because of jump-dev/SCS.jl#333, so it should be unrelated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants