Skip to content

Conversation

RomeoV
Copy link

@RomeoV RomeoV commented Jul 29, 2025

Only supports mutable structs, and has to have extra logic to dispatch on basic types...

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

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 deepcopy if it is mutable.

RomeoV added 2 commits July 28, 2025 18:26
Only supports mutable structs, and has to have extra logic to dispatch
on basic types...
@RomeoV
Copy link
Author

RomeoV commented Jul 29, 2025

I tried to swap this into here but that currently fails...

RomeoV and others added 3 commits July 28, 2025 19:19
- 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 <[email protected]>
- 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 <[email protected]>
- 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 <[email protected]>
@ChrisRackauckas
Copy link
Member

I tried to swap this into here but that currently fails...

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.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the issue there?

@ChrisRackauckas
Copy link
Member

I think at this point it should probably just be a library. I can't think of a good name, mediumcopy? 😅 specializedcopy?

@RomeoV
Copy link
Author

RomeoV commented Aug 6, 2025

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.
So that would be more like a white-list approach rather than a black-list approach.

@ChrisRackauckas
Copy link
Member

What are you running into?

What we really need is SciMLProblem and SciMLSolutions to be supported.

@RomeoV
Copy link
Author

RomeoV commented Aug 7, 2025

What about deserialize(serialize(sol))? Is this a stupid idea?
I guess it might be slow...

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μs

Also, it doesn't seem to trim either.

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