Repository navigation
Keep instantiated closures in sync with the live p (#1383) - #1400
Open
greekera1000 wants to merge 1 commit into
Open
greekera1000 wants to merge 1 commit into
greekera1000 wants to merge 1 commit into
Conversation
ChrisRackauckas-Claude
left a comment
Member
There was a problem hiding this comment.
Thanks for taking on #1383. Keeping the instantiated closures in sync with the live p is the right goal. An automated review ran the change against concrete probes and found three blocking problems. The scripts and outputs can be shared if useful.
- Sparse Hessian metadata goes stale after
reinit!(lib/OptimizationBase/src/live_params.jl:52vs_wrap_liveat line 134).l.fis rebuilt, but the original prototypes and color vectors are kept.- Setup:
AutoSparse(AutoForwardDiff()), objectivep[1] > 0 ? x[1]^2 : x[2]^2, linear constraintx[1] + x[2]. Changingpfrom[1.0]to[-1.0]through an actualOptimizationCache/reinit!. - Result: the callback fills the
(2,2)entry while the solver-facing prototype still declares(1,1), so the reconstructed Hessian isdiag(2,0)instead ofdiag(0,2). - Please either rebuild all dependent sparsity metadata consistently, keep a valid common sparsity structure, or reject a changed structure before returning values. Add a regression with parameter-dependent sparsity through
reinit!.
- Setup:
- σ = 0 Lagrangian Hessian becomes NaN (
lib/OptimizationBase/src/OptimizationDISparseExt.jl:266, and the out-of-place path near line 546). The full Lagrangian is always differentiated, so a singular objective derivative poisons the result even when its weight is zero.- Setup: objective
sqrt(x[1]) + x[2]^2, constraintsum(abs2, x), sparse ForwardDiff, instantiated at[1,1], thenlag_h(H, [0,0], 0.0, [1.0]). - Result:
[NaN 0; 0 NaN]. The dense backend gives the correct2I. - A constraint-only path for
σ == 0fixes this. Please test a singular-objective case.
- Setup: objective
OptimizationBase.instantiate_liveisn't public but is called from OptimizationPRIMA (OptimizationPRIMA.jl:82) and OptimizationMOI (nlp.jl:135). ExplicitImports' public-access check then fails withNonPublicQualifiedAccessException. Please declare it public in a way that works on the supported Julia versions, and add its docstring to the rendered docs. Please don't add an ignore-list entry for it. The 5.8 minor bump fits the new API.
Smaller points:
- About 13% of the added lines are comments, and several describe earlier implementations, e.g.
live_params.jl:1–13,function.jl:135andOptimizationDISparseExt.jl:259. That history fits better in the PR description. - Please note in the body that the Optimisers/Sophia changes overlap the open #1381, and include the commands and failing-before/passing-after output.
🤖 Review by an AI agent (Codex CLI, model gpt-6-astra), posted by Claude Code (model claude-opus-5-5[1m]) on behalf of Chris Rackauckas — https://claude.ai/code/session_01AXwyJDRaMKgnYMG9M1Ut49
greekera1000
force-pushed
the
fix-live-params
branch
from
October 9, 2026 16:41
823f7bb to
2282272
Compare
This branch has not been deployed
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.
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
Problem
instantiate_functionbakespinto the derivative/constraint closures atinit.reinit!(cache; p)only replacescache.reinit_cache.p, so those closures kept the oldp. With a data iterator, they were baked with the first batch, and non-minibatch solvers silently fit only batch 1.Fix #1383
Rather than changing every solver call site, this is fixed once in OptimizationBase:
instantiate_livewraps the instantiated closures. Each call checksreinit_cache.p === p_at_build(one pointer compare) and rebuilds once ifreinit!replacedp. An explicit livepis routed to the refreshed closures, and a different explicitp(a minibatch) is forwarded as-is.ArgumentErrorinstead of using batch 1.OptimizationCache, the MOI NLP cache and PRIMA now useinstantiate_live.Also fixes:
cons_vjp/cons_jvp: droppedv, so it landed inp.lag_h: had the wrong arity.NullParametersguards: were dead code.lag_hat σ = 0 (in-place and out-of-place): broken.Tests
reinit!@test_brokennow passes.live_params_test.jl.lag_htests.Not included: MTK
reinit!with symbolic maps, andsave_bestwith minibatches.OptimizationBase 5.7.0 → 5.8.0 (new
instantiate_live); MOI and PRIMA compat floors raised to 5.8.