Skip to content

Commit a74c321

Browse files
authored
Merge pull request #444 from SciML/ap/ensemble_problem
Add tests for Ensemble Problems
2 parents a797e46 + c7f47d6 commit a74c321

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/misc/ensemble_tests.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@testitem "Ensemble Nonlinear Problems" tags=[:misc] begin
2+
using NonlinearSolve
3+
4+
prob_func(prob, i, repeat) = remake(prob; u0 = prob.u0[:, i])
5+
6+
prob_nls_oop = NonlinearProblem((u, p) -> u .* u .- p, rand(4, 128), 2.0)
7+
prob_nls_iip = NonlinearProblem((du, u, p) -> du .= u .* u .- p, rand(4, 128), 2.0)
8+
prob_nlls_oop = NonlinearLeastSquaresProblem((u, p) -> u .^ 2 .- p, rand(4, 128), 2.0)
9+
prob_nlls_iip = NonlinearLeastSquaresProblem(
10+
NonlinearFunction{true}((du, u, p) -> du .= u .^ 2 .- p; resid_prototype = rand(4)),
11+
rand(4, 128), 2.0)
12+
13+
for prob in (prob_nls_oop, prob_nls_iip, prob_nlls_oop, prob_nlls_iip)
14+
ensembleprob = EnsembleProblem(prob; prob_func)
15+
16+
for ensemblealg in (EnsembleThreads(), EnsembleSerial())
17+
sim = solve(ensembleprob, nothing, ensemblealg; trajectories = size(prob.u0, 2))
18+
@test all(SciMLBase.successful_retcode, sim.u)
19+
end
20+
end
21+
end

0 commit comments

Comments
 (0)