Skip to content

Commit 31aa63a

Browse files
Merge pull request #4738 from ChrisRackauckas-Claude/agent/fix-mtkbase-unbound-parameters
Fix ModelingToolkitBase Aqua unbound arguments
2 parents 82aa055 + d31e990 commit 31aa63a

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

lib/ModelingToolkitBase/src/systems/parameter_buffer.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -784,9 +784,9 @@ end
784784
# For type-inference when using `SII.setp_oop`
785785
@generated function _remake_buffer(
786786
indp, oldbuf::MTKParameters{T, I, D, C, N, H},
787-
idxs::Union{Tuple{Vararg{ParameterIndex}}, AbstractArray{<:ParameterIndex{P}}},
787+
idxs::Union{Tuple{Vararg{ParameterIndex}}, AbstractArray{<:ParameterIndex}},
788788
vals::Union{AbstractArray, Tuple}; validate = true
789-
) where {T, I, D, C, N, H, P}
789+
) where {T, I, D, C, N, H}
790790

791791
# fallback to non-generated method if values aren't type-stable
792792
if vals <: AbstractArray && !isconcretetype(eltype(vals))
@@ -1012,10 +1012,8 @@ end
10121012
Base.size(::NestedGetIndex) = ()
10131013

10141014
function SymbolicIndexingInterface.with_updated_parameter_timeseries_values(
1015-
::AbstractSystem, ps::MTKParameters, args::Pair{A, B}...
1016-
) where {
1017-
A, B <: NestedGetIndex,
1018-
}
1015+
::AbstractSystem, ps::MTKParameters, args::Pair{<:Any, <:NestedGetIndex}...
1016+
)
10191017
for (i, ngi) in args
10201018
for (j, val) in enumerate(ngi.x)
10211019
copyto!(view(ps.discrete[j], Block(i)), val)

lib/ModelingToolkitBase/src/systems/problem_utils.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,9 +1770,6 @@ function maybe_build_initialization_problem(
17701770
)
17711771
end
17721772

1773-
rm_union(::Type{Union{T, Nothing}}) where {T} = T
1774-
rm_union(::Type{T}) where {T} = T
1775-
17761773
"""
17771774
$(TYPEDSIGNATURES)
17781775
@@ -1786,8 +1783,7 @@ function float_type_from_varmap(varmap, floatT = Bool)
17861783
is_array_of_symbolics(v) && continue
17871784
v = unwrap_const(v)
17881785
if v isa AbstractArray
1789-
# Remove union in case some elements of the array are `nothing`
1790-
floatT = promote_type(floatT, rm_union(eltype(unwrap_const(v))))
1786+
floatT = promote_type(floatT, typeintersect(eltype(v), Number))
17911787
elseif v isa Number
17921788
floatT = promote_type(floatT, typeof(unwrap_const(v)))
17931789
end

lib/ModelingToolkitBase/test/variable_utils.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ using ModelingToolkitBase: value, parse_variable
33
using SymbolicUtils: <
44
import SymbolicUtils as SU
55

6+
@variables x
7+
@test ModelingToolkitBase.float_type_from_varmap(
8+
[x => Union{Nothing, BigFloat}[nothing]]
9+
) == BigFloat
10+
@test ModelingToolkitBase.float_type_from_varmap(
11+
[x => Union{Nothing, Float32}[nothing]]
12+
) == Float32
13+
614
@parameters α β δ
715
expr = (((1 / β - 1) + δ) / α)^(1 /- 1))
816
ref = sort([β, δ, α], lt = <ₑ)

0 commit comments

Comments
 (0)