Skip to content

Update the get/set syntax#363

Open
joaquimg wants to merge 1 commit into
masterfrom
jg/getset_attribute
Open

Update the get/set syntax#363
joaquimg wants to merge 1 commit into
masterfrom
jg/getset_attribute

Conversation

@joaquimg
Copy link
Copy Markdown
Member

@joaquimg joaquimg commented May 27, 2026

Summary

Move the JuMP-level forward/reverse differentiation API to the standard
get_attribute / set_attribute interface with MOI attribute objects,
replacing the bespoke DiffOpt.{get,set}_* accessor functions.

API changes

Old New
DiffOpt.set_forward_parameter(model, x, v) set_attribute(x, DiffOpt.ForwardParameterValue(), v)
DiffOpt.get_reverse_parameter(model, x) get_attribute(x, DiffOpt.ReverseParameterValue())
DiffOpt.set_reverse_variable(model, x, v) set_attribute(x, DiffOpt.ReverseVariablePrimal(), v)
DiffOpt.get_forward_variable(model, x) get_attribute(x, DiffOpt.ForwardVariablePrimal())
DiffOpt.set_reverse_objective(model, v) set_attribute(model, DiffOpt.ReverseObjectiveValue(), v)
DiffOpt.get_forward_objective(model) get_attribute(model, DiffOpt.ForwardObjectiveSensitivity())
DiffOpt.set_forward_objective_function(model, f) set_attribute(model, DiffOpt.ForwardObjectiveFunction(), f)
DiffOpt.set_forward_constraint_function(model, c, f) set_attribute(c, DiffOpt.ForwardConstraintFunction(), f)
DiffOpt.get_forward_constraint_dual(model, c) get_attribute(c, DiffOpt.ForwardConstraintDual())
DiffOpt.get_reverse_objective_function(model) get_attribute(model, DiffOpt.ReverseObjectiveFunction())
DiffOpt.get_reverse_constraint_function(model, c) get_attribute(c, DiffOpt.ReverseConstraintFunction())
  • The old functions still work but now emit a deprecation warning.
  • ReverseObjectiveSensitivity renamed to ReverseObjectiveValue (deprecated binding kept).

[with help from claude]

Question:
Are we happy with:
forward_differentiate!(model)
or we want to move to:
set_attribute(model, ForwardDifferentiate(), nothing)
?

The nothing looks weird for something user-facing.

cc @blegat @odow @andrewrosemberg

@joaquimg joaquimg force-pushed the jg/getset_attribute branch from c94cbcb to 4a0e7aa Compare May 27, 2026 19:32
@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

❌ Patch coverage is 72.72727% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.46%. Comparing base (79393ce) to head (30fa61d).

Files with missing lines Patch % Lines
src/jump_wrapper.jl 53.33% 14 Missing ⚠️
src/diff_opt.jl 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #363      +/-   ##
==========================================
- Coverage   91.12%   90.46%   -0.67%     
==========================================
  Files          16       16              
  Lines        2491     2507      +16     
==========================================
- Hits         2270     2268       -2     
- Misses        221      239      +18     

☔ 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.

@joaquimg joaquimg force-pushed the jg/getset_attribute branch from 4a0e7aa to 30fa61d Compare May 27, 2026 19:53
@joaquimg joaquimg requested a review from blegat May 27, 2026 20:08
@blegat
Copy link
Copy Markdown
Member

blegat commented May 28, 2026

Doesn't this contradicts jump-dev/JuMP.jl#3980 (comment) and #345 ? I'm confused

@joaquimg
Copy link
Copy Markdown
Member Author

I was playing with this suggestion:
#345 (comment)

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