Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle events in isequal #3317

Merged
merged 4 commits into from
Jan 21, 2025
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
2 changes: 2 additions & 0 deletions src/systems/diffeqs/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ function Base.:(==)(sys1::ODESystem, sys2::ODESystem)
_eq_unordered(get_eqs(sys1), get_eqs(sys2)) &&
_eq_unordered(get_unknowns(sys1), get_unknowns(sys2)) &&
_eq_unordered(get_ps(sys1), get_ps(sys2)) &&
_eq_unordered(continuous_events(sys1), continuous_events(sys2)) &&
_eq_unordered(discrete_events(sys1), discrete_events(sys2)) &&
all(s1 == s2 for (s1, s2) in zip(get_systems(sys1), get_systems(sys2)))
end

Expand Down
6 changes: 4 additions & 2 deletions src/systems/diffeqs/sdesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,13 @@ function Base.:(==)(sys1::SDESystem, sys2::SDESystem)
iv2 = get_iv(sys2)
isequal(iv1, iv2) &&
isequal(nameof(sys1), nameof(sys2)) &&
isequal(get_eqs(sys1), get_eqs(sys2)) &&
isequal(get_noiseeqs(sys1), get_noiseeqs(sys2)) &&
_eq_unordered(get_eqs(sys1), get_eqs(sys2)) &&
_eq_unordered(get_noiseeqs(sys1), get_noiseeqs(sys2)) &&
isequal(get_is_scalar_noise(sys1), get_is_scalar_noise(sys2)) &&
_eq_unordered(get_unknowns(sys1), get_unknowns(sys2)) &&
_eq_unordered(get_ps(sys1), get_ps(sys2)) &&
_eq_unordered(continuous_events(sys1), continuous_events(sys2)) &&
_eq_unordered(discrete_events(sys1), discrete_events(sys2)) &&
all(s1 == s2 for (s1, s2) in zip(get_systems(sys1), get_systems(sys2)))
end

Expand Down
28 changes: 27 additions & 1 deletion test/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,32 @@ end
@test all(x -> any(isapprox(x, atol = 1e-6), sol2.t), expected_tstops)
end

# Test `isequal`
@testset "`isequal`" begin
@variables X(t)
@parameters p d
eq = D(X) ~ p - d*X

osys1 = complete(ODESystem([eq], t; name = :osys))
osys2 = complete(ODESystem([eq], t; name = :osys))
@test osys1 == osys2 # true

continuous_events = [[X ~ 1.0] => [X ~ X + 5.0]]
discrete_events = [5.0 => [d ~ d / 2.0]]

osys1 = complete(ODESystem([eq], t; name = :osys, continuous_events))
osys2 = complete(ODESystem([eq], t; name = :osys))
@test osys1 !== osys2

osys1 = complete(ODESystem([eq], t; name = :osys, discrete_events))
osys2 = complete(ODESystem([eq], t; name = :osys))
@test osys1 !== osys2

osys1 = complete(ODESystem([eq], t; name = :osys, continuous_events))
osys2 = complete(ODESystem([eq], t; name = :osys, discrete_events))
@test osys1 !== osys2
end

@testset "dae_order_lowering basic test" begin
@parameters a
@variables x(t) y(t) z(t)
Expand Down Expand Up @@ -1599,4 +1625,4 @@ end

prob = ODEProblem{false}(lowered_dae_sys; u0_constructor = x -> SVector(x...))
@test prob.u0 isa SVector
end
end
25 changes: 25 additions & 0 deletions test/sdesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,31 @@ end
@test length(observed(sys)) == 1
end

@testset "SDESystem Equality with events" begin
@variables X(t)
@parameters p d
@brownian a
seq = D(X) ~ p - d*X + a
@mtkbuild ssys1 = System([seq], t; name = :ssys)
@mtkbuild ssys2 = System([seq], t; name = :ssys)
@test ssys1 == ssys2 # true

continuous_events = [[X ~ 1.0] => [X ~ X + 5.0]]
discrete_events = [5.0 => [d ~ d / 2.0]]

@mtkbuild ssys1 = System([seq], t; name = :ssys, continuous_events)
@mtkbuild ssys2 = System([seq], t; name = :ssys)
@test ssys1 !== ssys2

@mtkbuild ssys1 = System([seq], t; name = :ssys, discrete_events)
@mtkbuild ssys2 = System([seq], t; name = :ssys)
@test ssys1 !== ssys2

@mtkbuild ssys1 = System([seq], t; name = :ssys, continuous_events)
@mtkbuild ssys2 = System([seq], t; name = :ssys, discrete_events)
@test ssys1 !== ssys2
end

@testset "Error when constructing SDESystem without `structural_simplify`" begin
@parameters σ ρ β
@variables x(tt) y(tt) z(tt)
Expand Down
Loading