JuliaDynamics / DrWatson.jl

The perfect sidekick to your scientific inquiries
https://juliadynamics.github.io/DrWatson.jl/stable/
Other
830 stars 93 forks source link

@onlyif with some constants #250

Open MatisPatel opened 3 years ago

MatisPatel commented 3 years ago

Is your feature request related to a problem? Please describe. I have a parameter B that greatly increases search space. I want to investigate b only when some values of A are hit but I still want as a base line all values of A to be run on a subset of B.

Describe the solution you'd like

d = Dict(:a => [1,2,3], :b => [1,2, @onlyif(:a==2, collect(3:5))])

In the above line @onlyif doesn't expand across the container collect(3:5). It just makes one dictionary with :b of that dict being an iterator 3:5.

Describe alternatives you've considered

d = Dict(:a => [1,2,3], :b => [1,2, @onlyif(:a==2, collect(3:5))])
listd = dict_list.(dict_list(d))
flatList = collect(Iterators.flatten(listd))

The above does work but it a tad messy. Maybe this is just a reasonable issue and the workaround is just the way to do it.

JonasIsensee commented 3 years ago
d = Dict(:a => [1,2,3], :b => [1,2, @onlyif(:a==2, collect(3:5))...])

Splatting the @onlyif should work.

MatisPatel commented 3 years ago

Yep that works! Obvious in retrospect. Maybe this use case could just be added as an example to the docs?

Datseris commented 3 years ago

Please do a PR that adds it to the "real world examples"?