feat: trace the termination status inside a Reactant-compiled solve - #156
Merged
gdalle merged 1 commit intoSep 10, 2026
Conversation
`ConvergenceStats.termination_status` was a plain `MOI.TerminationStatusCode`, written from inside three `@trace if` blocks. An enum cannot be traced, so only the trace-time value of those assignments survived: a compiled run that converged still reported `MOI.OPTIMIZE_NOT_CALLED`, and `max_kkt_passes` / `time_limit` decided when to stop without ever saying so. Store the status as an integer code instead. `termination_status_code` is an ordinary number, so `to_rarray` tracks it and the compiled program writes it like any other stat, and `termination_status(stats)` decodes it back to the enum. `solve` still returns the same `MOI.TerminationStatusCode` it always did, one call away. That also removes the `elseif` workaround. With a traceable code, the criteria can be selected with nested `ifelse` calls instead of three separate `@trace if` blocks ordered by increasing priority and relying on last-write-wins (EnzymeAD/Reactant.jl#2563), so the priority between simultaneous criteria is stated in one place. The Reactant coherence tests now compare statuses between the plain and compiled runs, which JuliaDecisionFocusedLearning#153 had to leave out, and the time limit test checks that the compiled solve reports `MOI.TIME_LIMIT` rather than just stopping at the right time. Verified locally on CPU: all three statuses (`OPTIMAL`, `ITERATION_LIMIT`, `TIME_LIMIT`) come back out of a compiled `solve!` for both PDHG and PDLP, and the `Core`, `MOI` and `Reactant` test groups pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JPzdTAQVAXUNUAQsL4Nz71
gdalle
approved these changes
Sep 10, 2026
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
gdalle
marked this pull request as ready for review
September 10, 2026 10:28
gdalle
merged commit Sep 10, 2026
04927b9
into
JuliaDecisionFocusedLearning:gd/reac2
13 checks passed
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.
This PR was opened by a coding agent, please disregard it until @gdalle has reviewed it
Stacked on #150 (base
gd/reac2). Addresses the first bullet of #149.The problem
ConvergenceStats.termination_statuswas a plainMOI.TerminationStatusCode, assigned from inside three@trace ifblocks. An enum cannot be traced, so only the trace-time value of those assignments survived: a compiled run that converged still reportedMOI.OPTIMIZE_NOT_CALLED.max_kkt_passesandtime_limitdecided when to stop, but the run never said which one had fired.The fix
Store the status as an integer code:
ConvergenceStatsgains a type parameter and its field becomestermination_status_code::S, an ordinary number.to_rarraytracks it and the compiled program writes it like any other stat.termination_status(stats)(@public) decodes it back to aMOI.TerminationStatusCode.solvereturns exactly the same status it always did, one call away; the MOI wrapper reads it through the accessor.status_code(status)is the encoding direction, used bytry_solve_noconstraints!.The
elseifworkaround goes away with it. With a traceable code,set_termination_status!!selects the criterion with nestedifelsecalls instead of three separate@trace ifblocks ordered by increasing priority and relying on last-write-wins (EnzymeAD/Reactant.jl#2563), so the priority between simultaneous criteria is now stated in one place.Tests
@stableand check Reactant/plain coherence #153 had to leave out.MOI.TIME_LIMIT, not just that it stops at the right time.Verified locally on the CPU backend that all three statuses (
OPTIMAL,ITERATION_LIMIT,TIME_LIMIT) come back out of a compiledsolve!, for both PDHG and PDLP. TheCore(5676 pass),MOI(1827 pass) andReactant(61 pass) test groups are green, and Runic is clean.Not in scope
The other items of #149 (the uncounted
kkt_errors!pass ininitialize, the silentrecord_error_history/show_progressno-ops, the loosened type parameters, coverage) are untouched.🤖 Generated with Claude Code
https://claude.ai/code/session_01JPzdTAQVAXUNUAQsL4Nz71