Open andrew-edwards opened 12 months ago
Also, do we need T
in the call for fit_models
- or can we assume it is always the number of rows in the data? Not exactly sure what would happen when they disagree.
** Realised that the call to fit_models
for the parallel code is
outputs <- parallel::parLapply(cl, all_sims, function(x) {
fit_models(x,
res_realisations = res_realisations,
R_switch = R_switch,
T = T,
pbsEDM_args = pbsEDM_args,
mve_args = mve_args,
larkin_args = larkin_args,
ricker_args = ricker_args)
}
which includes all_sims
, then fit_models
uses the m
th value. I was going to say that it would seem clearer to do:
outputs <- parallel::parLapply(cl, all_sims[m], function(x) {
......
(i.e. all_sims[m]
) and then change fit_models
, but now I'm not sure how the parallel stuff would get split up. But reading the code, it looks as though m
would equal M
(its last value from an earlier loop) at this stage of sim_and_fit_realisations()
.
Bit confused, and feel I'm missing something subtle/important about the parallelisation. Maybe to do with why you changed m
to realisations
somewhere also.
I renamed to the input to fit_models() to 'sim' instead of 'all_sims', and I removed [[m]] from inside the function and in the call to fti_models() in sim_and_fit_realistions.R (see commented out lines). It all runs for me, and gives the same answer when do_parallel is true and false.
Awesome, all works. I added a test to compare parallel and not. All tests pass locally for me now.
Finding it hard to test
fit_models()
without doing parallel stuff, but it should be able to work independently (I would think?). Putting abrowser()
in kind of gets ignored when calling it fromsim_and_fit_realisations()
, so having a working example would really help me!Realised that line 120 has
realisation <- dplyr::pull(all_sims['m'][1,])
but nom
has been defined within the function. [See ** below - figured out a solution]Trying to get an example working, this is what I'm using (also copied into example of function, but easier to paste from here):