Skip to content

Commit 5a4bbc1

Browse files
feat: allow specifying problem_type using system metadata
1 parent 7d330f4 commit 5a4bbc1

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/problems/nonlinearproblem.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ end
6767
check_length, check_compatibility, expression, kwargs...)
6868

6969
kwargs = process_kwargs(sys; kwargs...)
70-
args = (; f, u0, p, ptype = StandardNonlinearProblem())
70+
ptype = getmetadata(sys, ProblemTypeCtx, StandardNonlinearProblem())
71+
args = (; f, u0, p, ptype)
7172

7273
return maybe_codegen_scimlproblem(expression, NonlinearProblem{iip}, args; kwargs...)
7374
end

src/problems/odeproblem.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ end
7777
kwargs = process_kwargs(
7878
sys; expression, callback, eval_expression, eval_module, kwargs...)
7979

80-
args = (; f, u0, tspan, p, ptype = StandardODEProblem())
80+
ptype = getmetadata(sys, ProblemTypeCtx, StandardODEProblem())
81+
args = (; f, u0, tspan, p, ptype)
8182
maybe_codegen_scimlproblem(expression, ODEProblem{iip}, args; kwargs...)
8283
end
8384

src/systems/system.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,16 @@ function SymbolicUtils.setmetadata(sys::AbstractSystem, k::DataType, v)
807807
@set sys.metadata = meta
808808
end
809809

810+
"""
811+
$(TYPEDSIGNATURES)
812+
813+
Metadata key for systems containing the `problem_type` to be passed to the problem
814+
constructor, where applicable. For example, if `getmetadata(sys, ProblemTypeCtx, nothing)`
815+
is `CustomType()` then `ODEProblem(sys, ...).problem_type` will be `CustomType()` instead
816+
of `StandardODEProblem`.
817+
"""
818+
struct ProblemTypeCtx end
819+
810820
"""
811821
$(TYPEDSIGNATURES)
812822
"""

0 commit comments

Comments
 (0)