From 3b0d472276dee3e776ad3fdc456362d60e6f8940 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Fri, 3 Jan 2025 11:29:47 +0530 Subject: [PATCH 1/4] refactor: make `HomotopyNonlinearFunction` an `AbstractNonlinearFunction` --- src/scimlfunctions.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scimlfunctions.jl b/src/scimlfunctions.jl index fdcf4b721..7b65343f2 100644 --- a/src/scimlfunctions.jl +++ b/src/scimlfunctions.jl @@ -1786,7 +1786,7 @@ The fields of the `HomotopyNonlinearFunction` type directly match the names of t $(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. From b8e6aaee98c8f16b4d6887658394a96ce6d8f47d Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Fri, 3 Jan 2025 11:29:58 +0530 Subject: [PATCH 2/4] feat: allow directly calling `HomotopyNonlinearFunction` --- src/scimlfunctions.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/scimlfunctions.jl b/src/scimlfunctions.jl index 7b65343f2..25939eca8 100644 --- a/src/scimlfunctions.jl +++ b/src/scimlfunctions.jl @@ -2467,6 +2467,7 @@ end (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...) From 5850c7ac307bc993190acb4b2268fc334fe9f023 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Fri, 3 Jan 2025 11:30:23 +0530 Subject: [PATCH 3/4] feat: forward `HomotopyNonlinearFunction` kwargs to `NonlinearFunction` --- src/scimlfunctions.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/scimlfunctions.jl b/src/scimlfunctions.jl index 25939eca8..8f103ed00 100644 --- a/src/scimlfunctions.jl +++ b/src/scimlfunctions.jl @@ -4014,9 +4014,10 @@ function HomotopyNonlinearFunction{iip, specialize}(f; 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}( From 88c4b560d393ff62ab26f581d73cceca68934acc Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Fri, 3 Jan 2025 11:30:49 +0530 Subject: [PATCH 4/4] feat: forward `getproperty` on `HomotopyNonlinearFunction` to wrapped `NonlinearFunction` --- src/scimlfunctions.jl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/scimlfunctions.jl b/src/scimlfunctions.jl index 8f103ed00..7b247b5bc 100644 --- a/src/scimlfunctions.jl +++ b/src/scimlfunctions.jl @@ -4855,6 +4855,22 @@ function SymbolicIndexingInterface.observed(fn::HomotopyNonlinearFunction, sym:: 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! ||