Skip to content

Commit 28733ee

Browse files
MasonProtterChrisRackauckas
authored andcommitted
don't specialize on scalar noise, only handle diagonal noise
1 parent a5b64fb commit 28733ee

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/systems/systems.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,16 @@ function __structural_simplify(sys::AbstractSystem, io = nothing; simplify = fal
128128
@views copyto!(sorted_g_rows[i, :], g[g_row, :])
129129
end
130130
# Fix for https://github.com/SciML/ModelingToolkit.jl/issues/2490
131-
noise_eqs = if all(row -> count(!iszero, row) == 1, eachrow(sorted_g_rows)) # Does each row have only one non-zero entry?
132-
# then the noise is actually diagonal! make vector of non-zero entries.
133-
# This happens when the user uses multiple `@brownian`s but never mixes them
134-
map(eachrow(sorted_g_rows)) do row
135-
only(filter(!iszero, row))
136-
end
131+
noise_eqs = if isdiag(sorted_g_rows)
132+
# If the noise matrix is diagonal, then we just give solver just takes a vector column of equations
133+
# and it interprets that as diagonal noise.
134+
diag(sorted_g_rows)
137135
elseif sorted_g_rows isa AbstractMatrix && size(sorted_g_rows, 2) == 1
138-
sorted_g_rows[:, 1] # Take a vector slice so solver knows there's no mixing
136+
##-------------------------------------------------------------------------------
137+
## TODO: re-enable this code once we add a way to signal that the noise is scalar
138+
# sorted_g_rows[:, 1] # Take a vector slice so solver knows there's no mixing
139+
##-------------------------------------------------------------------------------
140+
sorted_g_rows
139141
else
140142
sorted_g_rows
141143
end

test/sdesystem.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,18 +679,18 @@ let
679679
β => 26.0,
680680
ρ => 2.33
681681
]
682-
683682
prob = SDEProblem(de, u0map, (0.0, 100.0), parammap)
684-
@test solve(prob, SOSRI()).retcode == ReturnCode.Success
683+
# TODO: re-enable this when we support scalar noise
684+
@test_broken solve(prob, SOSRI()).retcode == ReturnCode.Success
685685
end
686686

687687
let
688688
@parameters σ ρ β
689689
@variables x(t) y(t) z(t)
690-
@brownian a b
691-
eqs = [D(x) ~ σ * (y - x) + 0.1b * x,
692-
D(y) ~ x *- z) - y + 0.1a * y,
693-
D(z) ~ x * y - β * z + 0.1b * z]
690+
@brownian a b c
691+
eqs = [D(x) ~ σ * (y - x) + 0.1a * x,
692+
D(y) ~ x *- z) - y + 0.1b * y,
693+
D(z) ~ x * y - β * z + 0.1c * z]
694694

695695
@mtkbuild de = System(eqs, t)
696696

0 commit comments

Comments
 (0)