Skip to content
Closed
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
107 changes: 0 additions & 107 deletions demo.jl

This file was deleted.

86 changes: 84 additions & 2 deletions src/deprecations.jl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should not be touched

Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,90 @@ for T in [:NonlinearSystem, :DiscreteSystem, :ImplicitDiscreteSystem]
@eval @deprecate $T(args...; kwargs...) System(args...; kwargs...)
end

for T in [:ODEProblem, :DDEProblem, :SDEProblem, :SDDEProblem, :DAEProblem,
:BVProblem, :DiscreteProblem, :ImplicitDiscreteProblem]
# Time-dependent problems with keyword tspan
for T in [:ODEProblem, :SDEProblem, :BVProblem, :DDEProblem, :SDDEProblem]
for (pType, pCanonical) in [
(AbstractDict, :p),
(AbstractArray{<:Pair}, :(Dict(p))),
(AbstractArray, :(isempty(p) ? Dict() : Dict(parameters(sys) .=> p)))
],
(uType, uCanonical) in [
(Nothing, :(Dict())),
(AbstractDict, :u0),
(AbstractArray{<:Pair}, :(Dict(u0))),
(AbstractArray, :(isempty(u0) ? Dict() : Dict(unknowns(sys) .=> u0)))
]

@eval function SciMLBase.$T(sys::System, u0::$uType, tspan, p::$pType; kw...)
ctor = string($T)
uCan = string($(QuoteNode(uCanonical)))
pCan = string($(QuoteNode(pCanonical)))
@warn """
`$ctor(sys, u0, tspan, p; kw...)` is deprecated. Use
`$ctor(sys, merge($uCan, $pCan); tspan=tspan)` instead.
"""
SciMLBase.$T(sys, merge($uCanonical, $pCanonical); tspan=tspan, kw...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
SciMLBase.$T(sys, merge($uCanonical, $pCanonical); tspan=tspan, kw...)
SciMLBase.$T(sys, merge($uCanonical, $pCanonical); tspan = tspan, kw...)

end
@eval function SciMLBase.$T{iip}(
sys::System, u0::$uType, tspan, p::$pType; kw...) where {iip}
ctor = string($T{iip})
uCan = string($(QuoteNode(uCanonical)))
pCan = string($(QuoteNode(pCanonical)))
@warn """
`$ctor(sys, u0, tspan, p; kw...)` is deprecated. Use
`$ctor(sys, merge($uCan, $pCan); tspan=tspan)` instead.
"""
return SciMLBase.$T{iip}(sys, merge($uCanonical, $pCanonical); tspan=tspan, kw...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
return SciMLBase.$T{iip}(sys, merge($uCanonical, $pCanonical); tspan=tspan, kw...)
return SciMLBase.$T{iip}(
sys, merge($uCanonical, $pCanonical); tspan = tspan, kw...)

end
@eval function SciMLBase.$T{iip, spec}(
sys::System, u0::$uType, tspan, p::$pType; kw...) where {iip, spec}
ctor = string($T{iip, spec})
uCan = string($(QuoteNode(uCanonical)))
pCan = string($(QuoteNode(pCanonical)))
@warn """
`$ctor(sys, u0, tspan, p; kw...)` is deprecated. Use
`$ctor(sys, merge($uCan, $pCan); tspan=tspan)` instead.
"""
return $T{iip, spec}(sys, merge($uCanonical, $pCanonical); tspan=tspan, kw...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
return $T{iip, spec}(sys, merge($uCanonical, $pCanonical); tspan=tspan, kw...)
return $T{iip, spec}(sys, merge($uCanonical, $pCanonical); tspan = tspan, kw...)

end
end

for pType in [SciMLBase.NullParameters, Nothing], uType in [Any, Nothing]

@eval function SciMLBase.$T(sys::System, u0::$uType, tspan, p::$pType; kw...)
ctor = string($T)
pT = string($(QuoteNode(pType)))
@warn """
`$ctor(sys, u0, tspan, p::$pT; kw...)` is deprecated. Use
`$ctor(sys, u0; tspan=tspan)` instead.
"""
$T(sys, u0; tspan=tspan, kw...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
$T(sys, u0; tspan=tspan, kw...)
$T(sys, u0; tspan = tspan, kw...)

end
@eval function SciMLBase.$T{iip}(
sys::System, u0::$uType, tspan, p::$pType; kw...) where {iip}
ctor = string($T{iip})
pT = string($(QuoteNode(pType)))
@warn """
`$ctor(sys, u0, tspan, p::$pT; kw...)` is deprecated. Use
`$ctor(sys, u0; tspan=tspan)` instead.
"""
return $T{iip}(sys, u0; tspan=tspan, kw...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
return $T{iip}(sys, u0; tspan=tspan, kw...)
return $T{iip}(sys, u0; tspan = tspan, kw...)

end
@eval function SciMLBase.$T{iip, spec}(
sys::System, u0::$uType, tspan, p::$pType; kw...) where {iip, spec}
ctor = string($T{iip, spec})
pT = string($(QuoteNode(pType)))
@warn """
`$ctor(sys, u0, tspan, p::$pT; kw...)` is deprecated. Use
`$ctor(sys, u0; tspan=tspan)` instead.
"""
return $T{iip, spec}(sys, u0; tspan=tspan, kw...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
return $T{iip, spec}(sys, u0; tspan=tspan, kw...)
return $T{iip, spec}(sys, u0; tspan = tspan, kw...)

end
end
end

# Problems with positional tspan (unchanged)
for T in [:DAEProblem, :DiscreteProblem, :ImplicitDiscreteProblem]
for (pType, pCanonical) in [
(AbstractDict, :p),
(AbstractArray{<:Pair}, :(Dict(p))),
Expand Down
10 changes: 9 additions & 1 deletion src/problems/bvproblem.jl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not try and change our problem constructor syntax. This applies for every file in this subdirectory - the tspan can be optional but it shouldn't be a kwarg. It should default to get_tspan(sys) and the check ensuring it is not nothing should be a function defined somewhere else that it calls in all the relevant problem constructors to ensure we have a consistent implementation and error message.

Also, this just takes the tspan from the system if not explicitly provided, but doesn't do the work of actually handling the case when the tspan is symbolic and needs to be substituted to get a number out. Should mutating the parameters in an instantiated ODEProblem also update the tspan accordingly? Because it doesn't do that. I think tspan can be a function? In which case that is what this should target and we need a dedicated codegen function in codegen.jl.

Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
@fallback_iip_specialize function SciMLBase.BVProblem{iip, spec}(
sys::System, op, tspan;
sys::System, op; tspan = nothing,
check_compatibility = true, cse = true,
checkbounds = false, eval_expression = false, eval_module = @__MODULE__,
expression = Val{false}, guesses = Dict(), callback = nothing,
kwargs...) where {iip, spec}
check_complete(sys, BVProblem)
check_compatibility && check_compatible_system(BVProblem, sys)
isnothing(callback) || error("BVP solvers do not support callbacks.")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

# Use system's tspan as default if not provided
if tspan === nothing
tspan = get_tspan(sys)
if tspan === nothing
throw(ArgumentError("tspan must be provided either as an argument or defined in the system"))
end
end

dvs = unknowns(sys)
op = to_varmap(op, dvs)
Expand Down
10 changes: 9 additions & 1 deletion src/problems/ddeproblem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,20 @@
end

@fallback_iip_specialize function SciMLBase.DDEProblem{iip, spec}(
sys::System, op, tspan;
sys::System, op; tspan = nothing,
callback = nothing, check_length = true, cse = true, checkbounds = false,
eval_expression = false, eval_module = @__MODULE__, check_compatibility = true,
u0_constructor = identity, expression = Val{false}, kwargs...) where {iip, spec}
check_complete(sys, DDEProblem)
check_compatibility && check_compatible_system(DDEProblem, sys)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

# Use system's tspan as default if not provided
if tspan === nothing
tspan = get_tspan(sys)
if tspan === nothing
throw(ArgumentError("tspan must be provided either as an argument or defined in the system"))
end
end

f, u0,
p = process_SciMLProblem(DDEFunction{iip, spec}, sys, op;
Expand Down
10 changes: 9 additions & 1 deletion src/problems/odeproblem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,20 @@
end

@fallback_iip_specialize function SciMLBase.ODEProblem{iip, spec}(
sys::System, op, tspan;
sys::System, op; tspan = nothing,
callback = nothing, check_length = true, eval_expression = false,
expression = Val{false}, eval_module = @__MODULE__, check_compatibility = true,
kwargs...) where {iip, spec}
check_complete(sys, ODEProblem)
check_compatibility && check_compatible_system(ODEProblem, sys)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

# Use system's tspan as default if not provided
if tspan === nothing
tspan = get_tspan(sys)
if tspan === nothing
throw(ArgumentError("tspan must be provided either as an argument or defined in the system"))
end
end

f, u0,
p = process_SciMLProblem(ODEFunction{iip, spec}, sys, op;
Expand Down
10 changes: 9 additions & 1 deletion src/problems/sddeproblem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,21 @@
end

@fallback_iip_specialize function SciMLBase.SDDEProblem{iip, spec}(
sys::System, op, tspan;
sys::System, op; tspan = nothing,
callback = nothing, check_length = true, cse = true, checkbounds = false,
eval_expression = false, eval_module = @__MODULE__, check_compatibility = true,
u0_constructor = identity, sparse = false, sparsenoise = sparse,
expression = Val{false}, kwargs...) where {iip, spec}
check_complete(sys, SDDEProblem)
check_compatibility && check_compatible_system(SDDEProblem, sys)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

# Use system's tspan as default if not provided
if tspan === nothing
tspan = get_tspan(sys)
if tspan === nothing
throw(ArgumentError("tspan must be provided either as an argument or defined in the system"))
end
end

f, u0,
p = process_SciMLProblem(SDDEFunction{iip, spec}, sys, op;
Expand Down
10 changes: 9 additions & 1 deletion src/problems/sdeproblem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,20 @@
end

@fallback_iip_specialize function SciMLBase.SDEProblem{iip, spec}(
sys::System, op, tspan;
sys::System, op; tspan = nothing,
callback = nothing, check_length = true, eval_expression = false,
eval_module = @__MODULE__, check_compatibility = true, sparse = false,
sparsenoise = sparse, expression = Val{false}, kwargs...) where {iip, spec}
check_complete(sys, SDEProblem)
check_compatibility && check_compatible_system(SDEProblem, sys)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

# Use system's tspan as default if not provided
if tspan === nothing
tspan = get_tspan(sys)
if tspan === nothing
throw(ArgumentError("tspan must be provided either as an argument or defined in the system"))
end
end

f, u0,
p = process_SciMLProblem(SDEFunction{iip, spec}, sys, op;
Expand Down
13 changes: 9 additions & 4 deletions src/systems/system.jl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds the field to the system, but does not handle it in flatten and the other functions that operate on (hierarchical) systems.

Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ struct System <: IntermediateDeprecationSystem
"""
tstops::Vector{Any}
"""
The time span for time-dependent systems. This is a tuple of the start and end
time for the system, which can be symbolic expressions involving parameters.
"""
tspan::Union{Nothing, Tuple{Any, Any}}
"""
The `TearingState` of the system post-simplification with `mtkcompile`.
"""
tearing_state::Any
Expand Down Expand Up @@ -256,7 +261,7 @@ struct System <: IntermediateDeprecationSystem
defaults, guesses, systems, initialization_eqs, continuous_events, discrete_events,
connector_type, assertions = Dict{BasicSymbolic, String}(),
metadata = MetadataT(), gui_metadata = nothing,
is_dde = false, tstops = [], tearing_state = nothing, namespacing = true,
is_dde = false, tstops = [], tspan = nothing, tearing_state = nothing, namespacing = true,
complete = false, index_cache = nothing, ignored_connections = nothing,
preface = nothing, parent = nothing, initializesystem = nothing,
is_initializesystem = false, is_discrete = false, isscheduled = false,
Expand Down Expand Up @@ -296,7 +301,7 @@ struct System <: IntermediateDeprecationSystem
observed, parameter_dependencies, var_to_name, name, description, defaults,
guesses, systems, initialization_eqs, continuous_events, discrete_events,
connector_type, assertions, metadata, gui_metadata, is_dde,
tstops, tearing_state, namespacing, complete, index_cache, ignored_connections,
tstops, tspan, tearing_state, namespacing, complete, index_cache, ignored_connections,
preface, parent, initializesystem, is_initializesystem, is_discrete,
isscheduled, schedule)
end
Expand Down Expand Up @@ -332,7 +337,7 @@ function System(eqs::Vector{Equation}, iv, dvs, ps, brownians = [];
continuous_events = SymbolicContinuousCallback[], discrete_events = SymbolicDiscreteCallback[],
connector_type = nothing, assertions = Dict{BasicSymbolic, String}(),
metadata = MetadataT(), gui_metadata = nothing,
is_dde = nothing, tstops = [], tearing_state = nothing,
is_dde = nothing, tstops = [], tspan = nothing, tearing_state = nothing,
ignored_connections = nothing, parent = nothing,
description = "", name = nothing, discover_from_metadata = true,
initializesystem = nothing, is_initializesystem = false, is_discrete = false,
Expand Down Expand Up @@ -417,7 +422,7 @@ function System(eqs::Vector{Equation}, iv, dvs, ps, brownians = [];
costs, consolidate, dvs, ps, brownians, iv, observed, Equation[],
var_to_name, name, description, defaults, guesses, systems, initialization_eqs,
continuous_events, discrete_events, connector_type, assertions, metadata, gui_metadata, is_dde,
tstops, tearing_state, true, false, nothing, ignored_connections, preface, parent,
tstops, tspan, tearing_state, true, false, nothing, ignored_connections, preface, parent,
initializesystem, is_initializesystem, is_discrete; checks)
end

Expand Down
Loading
Loading