Skip to content
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
3 changes: 3 additions & 0 deletions docs/src/tutorials/modelingtoolkit.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ end

The stand-in has to be isbits and has to implement whatever the model calls on it.

Device initialization omits the nonlinear problem's `verbose` keyword, which controls
host logging. Other nonlinear solver keywords are preserved.

The current initialization path has the following restrictions:

- Square, underdetermined, and overdetermined nonlinear least-squares initialization
Expand Down
7 changes: 5 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ function _to_unbounded_initialization(u, lb, ub)
end
end

# Verbosity controls host logging, so device initialization omits it.
_device_initialization_kwargs(; verbose = nothing, kwargs...) = kwargs

function make_nonlinear_problem_compatible(prob::SciMLBase.NonlinearLeastSquaresProblem)
static_u0 = make_static_storage(prob.u0)
static_p = make_parameter_compatible(prob.p)
Expand All @@ -197,7 +200,7 @@ function make_nonlinear_problem_compatible(prob::SciMLBase.NonlinearLeastSquares
compatible_f, static_u0, static_p;
lb = nothing,
ub = nothing,
prob.kwargs...
_device_initialization_kwargs(; prob.kwargs...)...
)
end

Expand All @@ -215,7 +218,7 @@ function make_nonlinear_problem_compatible(
make_static_storage(prob.u0),
make_parameter_compatible(prob.p),
prob.problem_type;
prob.kwargs...
_device_initialization_kwargs(; prob.kwargs...)...
)
end

Expand Down
23 changes: 23 additions & 0 deletions test/gpu_kernel_de/stiff_ode/gpu_ode_modelingtoolkit_dae.jl
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,29 @@ end
# Test 6: Computed initialization maps and the FullSpecialize requirement
# ============================================================================

@testset "Device initialization verbosity" begin
f = SciMLBase.NonlinearFunction{false}((u, p) -> u .- p)
for constructor in (
SciMLBase.NonlinearProblem{false},
SciMLBase.ImmutableNonlinearProblem{false},
SciMLBase.NonlinearLeastSquaresProblem{false},
)
for kwargs in ((;), (; verbose = false), (; verbose = "host logging"))
original = constructor(f, SVector(0.0), SVector(1.0); kwargs...)
compatible = DiffEqGPU.make_nonlinear_problem_compatible(original)
@test isbits(compatible)
@test isempty(compatible.kwargs)
@test (; original.kwargs...) == kwargs
@test compatible.f(compatible.u0, compatible.p) == SVector(-1.0)
end
original = constructor(
f, SVector(0.0), SVector(1.0); verbose = false, maxiters = 7
)
compatible = DiffEqGPU.make_nonlinear_problem_compatible(original)
@test (; compatible.kwargs...) == (; maxiters = 7)
end
end

@testset "Computed initialization maps" begin
# `my` is an observed variable of the torn initialization system, so the state map
# computes it rather than copying it. ModelingToolkit compiles that into the
Expand Down
Loading