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: several HomotopyNonlinearFunction fixes #899

Merged
merged 4 commits into from
Jan 3, 2025
Merged
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
24 changes: 21 additions & 3 deletions src/scimlfunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1786,7 +1786,7 @@
$(FIELDS)
"""
struct HomotopyNonlinearFunction{iip, specialize, F, P, Q, D} <:
SciMLBase.AbstractSciMLFunction{iip}
SciMLBase.AbstractNonlinearFunction{iip}
"""
The polynomial function `f`. Stored as a `NonlinearFunction{iip, specialize}`. If not
provided to the constructor as a `NonlinearFunction`, it will be appropriately wrapped.
Expand All @@ -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 @@ -2467,6 +2467,7 @@

(f::ODEFunction)(args...) = f.f(args...)
(f::NonlinearFunction)(args...) = f.f(args...)
(f::HomotopyNonlinearFunction)(args...) = f.f(args...)
(f::IntervalNonlinearFunction)(args...) = f.f(args...)
(f::IntegralFunction)(args...) = f.f(args...)
(f::BatchIntegralFunction)(args...) = f.f(args...)
Expand Down Expand Up @@ -4013,9 +4014,10 @@
polynomialize = __has_polynomialize(f) ? f.polynomialize : DEFAULT_POLYNOMIALIZE,
unpolynomialize = __has_unpolynomialize(f) ? f.unpolynomialize :
DEFAULT_UNPOLYNOMIALIZE,
denominator = __has_denominator(f) ? f.denominator : Returns(())
denominator = __has_denominator(f) ? f.denominator : Returns(()),
kwargs...
) where {iip, specialize}
f = f isa NonlinearFunction ? f : NonlinearFunction{iip, specialize}(f)
f = f isa NonlinearFunction ? f : NonlinearFunction{iip, specialize}(f; kwargs...)

if specialize === NoSpecialize
HomotopyNonlinearFunction{iip, specialize, Any, Any, Any, Any}(
Expand Down Expand Up @@ -4853,6 +4855,22 @@
SymbolicIndexingInterface.observed(symbolic_container(fn), sym)
end

function Base.getproperty(x::HomotopyNonlinearFunction, sym::Symbol)
if hasfield(HomotopyNonlinearFunction, sym)
return getfield(x, sym)
elseif hasfield(NonlinearFunction, sym)
return getfield(getfield(x, :f), sym)
elseif (sym == :initializeprob || sym == :update_initializeprob! ||
sym == :initializeprobmap || sym == :initializeprobpmap)
f = getfield(x, :f)
if f.initialization_data === nothing
return nothing
else
return getproperty(f.initialization_data, sym)
end
end
end

function Base.getproperty(x::AbstractSciMLFunction, sym::Symbol)
if __has_initialization_data(x) &&
(sym == :initializeprob || sym == :update_initializeprob! ||
Expand Down
Loading