SciMLBase.jl icon indicating copy to clipboard operation
SciMLBase.jl copied to clipboard

`NamedTuple(::OptimizationSolution)` should be defined

Open Moelf opened this issue 9 months ago • 5 comments

Moelf avatar Apr 08 '25 17:04 Moelf

For what? I don't know the context here 😅

ChrisRackauckas avatar Apr 09 '25 11:04 ChrisRackauckas

For collecting the results and merge with other attributes for example

Moelf avatar Apr 09 '25 12:04 Moelf

MWE?

Most types don't have a NamedTuple function though? Is there a normal fallback just using fieldnames .=> getfield?

ChrisRackauckas avatar Apr 09 '25 13:04 ChrisRackauckas

It's a naive use case like:


sol = solve(...)
chi2 = compute_chi2(sol, input)
return merge(sol, (; chi2))

Currently, one has to do workaround like:

sol = solve(...)
chi2 = compute_chi2(sol, input)
(; u, objective) = sol
return (; u, objective, chi2)

Moelf avatar Apr 09 '25 13:04 Moelf

Is it common to add that to types? I'd assume we'd want to convert it to have all fields? In theory there's a canonical fieldnames .=> getfield that should just be defined in Base?

ChrisRackauckas avatar Apr 09 '25 16:04 ChrisRackauckas