sassoftware/R-swat

Skip run_iii when using n_thread =4

Alilou66 opened this issue · 3 comments

Hi there,
Thanks for your valuable package. When I want to run calibration with 700 run and with "n_thread =4", some of the run_iii is missed. So, there is a an error when I want to make a dotty plot (sensitive analysis). I have run 700 sample but there is 589 simulation.
In fact, one of the cores skype running.
The error code is that:
"Error in mutate():
! Problem while computing crit = crit.
x crit must be size 700 or 1, not 588."
Thanks in advance,
Hossein

Can you please provide an example of the code you are running ?

Please find the code:
n_sample <- 700
par_bound <- tibble( 'cn2.hru | change = absval' = c(50,80),
'awc.sol | change = pctchg' = c(-40, 40),
'esco.hru | change = absval' = c(0.2, 0.80),
'epco.hru | change = absval' = c(0.001, 0.4),
'perco.hru |change = absval' = c(0.01,0.7),
'slope.hru | change = pctchg' = c(-25, 25)
)
######################
n_par <- ncol(par_bound)

par_lhs <- randomLHS(n = n_sample, k = n_par) %>% # Perform sampling
as_tibble(., .name_repair = 'minimal') %>% # Convert to a tibble
set_names(names(par_bound)) %>% # Assign the parameter names with purrr
map2_df(., par_bound, ~ (.x * (.y[2] - .y[1]) + .y[1])) # Scale parameter ranges

################### Run

qout_et <- run_swatplus(project_path = path_plus,
output = list(q_out = define_output(file = 'channel_sd',
variable = 'flo_out',
unit = 1)),
parameter = par_lhs,
start_date = 20030101,
end_date = 20151231,
years_skip = 3,
n_thread =4)
####################
cmt_area <- 462097631.846 #m2
#################### Annual
qout_annual <- qout_et$simulation$q_out %>%
mutate(year = year(date)) %>%
group_by(year) %>%
dplyr::summarise(across(starts_with('run_'), ~ sum(.x243600 * 1e3 / cmt_area)))

qout_avann <- qout_annual %>%
dplyr::summarise(across(starts_with('run_'), .fns = mean))

######################

qobs_annual <- q_obs %>%
mutate(year = year(date)) %>%
group_by(year) %>%
dplyr::summarise(qobs_mm = sum(discharge243600 * 1e3 / cmt_area)) %>%
left_join(qout_annual['year'], ., by = 'year')

qobs_avann <- qobs_annual %>%
dplyr:: summarise(across(starts_with('run_'), .fns = mean))

qobs_avann <- qobs_annual %>%
dplyr:: summarise(qobs_mm = mean(qobs_mm))
######################################dotty plot
plot_dotty <- function(par, crit, crit_label = 'crit', n_col=3) {
dotty_tbl <- par %>%
mutate(crit = crit) %>%
pivot_longer(., cols = -crit, names_to = 'parameter')

ggplot(data = dotty_tbl) +
geom_point(aes(x = value, y = crit)) +
facet_wrap(. ~ parameter, ncol =3, scales = "free_x") +
labs(x = 'Change of parameter value', y = crit_label) +
theme_bw()
}
###################################
Cheers,
Hossein

Hi Hossein,
Thank you for providing the code sample.
It looks like you are using run_swatplus() and having a problem with that.
Unfortunately, run_swatplus() is not part of this project. It looks like run_swatplus() may be part of the SWATplusR project.
Could you please try re-posting your issue there ?