Skip to content

Commit

Permalink
Merge pull request #2405 from isaacsas/fix_some_warnings
Browse files Browse the repository at this point in the history
Fix some warnings
  • Loading branch information
ChrisRackauckas authored Dec 31, 2023
2 parents 23323bc + 55d95ae commit df4b7e5
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 29 deletions.
8 changes: 4 additions & 4 deletions ext/MTKBifurcationKitExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ struct ObservableRecordFromSolution{S, T}
param_end_idxs = state_end_idxs + length(parameters(nsys))

bif_par_idx = state_end_idxs + bif_idx
# Gets the (base) substitution values for states.
# Gets the (base) substitution values for states.
subs_vals_states = Pair.(states(nsys), u0_vals)
# Gets the (base) substitution values for parameters.
# Gets the (base) substitution values for parameters.
subs_vals_params = Pair.(parameters(nsys), p_vals)
# Gets the (base) substitution values for observables.
# Gets the (base) substitution values for observables.
subs_vals_obs = [obs.lhs => substitute(obs.rhs,
[subs_vals_states; subs_vals_params]) for obs in observed(nsys)]
# Sometimes observables depend on other observables, hence we make a second update to this vector.
Expand Down Expand Up @@ -136,7 +136,7 @@ function BifurcationKit.BifurcationProblem(osys::ODESystem, args...; kwargs...)
nsys = NonlinearSystem([0 ~ eq.rhs for eq in equations(osys)],
states(osys),
parameters(osys);
name = osys.name)
name = nameof(osys))
return BifurcationKit.BifurcationProblem(nsys, args...; kwargs...)
end

Expand Down
2 changes: 1 addition & 1 deletion src/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function split_parameters_by_type(ps)
split_ps = tighten_types.(Base.Fix1(getindex, ps).(split_idxs))

if ps isa StaticArray
parrs = map(x-> SArray{Tuple{size(x)...}}(x), split_ps)
parrs = map(x -> SArray{Tuple{size(x)...}}(x), split_ps)
split_ps = SArray{Tuple{size(parrs)...}}(parrs)
end
if length(split_ps) == 1 #Tuple not needed, only 1 type
Expand Down
14 changes: 9 additions & 5 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ end
function SymbolicIndexingInterface.is_variable(sys::AbstractSystem, sym::Symbol)
return any(isequal(sym), getname.(variable_symbols(sys))) ||
count('', string(sym)) == 1 &&
count(isequal(sym), Symbol.(sys.name, :₊, getname.(variable_symbols(sys)))) == 1
count(isequal(sym), Symbol.(nameof(sys), :₊, getname.(variable_symbols(sys)))) ==
1
end

function SymbolicIndexingInterface.variable_index(sys::AbstractSystem, sym)
Expand All @@ -213,7 +214,8 @@ function SymbolicIndexingInterface.variable_index(sys::AbstractSystem, sym::Symb
if idx !== nothing
return idx
elseif count('', string(sym)) == 1
return findfirst(isequal(sym), Symbol.(sys.name, :₊, getname.(variable_symbols(sys))))
return findfirst(isequal(sym),
Symbol.(nameof(sys), :₊, getname.(variable_symbols(sys))))
end
return nothing
end
Expand All @@ -236,7 +238,8 @@ end
function SymbolicIndexingInterface.is_parameter(sys::AbstractSystem, sym::Symbol)
return any(isequal(sym), getname.(parameter_symbols(sys))) ||
count('', string(sym)) == 1 &&
count(isequal(sym), Symbol.(sys.name, :₊, getname.(parameter_symbols(sys)))) == 1
count(isequal(sym),
Symbol.(nameof(sys), :₊, getname.(parameter_symbols(sys)))) == 1
end

function SymbolicIndexingInterface.parameter_index(sys::AbstractSystem, sym)
Expand All @@ -255,7 +258,8 @@ function SymbolicIndexingInterface.parameter_index(sys::AbstractSystem, sym::Sym
if idx !== nothing
return idx
elseif count('', string(sym)) == 1
return findfirst(isequal(sym), Symbol.(sys.name, :₊, getname.(parameter_symbols(sys))))
return findfirst(isequal(sym),
Symbol.(nameof(sys), :₊, getname.(parameter_symbols(sys))))
end
return nothing
end
Expand Down Expand Up @@ -656,7 +660,7 @@ function states(sys::AbstractSystem)
end
isempty(nonunique_states) && return nonunique_states
# `Vector{Any}` is incompatible with the `SymbolicIndexingInterface`, which uses
# `elsymtype = symbolic_type(eltype(_arg))`
# `elsymtype = symbolic_type(eltype(_arg))`
# which inappropriately returns `NotSymbolic()`
if nonunique_states isa Vector{Any}
nonunique_states = _nonum.(nonunique_states)
Expand Down
5 changes: 4 additions & 1 deletion src/systems/diffeqs/abstractodesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,10 @@ function DiffEqBase.ODEProblem(sys::AbstractODESystem, args...; kwargs...)
ODEProblem{true}(sys, args...; kwargs...)
end

function DiffEqBase.ODEProblem(sys::AbstractODESystem, u0map::StaticArray, args...; kwargs...)
function DiffEqBase.ODEProblem(sys::AbstractODESystem,
u0map::StaticArray,
args...;
kwargs...)
ODEProblem{false, SciMLBase.FullSpecialize}(sys, u0map, args...; kwargs...)
end

Expand Down
2 changes: 0 additions & 2 deletions src/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ function varmap_to_vars(varmap, varlist; defaults = Dict(), check = true,
container_type = Array
end

@show container_type

vals = if eltype(varmap) <: Pair # `varmap` is a dict or an array of pairs
varmap = todict(varmap)
_varmap_to_vars(varmap, varlist; defaults = defaults, check = check,
Expand Down
2 changes: 1 addition & 1 deletion test/inversemodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ sol = solve(prob, Rodas5P())
# plot(sol, idxs=[model.tank.xc, model.tank.xT, model.controller.ctr_output.u], layout=3, sp=[1 2 3])
# hline!([prob[cm.ref.k]], label="ref", sp=1)

@test sol(tspan[2], idxs = cm.tank.xc) getp(prob, cm.ref.k)(prob) atol=1e-2 # Test that the inverse model led to the correct reference
@test sol(tspan[2], idxs = cm.tank.xc)getp(prob, cm.ref.k)(prob) atol=1e-2 # Test that the inverse model led to the correct reference

Sf, simplified_sys = Blocks.get_sensitivity_function(model, :y) # This should work without providing an operating opint containing a dummy derivative
x, p = ModelingToolkit.get_u0_p(simplified_sys, op)
Expand Down
32 changes: 17 additions & 15 deletions test/symbolic_indexing_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ eqs = [D(x) ~ a * y + t, D(y) ~ b * t]

@test all(is_variable.((odesys,), [x, y, 1, 2, :x, :y]))
@test all(.!is_variable.((odesys,), [a, b, t, 3, 0, :a, :b]))
@test variable_index.((odesys,), [x, y, a, b, t, 1, 2, :x, :y, :a, :b]) == [1, 2, nothing, nothing, nothing, 1, 2, 1, 2, nothing, nothing]
@test variable_index.((odesys,), [x, y, a, b, t, 1, 2, :x, :y, :a, :b]) ==
[1, 2, nothing, nothing, nothing, 1, 2, 1, 2, nothing, nothing]
@test isequal(variable_symbols(odesys), [x, y])
@test all(is_parameter.((odesys,), [a, b, 1, 2, :a, :b]))
@test all(.!is_parameter.((odesys,), [x, y, t, 3, 0, :x, :y]))
@test parameter_index.((odesys,), [x, y, a, b, t, 1, 2, :x, :y, :a, :b]) == [nothing, nothing, 1, 2, nothing, 1, 2, nothing, nothing, 1, 2]
@test parameter_index.((odesys,), [x, y, a, b, t, 1, 2, :x, :y, :a, :b]) ==
[nothing, nothing, 1, 2, nothing, 1, 2, nothing, nothing, 1, 2]
@test isequal(parameter_symbols(odesys), [a, b])
@test all(is_independent_variable.((odesys,), [t, :t]))
@test all(.!is_independent_variable.((odesys,), [x, y, a, :x, :y, :a]))
Expand All @@ -23,10 +25,10 @@ eqs = [D(x) ~ a * y + t, D(y) ~ b * t]
@variables x y z
@parameters σ ρ β

eqs = [0 ~ σ*(y-x),
0 ~ x*-z)-y,
0 ~ x*y - β*z]
@named ns = NonlinearSystem(eqs, [x,y,z],[σ,ρ,β])
eqs = [0 ~ σ * (y - x),
0 ~ x *- z) - y,
0 ~ x * y - β * z]
@named ns = NonlinearSystem(eqs, [x, y, z], [σ, ρ, β])

@test !is_time_dependent(ns)

Expand All @@ -37,20 +39,20 @@ Dtt = Differential(t)^2
Dt = Differential(t)

#2D PDE
C=1
eq = Dtt(u(t,x)) ~ C^2*Dxx(u(t,x))
C = 1
eq = Dtt(u(t, x)) ~ C^2 * Dxx(u(t, x))

# Initial and boundary conditions
bcs = [u(t,0) ~ 0.,# for all t > 0
u(t,1) ~ 0.,# for all t > 0
u(0,x) ~ x*(1. - x), #for all 0 < x < 1
Dt(u(0,x)) ~ 0. ] #for all 0 < x < 1]
bcs = [u(t, 0) ~ 0.0,# for all t > 0
u(t, 1) ~ 0.0,# for all t > 0
u(0, x) ~ x * (1.0 - x), #for all 0 < x < 1
Dt(u(0, x)) ~ 0.0] #for all 0 < x < 1]

# Space and time domains
domains = [t (0.0,1.0),
x (0.0,1.0)]
domains = [t (0.0, 1.0),
x (0.0, 1.0)]

@named pde_system = PDESystem(eq,bcs,domains,[t,x],[u])
@named pde_system = PDESystem(eq, bcs, domains, [t, x], [u])

@test pde_system.ps == SciMLBase.NullParameters()
@test parameter_symbols(pde_system) == []
Expand Down

0 comments on commit df4b7e5

Please sign in to comment.