Skip to content

Conversation

@ChrisRackauckas-Claude
Copy link

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Sep 2, 2025

Summary

  • Fixes FunctionOperator copy method to properly handle nothing values for u and p parameters
  • Resolves CI failures in LinearSolve.jl PR #763 when copying FunctionOperators with nothing values

Problem

LinearSolve.jl PR #763 replaced deepcopy with copy in the initialization path to improve performance and enable trimming optimizations. However, the FunctionOperator.copy method was attempting to call copy(L.u) and deepcopy(L.p) even when L.u or L.p were nothing, causing MethodError exceptions.

Root Cause

The issue was in src/func.jl lines 450-451:

isdefined(L, :u) ? copy(L.u) : nothing,
isdefined(L, :p) ? deepcopy(L.p) : nothing,

This code checked if the fields were defined but didn't check if they were nothing before attempting to copy them.

Solution

Fixed the copy method to check for nothing values before attempting to copy:

isdefined(L, :u) && L.u !== nothing ? copy(L.u) : nothing,
isdefined(L, :p) && L.p !== nothing ? deepcopy(L.p) : nothing,

Testing

  • All existing copy tests pass (26/26)
  • Tested FunctionOperator copy with nothing values for u and p
  • Tested FunctionOperator copy with actual values to ensure deep copying still works
  • Verified no regression in functionality

Benefits

  • Fixes MethodError when copying FunctionOperators with nothing parameters
  • Enables LinearSolve.jl performance improvements from replacing deepcopy with copy
  • Maintains proper deep copying behavior for non-nothing values
  • No breaking changes to existing functionality

🤖 Generated with Claude Code

ChrisRackauckas and others added 3 commits September 1, 2025 23:26
This adds a fallback copy method for AbstractSciMLOperator that provides
safe copying behavior for operators that don't have specific copy methods
defined. This prevents issues when LinearSolve.jl tries to copy operators
in the initialization path, addressing CI failures in LinearSolve.jl PR #763.

The fallback method:
- For convertible operators: Creates a new operator from the copied concrete representation
- For non-convertible operators: Falls back to deepcopy as a last resort
- Includes appropriate warnings when using fallback behavior

This ensures all SciMLOperators have a copy method available, preventing
MethodError exceptions when copy() is called on complex operator types.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
The FunctionOperator copy method was attempting to copy L.u and deepcopy L.p
even when they were nothing, which causes errors. This fixes the copy method
to check if the values are nothing before attempting to copy them.

Changes:
- Check L.u !== nothing before calling copy(L.u)
- Check L.p !== nothing before calling deepcopy(L.p)

This prevents MethodError when copying FunctionOperators with nothing
values for u or p parameters.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
The issue was specifically in FunctionOperator's copy method trying to copy
nothing values, not a missing fallback. Removing the unnecessary fallback
method that was added earlier.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@ChrisRackauckas ChrisRackauckas merged commit 9f83776 into SciML:master Sep 2, 2025
13 of 15 checks passed
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