Skip to content

Commit

Permalink
fix iteration order, add test that catches catalyst case
Browse files Browse the repository at this point in the history
  • Loading branch information
MasonProtter committed Aug 1, 2024
1 parent 37e9689 commit cc6abde
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
40 changes: 33 additions & 7 deletions src/systems/diffeqs/sdesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,30 +246,56 @@ function Base.:(==)(sys1::SDESystem, sys2::SDESystem)
end

function __num_isdiag_noise(mat)
for j in axes(mat, 2)
for i in axes(mat, 1)
nnz = 0
for i in axes(mat, 1)
for j in axes(mat, 2)
if !isequal(mat[i, j], 0)
nnz += 1
end
end
if nnz > 1
return false
return (false)
end
end
true
end
function __get_num_diag_noise(mat)
map(axes(mat, 2)) do j
for i in axes(mat, 1)
if !isequal(mat[i, j], 0)
return mat[i, j]
map(axes(mat, 1)) do i
for j in axes(mat, 2)
mij = mat[i, j]
if !isequal(mij, 0)
return mij
end
end
0
end
end

# function __num_isdiag_noise(mat)
# for j in axes(mat, 2)
# nnz = 0
# for i in axes(mat, 1)
# if !isequal(mat[i, j], 0)
# nnz += 1
# end
# end
# if nnz > 1
# return false
# end
# end
# true
# end
# function __get_num_diag_noise(mat)
# map(axes(mat, 2)) do j
# for i in axes(mat, 1)
# if !isequal(mat[i, j], 0)
# return mat[i, j]
# end
# end
# 0
# end
# end

function generate_diffusion_function(sys::SDESystem, dvs = unknowns(sys),
ps = full_parameters(sys); isdde = false, kwargs...)
eqs = get_noiseeqs(sys)
Expand Down
9 changes: 5 additions & 4 deletions test/sdesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -726,10 +726,10 @@ end
@testset "Non-diagonal noise check" begin
@parameters σ ρ β
@variables x(tt) y(tt) z(tt)
@brownian a b c
eqs = [D(x) ~ σ * (y - x) + 0.1a * x + 0.1b * y,
D(y) ~ x *- z) - y + 0.1b * y,
D(z) ~ x * y - β * z + 0.1c * z]
@brownian a b c d e f
eqs = [D(x) ~ σ * (y - x) + 0.1a * x + d,
D(y) ~ x *- z) - y + 0.1b * y + e,
D(z) ~ x * y - β * z + 0.1c * z + f]
@mtkbuild de = System(eqs, tt)

u0map = [
Expand All @@ -749,6 +749,7 @@ end
@test_throws ErrorException solve(prob, SOSRI()).retcode==ReturnCode.Success
# ImplicitEM does work for non-diagonal noise
@test solve(prob, ImplicitEM()).retcode == ReturnCode.Success
@test size(ModelingToolkit.get_noiseeqs(de)) == (3, 6)
end

@testset "Diagonal noise, less brownians than equations" begin
Expand Down

0 comments on commit cc6abde

Please sign in to comment.