Repository navigation
Support successful_retcode on traced Reactant return codes - #1637
Merged
ChrisRackauckas merged 2 commits intoOct 11, 2026
Merged
ChrisRackauckas merged 2 commits into
ChrisRackauckas merged 2 commits into
Conversation
Inside a Reactant compilation a ReturnCode can be a Reactant.TracedEnum
(public since Reactant 0.2.289). successful_retcode then hit the generic
convert(ReturnCode.T, retcode) fallback and threw a MethodError, and the
short-circuiting || cannot branch on a traced Bool. A Reactant weakdep
extension adds successful_retcode(::Reactant.TracedEnum{ReturnCode.T}),
which combines the comparisons with | into a traced Bool. The successful
codes move to one internal tuple used by both methods.
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude <[email protected]>
Agent-Harness: Claude Code 2.1.292
Agent-Model: opus
Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/LineSearch.jl/jobs/ls109x-claude/log.txt on amdci2.julia.csail.mit.edu
… the extension Membership in a tuple made bulk host classification about 7x slower than the short-circuit expression. The host method is restored exactly; the tuple lives in SciMLBaseReactantExt for the traced method only, and a test checks the traced and host methods agree on every ReturnCode. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude <[email protected]> Agent-Harness: Claude Code 2.1.292 Agent-Model: opus Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/LineSearch.jl/jobs/ls109x-claude/log.txt on amdci2.julia.csail.mit.edu
Member
Independent review (Devin CLI 3000.11.3, model fusion-claude-opus-5-5-high-sidekick-swe-2-medium): MERGE, risk low. Full reviewVERDICT: MERGE PR: #1637 (head f78ac08, merge-base 432e985; origin/master c8ea9ca differs only in a downstream test file). Blocking findingsNone. Non-blocking findings
What I ranAll runs used Julia 1.12.7 and Reactant 0.2.291, with SciMLBase dev'd from the checkout. Logs are in
What I did not verify
Links
🤖 Posted by an AI agent — harness: Devin CLI 3000.11.3 (review), Claude Code 2.1.285 (posting) · model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium |
ChrisRackauckas
marked this pull request as ready for review
October 11, 2026 10:31
ChrisRackauckas
referenced
this pull request
Oct 13, 2026
* Add a specialization marker to `OptimizationFunction`
`OptimizationFunction` had no specialization marker: its second type parameter is
the AD type, and `specialization(::OptimizationFunction)` returned that instead of
an `AbstractSpecialization`. The marker is now stored as the last type parameter,
after the field types, so code that spells out the existing parameters keeps
working. It defaults to `FullSpecialize`, so existing functions are unchanged.
`OptimizationFunction{iip, specialize}(f, adtype; kwargs...)` selects it, and
`specialization` returns it. `remake`, `ConstructionBase.setproperties` (and with
it `@set`) and `OptimizationProblem` keep it. The spelling that passes the AD
type as the second type parameter (`OptimizationFunction{iip, AD}(f; adtype)`)
still builds a `FullSpecialize` function.
What `AutoSpecialize` and `AutoDespecialize` do is up to the solver packages,
as for the other SciML functions.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
* Convert parameter objects to `DespecializedParameters`
Storage typed for despecialized parameters could not be assigned a new parameter
object. For example, an optimization cache built from an `AutoDespecialize`
problem stores `p` as a `DespecializedParameters`, and `reinit!(cache; p = new_p)`
threw `Cannot convert an object of type ... to an object of type
SciMLBase.DespecializedParameters`. `convert` now wraps the object, and returns an
already wrapped one unchanged.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
* Bump version to 3.58.0
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
---------
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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.
Please ignore until reviewed by @ChrisRackauckas.
What changed and why
SciMLBase.successful_retcodethrows on a return code produced insideReactant.@jit. A compiled solver that selects its code withifelsereturns aReactant.TracedEnum{ReturnCode.T}. The generic fallback then callsconvert(ReturnCode.T, retcode), which throwsMethodError: Cannot convert Reactant.TracedEnum{SciMLBase.ReturnCode.T} to SciMLBase.ReturnCode.T. TheReturnCode.Tmethod uses short-circuit||, which cannot branch on a tracedBooleither.This PR adds a
SciMLBaseReactantExtextension. It definessuccessful_retcode(::Reactant.TracedEnum{ReturnCode.T}), which foldsretcode == codeover the successful codes with the non-short-circuiting|and returns a tracedBool. The successful codes for the traced method are a tuple inside the extension. The host methodsuccessful_retcode(::ReturnCode.T)is unchanged from master, keeping its short-circuit||expression and its speed. A test checks that the traced and host methods agree on everyinstances(ReturnCode.T), so the two lists cannot drift apart silently.The concrete caller is the compiled
RobustNonMonotoneLineSearchin SciML/LineSearch.jl#112. NonlinearSolve's DFSane checks!SciMLBase.successful_retcode(linesearch_sol.retcode)inside the compiled loop: https://github.com/SciML/NonlinearSolve.jl/blob/1caff340eef9f55895b03cb06c6849bacb37cce6/lib/NonlinearSolveSpectralMethods/src/solve.jl#L212-L230Verification
All at head
f78ac0858.GROUP=Reactant: "Reactant specialization" 4/4 and "Reactant return codes" 28/28 pass.test/reactant_retcodes.jlcovers:@jit, plus the after-returnConcreteEnum;ReturnCodeinstances.The agreement test catches drift: I dropped
StalledSuccessfrom the extension's tuple in a scratch copy. Exactly one of the 22 cases fails, "agree on StalledSuccess" (false == true), and so does the existing StalledSuccess assertion.GROUP=Core: passed.ExplicitImports with Reactant loaded: all six checks pass on
SciMLBaseReactantExt, using the round-1 reviewer'sei.jl. The extension references no SciMLBase internal, sotest/qa/qa.jl's_ei_own_internalsneeds no new entry.Formatting: Runic is clean on the changed files; the repo-wide
--checkalready fails on master.typosis clean.Host performance matches master. I used the reviewer's
bulk_host.jl(@btime count(SciMLBase.successful_retcode, xs)over 22000 codes, 6000 successes) andbench_compare.jl(the original expression vs the package method, in the same process). Each project is a dev'd worktree of master432e9856bor this head:bulk_host.jlmasterbulk_host.jlheadbench_compare.jlhead: original/package, 22000 codes, ratioThe previous head
65f835f2, which used tuple membership, measured 53.2 μs on Julia 1.10.12 in the round-1 review.Downstream: the LineSearch branch https://github.com/ChrisRackauckas-Claude/LineSearch.jl/tree/agent/ls109x-traced-retcode tests
successful_retcode(sol.retcode)inside@jit.MethodErrorabove).f78ac0858; only the extension's internals changed, and they are covered by the 28/28 above.GROUP=QA: at65f835f2it gave 9 pass + 1 environmental CondaPkg/pixi error, the same as master on this machine. Not rerun at this head.Not verified
run_qadoes not scan the new extension; the existingSciMLBaseReactantCoreExtis in the same position. The direct ExplicitImports checks above pass.For the reviewer
Reactantmoves from test-only to[weakdeps], and its compat floor rises from0.2to0.2.289, the first release whereReactant.TracedEnumis public. Reactant is MIT licensed.Risk assessment
successful_retcode(::ReturnCode.T)is unchanged from master. The new method loads only when Reactant is loaded. No public API is removed or changed.MethodError: Cannot convert Reactant.TracedEnum...) and passes on this branch.GROUP=Reactantat f78ac08 (Julia 1.12, Reactant 0.2.291): 4/4 and 28/28, exit 0.🤖 Generated with Claude Code (model: claude-opus-5-5[1m]). The branch was written by a Claude Code Opus 5.5 worker session (~/sandbox/agent-jobs/LineSearch.jl/jobs/ls109x-claude on amdci2) and opened by the head session.
https://claude.ai/code/session_01592Hc7Y1ZjeqdXirDGww44
Independent review: Devin Fusion (fusion-claude-opus-5-5-high-sidekick-swe-2-medium) rated it low, verdict MERGE: #1637 (comment)