feat: Implement recursivecopy for structs#468
Conversation
Only supports mutable structs, and has to have extra logic to dispatch on basic types...
|
I tried to swap this into here but that currently fails... |
- Test recursivecopy with ODE solutions and ArrayPartition integration - Verify struct-based parameter copying in differential equations - Ensure deep independence of copied solution objects 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Include Function in the list of basic Julia types - Add RecursiveArrayTools dependency to downstream tests - Include struct copy tests in main test suite - Add ODE solution copy tests to downstream test suite 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add type equality check for copied solution - Simplify independence test to focus on solution data - Update comments to clarify test objectives - Remove overly complex parameter independence tests 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
What's the failure? |
| # Tuple, etc.) are technically structs but should use copy() or return as-is. | ||
| if Base.isstructtype(T) && !_is_basic_julia_type(T) | ||
| if Base.ismutabletype(T) | ||
| error("recursivecopy for mutable structs is not currently implemented. Use deepcopy instead.") |
|
I think at this point it should probably just be a library. I can't think of a good name, mediumcopy? 😅 specializedcopy? |
|
I'm also becoming increasingly less certain that it's sensible to try to write a version that works for arbitrary struct compositions. Perhaps it would make more sense to specialize on a few types that we know may shows up in sciml solution structs. |
|
What are you running into? What we really need is SciMLProblem and SciMLSolutions to be supported. |
|
What about EDIT: Yes seems to be about 4x slower. using LinearSolve, Serialization, BenchmarkTools
prob = LinearProblem(rand(1000, 1000), rand(1000))
cache = init(prob, LinearSolve.GenericLUFactorization())
mycopy(s) = let buf = IOBuffer()
serialize(buf, s)
seekstart(buf)
deserialize(buf)
end
@btime mycopy(cache) # 1.4ms
@btime deepcopy(cache) # 360μsAlso, it doesn't seem to |
Only supports mutable structs, and has to have extra logic to dispatch on basic types...
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
Additional context
This problem came up as part of SciML/LinearSolve.jl#648 and it a first draft of solving the issue. However, the current handling of the Julia special types is perhaps not perfect yet. Also the code path for normal types is now a bit more difficult to follow, and we explicitly don't allow copying mutable structs. Was that allowed before? In that case we can also just call
deepcopyif it is mutable.