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

test: added tests for SDEFunctionExpr #3313

Merged
merged 3 commits into from
Jan 22, 2025
Merged
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
44 changes: 43 additions & 1 deletion test/sdesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,48 @@ end
@test length(observed(sys)) == 1
end

@testset "SDEFunctionExpr" begin
@parameters σ ρ β
@variables x(tt) y(tt) z(tt)

eqs = [D(x) ~ σ * (y - x),
D(y) ~ x * (ρ - z) - y,
D(z) ~ x * y - β * z]

noiseeqs = [0.1 * x,
0.1 * y,
0.1 * z]

@named sys = ODESystem(eqs, tt, [x, y, z], [σ, ρ, β])

@named de = SDESystem(eqs, noiseeqs, tt, [x, y, z], [σ, ρ, β], tspan = (0.0, 10.0))
de = complete(de)

f = SDEFunctionExpr(de)
@test f isa Expr

@testset "Configuration Tests" begin
# Test with `tgrad`
f_tgrad = SDEFunctionExpr(de; tgrad = true)
@test f_tgrad isa Expr

# Test with `jac`
f_jac = SDEFunctionExpr(de; jac = true)
@test f_jac isa Expr

# Test with sparse Jacobian
f_sparse = SDEFunctionExpr(de; sparse = true)
@test f_sparse isa Expr
end

@testset "Ordering Tests" begin
dvs = [z, y, x]
ps = [β, ρ, σ]
f_order = SDEFunctionExpr(de, dvs, ps)
@test f_order isa Expr
end
end

@testset "SDESystem Equality with events" begin
@variables X(t)
@parameters p d
Expand Down Expand Up @@ -911,4 +953,4 @@ end
@test_throws ErrorException("SDESystem constructed by defining Brownian variables with @brownian must be simplified by calling `structural_simplify` before a SDEProblem can be constructed.") SDEProblem(de, u0map, (0.0, 100.0), parammap)
de = structural_simplify(de)
@test SDEProblem(de, u0map, (0.0, 100.0), parammap) isa SDEProblem
end
end
Loading