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

Add EnsembleProblem syntax to example #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 16 additions & 1 deletion docs/src/tutorials/params.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,19 @@ for (j, sol) in enumerate(sols)
gif(anim, "plot_$j.gif",fps=10)
end

```
```

## Scan parameter sets in parallel

This toy example solves quickly by simply looping through parameter sets, but slower problems can benefit from parallel processing using an [EnsembleProblem](https://diffeq.sciml.ai/stable/features/ensemble/s).

```
Dnval = rand(1000)
Dpval = rand(1000)

function prob_func(prob,i,repeat)
remake(prob, p=[Dnval[i],Dpval[i]])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably add an index check https://mtk.sciml.ai/dev/basics/FAQ/#Getting-the-index-for-a-symbol in case it's reordered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without having dug around inside remake, is this something that could be handled internally there to prevent reordering? Seems dangerous to have exposure to invisible bugs like this that users wouldn't foresee unless they crossed this FAQ.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChrisRackauckas thoughts on this? ^

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. Right now parameters never reorder, so technically this is correct. And with states, the reordering comes with reduction, so just passing an array of the right size will throw an error. But this is something we need to be working on. If an ODEProblem has a symbolic base, we should probably require a force=true or something to allow raw arrays to remake.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should have that. If one does not want reordering, then just don't use structural_simplify. Reordering is one of the most fundamental assumptions we have in MTK. Otherwise, there is not much point in giving states names other than for convenience.

Copy link
Member

@ChrisRackauckas ChrisRackauckas Aug 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well we'd need a force=true behavior internally anyways, but it would make sense to add a safety check and assume people will be using transformed systems.

Copy link
Member

@xtalax xtalax Aug 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to me that if you are defining your problem symbolically, and therefore are using named states and structural_simplify, then remake should require a Dict/Array{Pair} for p as in the system definition. This would also enhance consistency of the interface.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remake should now work here with the pairs?

end
ensemble_prob = EnsembleProblem(prob, prob_func=prob_func)
sols = solve(ensemble_prob, Tsit5(), trajectories=1000)
```