-
-
Notifications
You must be signed in to change notification settings - Fork 114
Simplify ensemble indexing #839
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,9 +1,19 @@ | ||||||||||||||||||||||||||||||||||
| using OrdinaryDiffEq | ||||||||||||||||||||||||||||||||||
| using OrdinaryDiffEq, Test | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| prob = ODEProblem((u, p, t) -> 1.01u, 0.5, (0.0, 1.0)) | ||||||||||||||||||||||||||||||||||
| A = [1 2 | ||||||||||||||||||||||||||||||||||
| 3 4] | ||||||||||||||||||||||||||||||||||
| prob = ODEProblem((u, p, t) -> A*u, ones(2,2), (0.0, 1.0)) | ||||||||||||||||||||||||||||||||||
| function prob_func(prob, i, repeat) | ||||||||||||||||||||||||||||||||||
| remake(prob, u0 = rand() * prob.u0) | ||||||||||||||||||||||||||||||||||
| remake(prob, u0 = i * prob.u0) | ||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
| ensemble_prob = EnsembleProblem(prob, prob_func = prob_func) | ||||||||||||||||||||||||||||||||||
| sim = solve(ensemble_prob, Tsit5(), EnsembleThreads(), trajectories = 10) | ||||||||||||||||||||||||||||||||||
| sim = solve(ensemble_prob, Tsit5(), EnsembleThreads(), trajectories = 10, saveat=0.01) | ||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||
| @test sim isa EnsembleSolution | ||||||||||||||||||||||||||||||||||
| @test size(sim[1,:,:,:]) == (2,101,10) | ||||||||||||||||||||||||||||||||||
| @test size(sim[:,1,:,:]) == (2,101,10) | ||||||||||||||||||||||||||||||||||
| @test size(sim[:,:,1,:]) == (2,2,10) | ||||||||||||||||||||||||||||||||||
| @test size(sim[:,:,:,1]) == (2,2,101) | ||||||||||||||||||||||||||||||||||
| @test Array(sim)[1,:,:,:] == sim[1,:,:,:] | ||||||||||||||||||||||||||||||||||
| @test Array(sim)[:,1,:,:] == sim[:,1,:,:] | ||||||||||||||||||||||||||||||||||
| @test Array(sim)[:,:,1,:] == sim[:,:,1,:] | ||||||||||||||||||||||||||||||||||
| @test Array(sim)[:,:,:,1] == sim[:,:,:,1] | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| @test size(sim[1,:,:,:]) == (2,101,10) | |
| @test size(sim[:,1,:,:]) == (2,101,10) | |
| @test size(sim[:,:,1,:]) == (2,2,10) | |
| @test size(sim[:,:,:,1]) == (2,2,101) | |
| @test Array(sim)[1,:,:,:] == sim[1,:,:,:] | |
| @test Array(sim)[:,1,:,:] == sim[:,1,:,:] | |
| @test Array(sim)[:,:,1,:] == sim[:,:,1,:] | |
| @test Array(sim)[:,:,:,1] == sim[:,:,:,1] | |
| @test size(sim[1, :, :, :]) == (2, 101, 10) | |
| @test size(sim[:, 1, :, :]) == (2, 101, 10) | |
| @test size(sim[:, :, 1, :]) == (2, 2, 10) | |
| @test size(sim[:, :, :, 1]) == (2, 2, 101) | |
| @test Array(sim)[1, :, :, :] == sim[1, :, :, :] | |
| @test Array(sim)[:, 1, :, :] == sim[:, 1, :, :] | |
| @test Array(sim)[:, :, 1, :] == sim[:, :, 1, :] | |
| @test Array(sim)[:, :, :, 1] == sim[:, :, :, 1] |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,10 +17,9 @@ prob3 = ODEProblem(sys3, [3.0, 3.0], (0.0, 1.0)) | |||||||||
| ensemble_prob = EnsembleProblem([prob1, prob2, prob3]) | ||||||||||
| sol = solve(ensemble_prob, Tsit5(), EnsembleThreads()) | ||||||||||
| for i in 1:3 | ||||||||||
| @test sol[x, :][i] == sol.u[i][x] | ||||||||||
| @test sol[y, :][i] == sol.u[i][y] | ||||||||||
| @test sol[1,:,i] == sol.u[i][x] | ||||||||||
| @test sol[2,:,i] == sol.u[i][y] | ||||||||||
|
Comment on lines
+20
to
+21
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||
| end | ||||||||||
| # Ensemble is a recursive array | ||||||||||
| @test only.(sol(0.0, idxs = [x])) == sol[1, 1, :] == first.(sol[x, :]) | ||||||||||
| # TODO: fix the interpolation | ||||||||||
| @test only.(sol(1.0, idxs = [x])) ≈ last.(sol[x, :]) | ||||||||||
| @test only.(sol(0.0, idxs = [x])) == sol[1, 1, :] | ||||||||||
| @test only.(sol(1.0, idxs = [x])) ≈ [sol[i][1, end] for i in 1:3] | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶