Skip to content

Commit df80490

Browse files
fix: propagate and respect use_union for get_u0 and get_u0_p
1 parent 0084ffa commit df80490

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ function get_u0_p(sys,
722722
if symbolic_u0
723723
u0 = varmap_to_vars(u0map, dvs; defaults = defs, tofloat = false, use_union = false)
724724
else
725-
u0 = varmap_to_vars(u0map, dvs; defaults = defs, tofloat = true)
725+
u0 = varmap_to_vars(u0map, dvs; defaults = defs, tofloat = true, use_union)
726726
end
727727
p = varmap_to_vars(parammap, ps; defaults = defs, tofloat, use_union)
728728
p = p === nothing ? SciMLBase.NullParameters() : p
@@ -732,7 +732,7 @@ end
732732

733733
function get_u0(
734734
sys, u0map, parammap = nothing; symbolic_u0 = false,
735-
toterm = default_toterm, t0 = nothing)
735+
toterm = default_toterm, t0 = nothing, use_union = true)
736736
dvs = unknowns(sys)
737737
ps = parameters(sys)
738738
defs = defaults(sys)
@@ -757,7 +757,7 @@ function get_u0(
757757
u0 = varmap_to_vars(
758758
u0map, dvs; defaults = defs, tofloat = false, use_union = false, toterm)
759759
else
760-
u0 = varmap_to_vars(u0map, dvs; defaults = defs, tofloat = true, toterm)
760+
u0 = varmap_to_vars(u0map, dvs; defaults = defs, tofloat = true, use_union, toterm)
761761
end
762762
t0 !== nothing && delete!(defs, get_iv(sys))
763763
return u0, defs
@@ -836,7 +836,7 @@ function process_DEProblem(constructor, sys::AbstractODESystem, u0map, parammap;
836836

837837
if has_index_cache(sys) && get_index_cache(sys) !== nothing
838838
u0, defs = get_u0(sys, trueinit, parammap; symbolic_u0,
839-
t0 = constructor <: Union{DDEFunction, SDDEFunction} ? nothing : t)
839+
t0 = constructor <: Union{DDEFunction, SDDEFunction} ? nothing : t, use_union)
840840
check_eqs_u0(eqs, dvs, u0; kwargs...)
841841
p = if parammap === nothing ||
842842
parammap == SciMLBase.NullParameters() && isempty(defs)

src/utils.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,9 @@ function promote_to_concrete(vs; tofloat = true, use_union = true)
689689
if use_union
690690
C = Union{C, E}
691691
else
692-
@assert C==E "`promote_to_concrete` can't make type $E uniform with $C"
693-
C = E
692+
C2 = promote_type(C, E)
693+
@assert C2==E || C2==C "`promote_to_concrete` can't make type $E uniform with $C"
694+
C = C2
694695
end
695696
end
696697

test/odesystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ end
11771177
sys = structural_simplify(ODESystem([D(x) ~ P], t, [x], [P]; name = :sys))
11781178

11791179
function x_at_1(P)
1180-
prob = ODEProblem(sys, [x => P], (0.0, 1.0), [sys.P => P])
1180+
prob = ODEProblem(sys, [x => P], (0.0, 1.0), [sys.P => P], use_union = false)
11811181
return solve(prob, Tsit5())(1.0)
11821182
end
11831183

0 commit comments

Comments
 (0)