Skip to content

OptimizationOptimJL: default extended_trace to false - #1406

Draft
ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:opt-optimjl-no-extended-trace
Draft

ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:opt-optimjl-no-extended-trace

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Summary

__map_optimizer_args always passed extended_trace = true into Optim.Options, so every Optim iteration built a metadata Dict with copies of x, g(x), and (for BFGS) the full n×n ~inv(H) — even though OptimizationOptimJL never reads that trace (callbacks use optim_state fields). This defaults extended_trace to false while still allowing opt-in via solve(...; extended_trace=true) through the existing kwargs passthrough. The docs already say extended_trace "Defaults to false" (docs/src/optimization_packages/optim.md:45); this change makes the code match the docs.

User-visible change: with store_trace=true, each sol.original.trace entry's metadata now keeps only "time" by default. In addition to losing x / g(x) / ~inv(H), BFGS also loses "Current step size", and NelderMead loses "centroid" and "step_type". Passing extended_trace=true restores everything. The printed show_trace=true / verbose=true output changes the same way (e.g. BFGS no longer prints ~inv(H)).

Performance (BenchmarkTools minima, JULIA_NUM_THREADS=1 taskset -c 96)

Rosenbrock + AutoForwardDiff, same machine (amdci2).

Julia 1.12.4

case before after
LBFGS n=2 0.09 ms / 0.05 MB 0.08 ms / 0.04 MB
BFGS n=10 0.22 ms / 0.22 MB 0.18 ms / 0.10 MB
BFGS n=100 18.07 ms / 41.98 MB 13.06 ms / 0.61 MB

Julia 1.10.12

case before after
LBFGS n=2 0.10 ms / 0.06 MB 0.08 ms / 0.04 MB
BFGS n=10 0.24 ms / 0.23 MB 0.18 ms / 0.10 MB
BFGS n=100 18.46 ms / 41.56 MB 13.87 ms / 0.62 MB

Matches auditor A/B (BFGS n=100: 18.26 ms / 42.0 MB → 13.05 ms / 0.61 MB on 1.12).

Regression test

New @testset "extended_trace defaults to false" in lib/OptimizationOptimJL/test/core_tests.jl:

  • Unfixed (git stash of src): 5 pass / 3 fail (metadata still has x/g(x)/~inv(H)).
  • Fixed: 8/8 pass. Verified on 1.12.4 and 1.10.12.

Callback parity

Captured OptimizationState (u, objective, grad, loss) for LBFGS / BFGS / Newton / IPNewton over 10 iters: identical master vs this PR.

Test-group tails

  • OPTIMIZATION_TEST_GROUP=Core (1.12.4): Core | 6977 Pass / 6977 Total; tests passed
  • OPTIMIZATION_TEST_GROUP=Core (1.10.12): Core | 6977 Pass / 6977 Total; tests passed
  • OPTIMIZATION_TEST_GROUP=QA (1.12.4): Quality Assurance | 54 Pass, 1 Broken / 55 Total; tests passed (broken is pre-existing ExplicitImports)
  • Runic + typos on touched files: clean (files were Runic-clean on master)

Not verified

  • Root monorepo GROUP=QA / GROUP=All (never run per policy).
  • Downstream packages that may have depended on extended metadata appearing under store_trace=true alone.
  • Absolute µs on a busy shared host have run-to-run noise; memory (MB) is the stable signal for BFGS n=100.

Reviewer pushback

  • Is anyone relying on store_trace=true implicitly getting extended metadata (x/g(x)/~inv(H), BFGS "Current step size", NelderMead "centroid"/"step_type") or the matching show_trace/verbose lines without extended_trace=true? Docs already said extended_trace defaults to false.
  • Should we omit extended_trace from mapped_args entirely (let Optim's default apply) instead of setting false explicitly? Behavior is the same today because kwargs override.

Please ignore until reviewed by @ChrisRackauckas.

Risk assessment

Independent review: MERGE (Claude Code, Opus 5.5) — low risk; callback parity holds; memory 42 → 0.6 MB. Pending @ChrisRackauckas.


🤖 Generated with Cursor Agent 2026.10.01-14929f9 (model: unknown (Cursor auto)), transcript /home/crackauc/sandbox/goals/performance/jobs/opt/opt-trace/log.txt on amdci2; orchestrated by Claude Code (claude-opus-5-5[1m]) https://claude.ai/code/session_01LPHREnnonfLg1VcE1EJovv

Forcing extended_trace=true made Optim allocate per-iteration Dicts with
copies of x, g(x), and ~inv(H); nothing in the wrapper reads that metadata.
Default false (opt-in via kwargs) cuts BFGS n=100 solve memory ~42 MB → ~0.6 MB.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Cursor Agent <noreply@cursor.com>
Agent-Harness: Cursor Agent 2026.10.01-14929f9
Agent-Model: unknown (Cursor auto)
Agent-Session: local session, transcript /home/crackauc/sandbox/goals/performance/jobs/opt/opt-trace/log.txt on amdci2

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants