Repository navigation
Use MOI.Nonlinear.ModelWithQuad instead of QPBlockData - #549
Merged
Merged
Conversation
Store the affine and quadratic objective and constraints in a MOI.Nonlinear.ModelWithQuad whose inner model is the nonlinear model (nlp_model now aliases quad_data.inner), and evaluate everything through a MOI.Nonlinear.EvaluatorWithQuad built in _setup_model. The evaluator owns the QP block entry counts, so the qp_nnzj/qp_nnzh fields are removed. The inner evaluator is a new _OracleNLPEvaluator that stacks the VectorNonlinearOracle rows before the NLPBlock rows; it extends the private MOI.Nonlinear._constraint_bounds so that the constraint bounds of the whole stack are assembled by the evaluator.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## bl/qp_block_data #549 +/- ##
====================================================
- Coverage 100.00% 99.55% -0.45%
====================================================
Files 4 4
Lines 948 899 -49
====================================================
- Hits 948 895 -53
- Misses 0 4 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
MOI.Nonlinear.ModelWithQuad no longer implements MOI.set for the objective; Nonlinear.set_objective is the single way to set it.
MOI.Nonlinear.ModelWithQuad now owns the variables (with indices guaranteed to be 1:n) and the parameters of the model, so the variables, parameters, quad_data and nlp_model fields collapse into a single model field that most of the MOI API forwards to. The parameter convention is back to the simple _PARAMETER_OFFSET test, now defined in MOI.Nonlinear, and the parameter values are stored once, in the inner nonlinear model, aliased by the QP block: the per-solve parameter sync is gone. A uses_nlp_block flag replaces the nlp_model !== nothing test to tell the legacy MOI.NLPBlock API apart, because optimize! overwrites nlp_data; the NLPBlock is rebuilt on every setup unless that flag is set, so that a stale objective cannot survive an objective switch.
Defining the term methods on a local alias of the function pirated it; the term methods are in MOI.Nonlinear now.
odow
reviewed
Aug 17, 2026
| using Pkg | ||
| Pkg.add([ | ||
| PackageSpec(name="MathOptInterface", rev="bl/qp_block_data"), | ||
| PackageSpec(name="MathOptInterface", rev="bl/model_with_quad"), |
Member
There was a problem hiding this comment.
Use [sources] in Project.toml instead
Member
Author
There was a problem hiding this comment.
Doesn't work on Julia v1.10
blegat
marked this pull request as ready for review
August 21, 2026 05:17
blegat
added a commit
that referenced
this pull request
Oct 19, 2026
* Use MOI.Nonlinear.ModelWithQuad instead of QPBlockData Store the affine and quadratic objective and constraints in a MOI.Nonlinear.ModelWithQuad whose inner model is the nonlinear model (nlp_model now aliases quad_data.inner), and evaluate everything through a MOI.Nonlinear.EvaluatorWithQuad built in _setup_model. The evaluator owns the QP block entry counts, so the qp_nnzj/qp_nnzh fields are removed. The inner evaluator is a new _OracleNLPEvaluator that stacks the VectorNonlinearOracle rows before the NLPBlock rows; it extends the private MOI.Nonlinear._constraint_bounds so that the constraint bounds of the whole stack are assembled by the evaluator. * MOI * Set the quadratic objective with Nonlinear.set_objective MOI.Nonlinear.ModelWithQuad no longer implements MOI.set for the objective; Nonlinear.set_objective is the single way to set it. * Merge the variables, parameters and nonlinear model into one field MOI.Nonlinear.ModelWithQuad now owns the variables (with indices guaranteed to be 1:n) and the parameters of the model, so the variables, parameters, quad_data and nlp_model fields collapse into a single model field that most of the MOI API forwards to. The parameter convention is back to the simple _PARAMETER_OFFSET test, now defined in MOI.Nonlinear, and the parameter values are stored once, in the inner nonlinear model, aliased by the QP block: the per-solve parameter sync is gone. A uses_nlp_block flag replaces the nlp_model !== nothing test to tell the legacy MOI.NLPBlock API apart, because optimize! overwrites nlp_data; the NLPBlock is rebuilt on every setup unless that flag is set, so that a stale objective cannot survive an objective switch. * Use the _is_parameter of MOI.Nonlinear directly Defining the term methods on a local alias of the function pirated it; the term methods are in MOI.Nonlinear now. * Fix * Get rid of list_of_variable_indices
blegat
added a commit
that referenced
this pull request
Nov 26, 2026
* Use MOI.Nonlinear.ModelWithQuad instead of QPBlockData Store the affine and quadratic objective and constraints in a MOI.Nonlinear.ModelWithQuad whose inner model is the nonlinear model (nlp_model now aliases quad_data.inner), and evaluate everything through a MOI.Nonlinear.EvaluatorWithQuad built in _setup_model. The evaluator owns the QP block entry counts, so the qp_nnzj/qp_nnzh fields are removed. The inner evaluator is a new _OracleNLPEvaluator that stacks the VectorNonlinearOracle rows before the NLPBlock rows; it extends the private MOI.Nonlinear._constraint_bounds so that the constraint bounds of the whole stack are assembled by the evaluator. * MOI * Set the quadratic objective with Nonlinear.set_objective MOI.Nonlinear.ModelWithQuad no longer implements MOI.set for the objective; Nonlinear.set_objective is the single way to set it. * Merge the variables, parameters and nonlinear model into one field MOI.Nonlinear.ModelWithQuad now owns the variables (with indices guaranteed to be 1:n) and the parameters of the model, so the variables, parameters, quad_data and nlp_model fields collapse into a single model field that most of the MOI API forwards to. The parameter convention is back to the simple _PARAMETER_OFFSET test, now defined in MOI.Nonlinear, and the parameter values are stored once, in the inner nonlinear model, aliased by the QP block: the per-solve parameter sync is gone. A uses_nlp_block flag replaces the nlp_model !== nothing test to tell the legacy MOI.NLPBlock API apart, because optimize! overwrites nlp_data; the NLPBlock is rebuilt on every setup unless that flag is set, so that a stale objective cannot survive an objective switch. * Use the _is_parameter of MOI.Nonlinear directly Defining the term methods on a local alias of the function pirated it; the term methods are in MOI.Nonlinear now. * Fix * Get rid of list_of_variable_indices
blegat
added a commit
that referenced
this pull request
Nov 26, 2026
* Use MOI.Nonlinear.QPBlockData Delete the local QPBlockData (utils.jl) in favor of the copy that moved to MathOptInterface. Two adaptations: - MOI's QPBlockData treats a variable as a parameter if and only if its index is a key of the parameters dictionary, instead of the index-offset convention, so parameters are registered when the constrained variable is added (the value is still re-synced in copy_parameters before every solve). - eval_constraint_jacobian and eval_hessian_lagrangian now return the number of entries written instead of a one-indexed cursor, so the callers drop the offset adjustment. * MOI * Track the QP block entry counts in the Optimizer The evaluator methods of MOI.Nonlinear.QPBlockData now return nothing, following the documented contract of MOI.eval_constraint_jacobian and MOI.eval_hessian_lagrangian, so the offsets of the oracle and NLP blocks are computed once in _setup_model instead. * Use MOI.Nonlinear.ModelWithQuad instead of QPBlockData (#549) * Use MOI.Nonlinear.ModelWithQuad instead of QPBlockData Store the affine and quadratic objective and constraints in a MOI.Nonlinear.ModelWithQuad whose inner model is the nonlinear model (nlp_model now aliases quad_data.inner), and evaluate everything through a MOI.Nonlinear.EvaluatorWithQuad built in _setup_model. The evaluator owns the QP block entry counts, so the qp_nnzj/qp_nnzh fields are removed. The inner evaluator is a new _OracleNLPEvaluator that stacks the VectorNonlinearOracle rows before the NLPBlock rows; it extends the private MOI.Nonlinear._constraint_bounds so that the constraint bounds of the whole stack are assembled by the evaluator. * MOI * Set the quadratic objective with Nonlinear.set_objective MOI.Nonlinear.ModelWithQuad no longer implements MOI.set for the objective; Nonlinear.set_objective is the single way to set it. * Merge the variables, parameters and nonlinear model into one field MOI.Nonlinear.ModelWithQuad now owns the variables (with indices guaranteed to be 1:n) and the parameters of the model, so the variables, parameters, quad_data and nlp_model fields collapse into a single model field that most of the MOI API forwards to. The parameter convention is back to the simple _PARAMETER_OFFSET test, now defined in MOI.Nonlinear, and the parameter values are stored once, in the inner nonlinear model, aliased by the QP block: the per-solve parameter sync is gone. A uses_nlp_block flag replaces the nlp_model !== nothing test to tell the legacy MOI.NLPBlock API apart, because optimize! overwrites nlp_data; the NLPBlock is rebuilt on every setup unless that flag is set, so that a stale objective cannot survive an objective switch. * Use the _is_parameter of MOI.Nonlinear directly Defining the term methods on a local alias of the function pirated it; the term methods are in MOI.Nonlinear now. * Fix * Get rid of list_of_variable_indices * MOI * Use MOI api with NL model * Use MOI.Nonlinear.model * Remove calls to internal functions * Remove _has_objective * Use variable_bounds and constraint_bounds * Add assert * Fix tests with MOI.Nonlinear.ModelWithQuad * Exclude the parameters from the variables of the evaluator * Only set hessian_constant if the constraints are linear * Use MOI.is_empty of the model in MOI.is_empty * Error when setting the NLPBlock after adding a parameter * Keep the model data when the AD backend uses the same type of model * Return the block of the evaluator in MOI.get for MOI.NLPBlock * Read the objective sense at each evaluation of the legacy NLPBlock * Do not query the Jacobian of a legacy NLPBlock without constraints * Format * Fix codecov * Bump MOI * Compute oracle duals from the requested oracle’s Jacobian
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Need