Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix remake(::HomotopyNonlinearFunction) #923

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/remake.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,19 @@ function remake(
if !(f isa Union{AbstractSciMLOperator, split_function_f_wrapper(T)})
f = split_function_f_wrapper(T){iip, spec}(f)
end
# For SplitFunction
# we don't do the same thing as `g`, because for SDEs `g` is
# stored in the problem as well, whereas for Split ODEs etc
# f2 is a part of the function. Thus, if the user provides
# a SciMLFunction for `f` which contains `f2` we use that.
f2 = coalesce(f2, get(props, :f2, missing), func.f2)
if !(f2 isa Union{AbstractSciMLOperator, split_function_f_wrapper(T)})
f2 = split_function_f_wrapper(T){iip, spec}(f2)
if hasproperty(func, :f2)
# For SplitFunction
# we don't do the same thing as `g`, because for SDEs `g` is
# stored in the problem as well, whereas for Split ODEs etc
# f2 is a part of the function. Thus, if the user provides
# a SciMLFunction for `f` which contains `f2` we use that.
f2 = coalesce(f2, get(props, :f2, missing), func.f2)
if !(f2 isa Union{AbstractSciMLOperator, split_function_f_wrapper(T)})
f2 = split_function_f_wrapper(T){iip, spec}(f2)
end
props = @delete props.f2
args = (args..., f2)
end
props = @delete props.f2
args = (args..., f2)
end
if isdefined(func, :g)
# For SDEs/SDDEs where `g` is not a keyword
Expand Down
3 changes: 2 additions & 1 deletion src/scimlfunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1805,7 +1805,7 @@
In the above example, it will be the function:

```julia
functon polynomialize(u, p)

Check warning on line 1808 in src/scimlfunctions.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"functon" should be "function".
x, y = u
return [sin(x^2), log(x + y)]
end
Expand Down Expand Up @@ -4757,7 +4757,7 @@
is_split_function(::Type) = false
function is_split_function(::Type{T}) where {T <: Union{
SplitFunction, SplitSDEFunction, DynamicalODEFunction,
DynamicalDDEFunction, DynamicalSDEFunction}}
DynamicalDDEFunction, DynamicalSDEFunction, HomotopyNonlinearFunction}}
true
end

Expand All @@ -4766,6 +4766,7 @@
split_function_f_wrapper(::Type{<:DynamicalODEFunction}) = ODEFunction
split_function_f_wrapper(::Type{<:DynamicalDDEFunction}) = DDEFunction
split_function_f_wrapper(::Type{<:DynamicalSDEFunction}) = DDEFunction
split_function_f_wrapper(::Type{<:HomotopyNonlinearFunction}) = NonlinearFunction

######### Additional traits

Expand Down
20 changes: 20 additions & 0 deletions test/remake_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,23 @@ end
prob2 = remake(prob; f = fn2)
@test prob2.f.resid_prototype isa Vector{Float32}
end

@testset "`remake(::HomotopyNonlinearFunction)`" begin
f! = function (du, u, p)
du[1] = u[1] * u[1] - p[1] * u[2] + u[2]^3 + 1
du[2] = u[2]^3 + 2 * p[2] * u[1] * u[2] + u[2]
end

fjac! = function (j, u, p)
j[1, 1] = 2u[1]
j[1, 2] = -p[1] + 3 * u[2]^2
j[2, 1] = 2 * p[2] * u[2]
j[2, 2] = 3 * u[2]^2 + 2 * p[2] * u[1] + 1
end
fn = NonlinearFunction(f!; jac = fjac!)
fn = HomotopyNonlinearFunction(fn)
prob = NonlinearProblem(fn, ones(2), ones(2))
@test prob.f.f.jac == fjac!
prob2 = remake(prob; u0 = zeros(2))
@test prob2.f.f.jac == fjac!
end
Loading