What is the interface for the "initial guess" function as 3rd argument of BVProblem?

Hello,
I’m coding a solver for a set of three coupled highly nonlinear differential equations.
This problem offers a huge complex solution space in which any solver is likely to become lost without reasonable “initial guesses” for all 3 functions over the entire t-span, which I have easily coded. It seems that an ideal solver could be a collocation method — Fully Implicit Runge Kutta (FIRK), because it is said to allow such guess vectors. I have selected the RadauIIA5 solver.
My problem is that the quite nice documentation for BVProblem seems incomplete regarding
the interface for providing this initial guess. The template code is…

BVProblem{isinplace}(f, bc, initialGuess, tspan, p=NullParameters(); kwargs...) 

A “…bvp_types” page says: initialGuess can be “Vector of values for u(t) for collocation methods”, but how do I receive/provide the t vector?
And a “…bvp_example” page says “The initial guess can also be supplied via a function of t or a previous solution type…” but without specifying the interface, including the arguments of this function.
This is made clear about the “bc” function for boundary conditions, but that function has a first argument that doesn’t apply to the initial guess.
When I try to guess the function arguments, I get an error message saying that the iterator used by the solver to obtain the initial guess doesn’t understand the Type of my function.

I hope someone can idenify the missing information.

thanks!

Andy

Thanks for your quick reply!
But it seems to leave uncertainty…

You don’t mention the parameter tuple “par” that usually is needed by any such function, such as the “bc” function used to specify boundary conditions — argument #2 of BVProblem:

function bcond!(resid, sol, par, t)
par1, par2, par3 = par
resident[1] = par1*t^2
—etc—
end

Such a “par” may also be needed by your initialGuess(t) example. It is needed in my case. Of course, I tried initialGuess(par,t) , but that resulted in the iterator error that I mentioned. That error still appears if I omit “par”, resulting essentially what you suggest. So a single argument seems incomplete.


**ERROR:** MethodError: no method matching iterate(::typeof(initialGuess))
The function `iterate` exists, but no method is defined for this combination of argument types.

Closest candidates are:
iterate(::Expronicon.JLMatch)
@ Expronicon ~/.julia/packages/Expronicon/Oa1rJ/src/match.jl:139
iterate(::Expronicon.JLMatch, ::Any)
@ Expronicon ~/.julia/packages/Expronicon/Oa1rJ/src/match.jl:139
iterate(::DataStructures.EnumerateAll)
@ DataStructures ~/.julia/packages/DataStructures/95DJa/src/multi_dict.jl:98
...

Stacktrace:
[1] **isempty(**itr::Function**)**
@ Base ./essentials.jl:1121
[2] **norm(**itr::Function, p::Int64**)**
@ LinearAlgebra ~/.julia/juliaup/julia-1.11.2+0.x64.apple.darwin14/share/julia/stdlib/v1.11/LinearAlgebra/src/generic.jl:602
[3] **ODE_DEFAULT_NORM(**u::Function, t::Float64**)**
@ DiffEqBase ~/.julia/packages/DiffEqBase/slKc5/src/common_defaults.jl:83
[4] **__init(**prob::BVProblem{…}, alg::RadauIIA5{…}, timeseries_init::Tuple{}, ts_init::Tuple{}, ks_init::Tuple{}, recompile::Type{…}; saveat::Tuple{}, tstops::Tuple{}, d_discontinuities::Tuple{}, save_idxs::Nothing, save_everystep::Bool, save_on::Bool, save_start::Bool, save_end::Nothing, callback::Nothing, dense::Bool, calck::Bool, dt::Float64, dtmin::Float64, dtmax::Float64, force_dtmin::Bool, adaptive::Bool, gamma::Rational{…}, abstol::Float64, reltol::Float64, qmin::Rational{…}, qmax::Int64, qsteady_min::Int64, qsteady_max::Rational{…}, beta1::Nothing, beta2::Nothing, qoldinit::Rational{…}, controller::Nothing, fullnormalize::Bool, failfactor::Int64, maxiters::Int64, internalnorm::typeof(DiffEqBase.ODE_DEFAULT_NORM), internalopnorm::typeof(opnorm), isoutofdomain::typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), unstable_check::typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), verbose::Bool, timeseries_errors::Bool, dense_errors::Bool, advance_to_tstop::Bool, stop_at_next_tstop::Bool, initialize_save::Bool, progress::Bool, progress_steps::Int64, progress_name::String, progress_message::typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), progress_id::Symbol, userdata::Nothing, allow_extrapolation::Bool, initialize_integrator::Bool, alias_u0::Bool, alias_du0::Bool, initializealg::OrdinaryDiffEqCore.DefaultInit, kwargs::@Kwargs{}**)**
@ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/hCoet/src/solve.jl:326
[5] **__solve(**::BVProblem{…}, ::RadauIIA5{…}; kwargs::@Kwargs{…}**)**
@ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/hCoet/src/solve.jl:6
[6] **solve_call(**_prob::BVProblem{…}, args::RadauIIA5{…}; merge_callbacks::Bool, kwargshandle::Nothing, kwargs::@Kwargs{…}**)**
@ DiffEqBase ~/.julia/packages/DiffEqBase/slKc5/src/solve.jl:612
[7] **solve_up(**prob::BVProblem{…}, sensealg::Nothing, u0::Function, p::Tuple{…}, args::RadauIIA5{…}; kwargs::@Kwargs{…}**)**
@ DiffEqBase ~/.julia/packages/DiffEqBase/slKc5/src/solve.jl:1080
[8] **solve(**prob::BVProblem{…}, args::RadauIIA5{…}; sensealg::Nothing, u0::Nothing, p::Nothing, wrap::Val{…}, kwargs::@Kwargs{…}**)**
@ DiffEqBase ~/.julia/packages/DiffEqBase/slKc5/src/solve.jl:1003
[9] **integrate_star(**eos::Sim{…}, M::Float64, rμ::Float64, pf::Float64**)**
@ Main ~/Applications/Julia/RealisticSeismology-main/src/RealMod/src/shtar.jl:99
[10] **Shtar(**eos::Sim{…}, Madm::Float64, pf::Float64**)**
@ Main ~/Applications/Julia/RealisticSeismology-main/src/RealMod/src/shtar.jl:157
[11] top-level scope
@ REPL[333]:1
Some type information was truncated. Use `show(err)` to see complete types.

p.s.: your reply does not appear in this topic, when I click “Visit Topic” at the bottom of your message. And I enabled notifications, etc.

Andy

I offer here a quasi-minimal example of the latest iterator failure.
I also tried the RadauIIA3 solver, getting the same result.
By the way, there seems to be two different versions of the RadauIIA5 solver with the same name — one in BoundaryValueDiffEq, and one in OrdinaryDiffEqFIRK that is incomparible with BVProblem.

Only the last 2 lines of this are important — most of the rest is context.

using BoundaryValueDiffEq  

function f!(dy_dr, y, par, t)
    y1, y2 = y
    par1, par2 = par 

    dy_dt[1] = 2*y1 + t*par1
    dy_dt[2] = 3*y2 - t/par2

    dy_dt
end

function initialGuess(t)

# Would be nice to have access here to parameters in par, as in bc!  

    guess1 = t^2 
    guess2 = t^3 

    [guess1, guess2]
end

function bc!(resid, y, par, t)
#  y[1,i] & y[2,i] were evaluated at t[i]

    par1, par2 = par 

    resid[1] = abs(y[1,1] - par1)
    resid[2] = abs(y[2,end] - par2) 
end

tspan = (0.0, 50.0)

par = (1.0, 2.0)

bvp = BVProblem(f!, bc!, initialGuess, tspan, par)

sol = solve(bvp, RadauIIA5(); abstol=1e-2, reltol=1e-2) 

which produced this…

**ERROR:** LoadError: ArgumentError: Package BoundaryValueDiffEqFIRK not found in current path.

- Run `import Pkg; Pkg.add("BoundaryValueDiffEqFIRK")` to install the BoundaryValueDiffEqFIRK package.

Stacktrace:

[1] **macro expansion**

@ ./loading.jl:2296 [inlined]

[2] **macro expansion**

@ ./lock.jl:273 [inlined]

[3] **__require(**into::Module, mod::Symbol**)**

@ Base ./loading.jl:2271

[4] **#invoke_in_world#3**

@ ./essentials.jl:1089 [inlined]

[5] **invoke_in_world**

@ ./essentials.jl:1086 [inlined]

[6] **require(**into::Module, mod::Symbol**)**

@ Base ./loading.jl:2260

[7] **include(**fname::String**)**

@ Main ./sysimg.jl:38

[8] top-level scope

@ REPL[366]:1

in expression starting at /Users/andy 1/Applications/Julia/RealisticSeismology-main/BVProblem,Example1.jl:2

**julia>** include("../../../BVProblem,Example1.jl")

**ERROR:** LoadError: MethodError: no method matching iterate(::typeof(initialGuess))

The function `iterate` exists, but no method is defined for this combination of argument types.

Closest candidates are:

iterate(::Expronicon.JLMatch)

@ Expronicon ~/.julia/packages/Expronicon/Oa1rJ/src/match.jl:139

iterate(::Expronicon.JLMatch, ::Any)

@ Expronicon ~/.julia/packages/Expronicon/Oa1rJ/src/match.jl:139

iterate(::DataStructures.EnumerateAll)

@ DataStructures ~/.julia/packages/DataStructures/95DJa/src/multi_dict.jl:98

...

Stacktrace:

[1] **isempty(**itr::Function**)**

@ Base ./essentials.jl:1121

[2] **norm(**itr::Function, p::Int64**)**

@ LinearAlgebra ~/.julia/juliaup/julia-1.11.2+0.x64.apple.darwin14/share/julia/stdlib/v1.11/LinearAlgebra/src/generic.jl:602

[3] **ODE_DEFAULT_NORM(**u::Function, t::Float64**)**

@ DiffEqBase ~/.julia/packages/DiffEqBase/slKc5/src/common_defaults.jl:83

[4] **__init(**prob::BVProblem{…}, alg::RadauIIA5{…}, timeseries_init::Tuple{}, ts_init::Tuple{}, ks_init::Tuple{}, recompile::Type{…}; saveat::Tuple{}, tstops::Tuple{}, d_discontinuities::Tuple{}, save_idxs::Nothing, save_everystep::Bool, save_on::Bool, save_start::Bool, save_end::Nothing, callback::Nothing, dense::Bool, calck::Bool, dt::Float64, dtmin::Float64, dtmax::Float64, force_dtmin::Bool, adaptive::Bool, gamma::Rational{…}, abstol::Float64, reltol::Float64, qmin::Rational{…}, qmax::Int64, qsteady_min::Int64, qsteady_max::Rational{…}, beta1::Nothing, beta2::Nothing, qoldinit::Rational{…}, controller::Nothing, fullnormalize::Bool, failfactor::Int64, maxiters::Int64, internalnorm::typeof(DiffEqBase.ODE_DEFAULT_NORM), internalopnorm::typeof(opnorm), isoutofdomain::typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), unstable_check::typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), verbose::Bool, timeseries_errors::Bool, dense_errors::Bool, advance_to_tstop::Bool, stop_at_next_tstop::Bool, initialize_save::Bool, progress::Bool, progress_steps::Int64, progress_name::String, progress_message::typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), progress_id::Symbol, userdata::Nothing, allow_extrapolation::Bool, initialize_integrator::Bool, alias_u0::Bool, alias_du0::Bool, initializealg::OrdinaryDiffEqCore.DefaultInit, kwargs::@Kwargs{}**)**

@ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/hCoet/src/solve.jl:326

[5] **__solve(**::BVProblem{…}, ::RadauIIA5{…}; kwargs::@Kwargs{…}**)**

@ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/hCoet/src/solve.jl:6

[6] **solve_call(**_prob::BVProblem{…}, args::RadauIIA5{…}; merge_callbacks::Bool, kwargshandle::Nothing, kwargs::@Kwargs{…}**)**

@ DiffEqBase ~/.julia/packages/DiffEqBase/slKc5/src/solve.jl:612

[7] **solve_up(**prob::BVProblem{…}, sensealg::Nothing, u0::Function, p::Tuple{…}, args::RadauIIA5{…}; kwargs::@Kwargs{…}**)**

@ DiffEqBase ~/.julia/packages/DiffEqBase/slKc5/src/solve.jl:1080

[8] **solve(**prob::BVProblem{…}, args::RadauIIA5{…}; sensealg::Nothing, u0::Nothing, p::Nothing, wrap::Val{…}, kwargs::@Kwargs{…}**)**

@ DiffEqBase ~/.julia/packages/DiffEqBase/slKc5/src/solve.jl:1003

[9] top-level scope

@ ~/Applications/Julia/RealisticSeismology-main/BVProblem,Example1.jl:39

[10] **include(**fname::String**)**

@ Main ./sysimg.jl:38

[11] top-level scope

@ REPL[366]:1

in expression starting at /Users/andy 1/Applications/Julia/RealisticSeismology-main/BVProblem,Example1.jl:39

Some type information was truncated. Use `show(err)` to see complete types.