Skip to content
Merged
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
5 changes: 4 additions & 1 deletion src/systems/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,11 @@ function SymbolicDiscreteCallback(
condition::Union{Symbolic{Bool}, Number, Vector{<:Number}}, affect = nothing;
initialize = nothing, finalize = nothing,
reinitializealg = nothing, kwargs...)
c = is_timed_condition(condition) ? condition : value(scalarize(condition))
# Manual error check (to prevent events like `[X < 5.0] => [X ~ Pre(X) + 10.0]` from being created).
(condition isa Vector) && (eltype(condition) <: Num) &&
error("Vectors of symbolic conditions are not allowed for `SymbolicDiscreteCallback`.")

c = is_timed_condition(condition) ? condition : value(scalarize(condition))
if isnothing(reinitializealg)
if any(a -> a isa ImperativeAffect,
[affect, initialize, finalize])
Expand Down
15 changes: 15 additions & 0 deletions test/symbolic_events.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1440,3 +1440,18 @@ end
@mtkcompile sys = MWE()
@test_nowarn ODEProblem(sys, [], (0.0, 1.0))
end

@testset "Test erroneously created events yields errors" begin
@parameters p(t) d
@variables X(t)
@test_throws "Vectors of symbolic conditions are not allowed" SymbolicDiscreteCallback([X <
5.0] => [X ~
Pre(X) +
10.0])
@test_throws "Vectors of symbolic conditions are not allowed" SymbolicDiscreteCallback([
X < 5.0, X > 10.0] => [X ~ Pre(X) + 10.0])
@test_throws "MethodError: no method" SymbolicContinuousCallback((X <
5.0) => [X ~
Pre(X) +
10.0])
end
Loading