Skip to content

Commit

Permalink
Merge pull request #444 from SciML/ap/ensemble_problem
Browse files Browse the repository at this point in the history
Add tests for Ensemble Problems
  • Loading branch information
avik-pal authored Jun 1, 2024
2 parents a797e46 + c7f47d6 commit a74c321
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/misc/ensemble_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@testitem "Ensemble Nonlinear Problems" tags=[:misc] begin
using NonlinearSolve

prob_func(prob, i, repeat) = remake(prob; u0 = prob.u0[:, i])

prob_nls_oop = NonlinearProblem((u, p) -> u .* u .- p, rand(4, 128), 2.0)
prob_nls_iip = NonlinearProblem((du, u, p) -> du .= u .* u .- p, rand(4, 128), 2.0)
prob_nlls_oop = NonlinearLeastSquaresProblem((u, p) -> u .^ 2 .- p, rand(4, 128), 2.0)
prob_nlls_iip = NonlinearLeastSquaresProblem(
NonlinearFunction{true}((du, u, p) -> du .= u .^ 2 .- p; resid_prototype = rand(4)),
rand(4, 128), 2.0)

for prob in (prob_nls_oop, prob_nls_iip, prob_nlls_oop, prob_nlls_iip)
ensembleprob = EnsembleProblem(prob; prob_func)

for ensemblealg in (EnsembleThreads(), EnsembleSerial())
sim = solve(ensembleprob, nothing, ensemblealg; trajectories = size(prob.u0, 2))
@test all(SciMLBase.successful_retcode, sim.u)
end
end
end

0 comments on commit a74c321

Please sign in to comment.