Skip to content

Commit 2de80ce

Browse files
Fix noise kwarg propagation for SDEProblem(f::SDESystem)
When creating an SDEProblem from an SDESystem, the noise keyword argument was being ignored. The constructor always calculated noise and noise_rate_prototype from the system, overwriting any user-provided values. This fix checks if the user has already provided noise or noise_rate_prototype in kwargs before calculating defaults from the system. This allows users to specify custom noise processes for their SDEProblems. Fixes #3664 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 865e339 commit 2de80ce

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ SimpleNonlinearSolve = "727e6d20-b764-4bd8-a329-72de5adea6c7"
5858
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
5959
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
6060
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
61+
StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0"
6162
SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5"
6263
SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"
6364
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"

src/problems/sdeproblem.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,20 @@ end
7777
t = tspan !== nothing ? tspan[1] : tspan, check_length, eval_expression,
7878
eval_module, check_compatibility, sparse, expression, kwargs...)
7979

80-
noise, noise_rate_prototype = calculate_noise_and_rate_prototype(sys, u0; sparsenoise)
80+
# Only calculate noise and noise_rate_prototype if not provided by user
81+
if !haskey(kwargs, :noise) && !haskey(kwargs, :noise_rate_prototype)
82+
noise, noise_rate_prototype = calculate_noise_and_rate_prototype(sys, u0; sparsenoise)
83+
elseif !haskey(kwargs, :noise)
84+
noise, _ = calculate_noise_and_rate_prototype(sys, u0; sparsenoise)
85+
noise_rate_prototype = kwargs[:noise_rate_prototype]
86+
elseif !haskey(kwargs, :noise_rate_prototype)
87+
_, noise_rate_prototype = calculate_noise_and_rate_prototype(sys, u0; sparsenoise)
88+
noise = kwargs[:noise]
89+
else
90+
noise = kwargs[:noise]
91+
noise_rate_prototype = kwargs[:noise_rate_prototype]
92+
end
93+
8194
kwargs = process_kwargs(sys; expression, callback, eval_expression, eval_module,
8295
op, kwargs...)
8396

0 commit comments

Comments
 (0)