Skip to content

Conversation

@klamike
Copy link
Contributor

@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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.13%. Comparing base (1b3cfe1) to head (2f93d63).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #332      +/-   ##
==========================================
+ Coverage   88.72%   89.13%   +0.41%     
==========================================
  Files          16       16              
  Lines        1960     1961       +1     
==========================================
+ Hits         1739     1748       +9     
+ Misses        221      213       -8     

☔ 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

Copy link
Member

@blegat blegat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@blegat blegat merged commit 2fe6bb9 into jump-dev:master Jan 19, 2026
6 of 7 checks passed
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