r-simmer / simmer

Discrete-Event Simulation for R
https://r-simmer.org
GNU General Public License v2.0
222 stars 42 forks source link

Error in the 5G Vignette - base::split() function leads to compatiblity issue with get_mon_arrivals() #210

Closed palandh closed 5 years ago

palandh commented 5 years ago

I tried to execute the 5G vignette code. Simulation runs fine, but upon retrieval of the monitored arrivals there happens a code error

arrivals <- envs %>% get_mon_arrivals() %>% left_join(rowid_to_column(cases, "replication")) %>% filter(!(fh_prio==0 & preemptive==TRUE)) %>% separate(name, c("Flow", "index", "n")) %>% mutate(total_time = end_time - start_time, waiting_time = total_time - activity_time, Queue = forcats::fct_recode(interaction(fh_prio, preemptive), "without SP" = "0.FALSE", "with SP" = "1.FALSE", "with SP & preemption" = "1.TRUE")) Error in (function (x) : unused argument (1 = )

I think it has something to do how base::split() function transform the cases dataframe into a list.

system.time({ envs <- parallel::mclapply(split(cases, 1:nrow(cases)), simulate, mc.cores=nrow(cases), mc.set.seed=FALSE) })

Sadly I could not find a solution for this problem.

R Version Information:

R version 3.6.1 (2019-07-05) -- "Action of the Toes" Copyright (C) 2019 The R Foundation for Statistical Computing Platform: x86_64-apple-darwin15.6.0 (64-bit)

Enchufa2 commented 5 years ago

sessionInfo(), please?

Enchufa2 commented 5 years ago

Also, please try to determine at which point the error is issued by running just

arrivals <- envs %>%
  get_mon_arrivals() 

then

arrivals <- envs %>%
  get_mon_arrivals() %>%
  left_join(rowid_to_column(cases, "replication"))

etc.

palandh commented 5 years ago

My sessionInfo()

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] forcats_0.4.0   stringr_1.4.0   dplyr_0.8.3     purrr_0.3.2     readr_1.3.1     tidyr_0.8.3     tibble_2.1.3   
 [8] ggplot2_3.2.0   tidyverse_1.2.1 simmer_4.3.0   

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.2       cellranger_1.1.0 pillar_1.4.2     compiler_3.6.1   tools_3.6.1      zeallot_0.1.0    lubridate_1.7.4 
 [8] jsonlite_1.6     nlme_3.1-140     gtable_0.3.0     lattice_0.20-38  pkgconfig_2.0.2  rlang_0.4.0      cli_1.1.0       
[15] rstudioapi_0.10  yaml_2.2.0       parallel_3.6.1   haven_2.1.1      withr_2.1.2      xml2_1.2.0       httr_1.4.0      
[22] generics_0.0.2   vctrs_0.2.0      hms_0.5.0        grid_3.6.1       tidyselect_0.2.5 glue_1.3.1       R6_2.4.0        
[29] readxl_1.3.1     modelr_0.1.4     magrittr_1.5     backports_1.1.4  scales_1.0.0     codetools_0.2-16 rvest_0.3.4     
[36] assertthat_0.2.1 colorspace_1.4-1 stringi_1.4.3    lazyeval_0.2.2   munsell_0.5.0    broom_0.5.2      crayon_1.3.4   

Error occurs directly here

> arrivals <- envs %>%
+   get_mon_arrivals()
Error in (function (x)  : unused argument (`1` = <environment>)

Output of head(envs) is:

head(envs)
$`1`
simmer environment: anonymous | now: 0.00490430307362402 | next: 0.00490431162255462
{ Monitor:  }
{ Resource: switch1 | monitored: FALSE | server status: 1(1) | queue status: 7(Inf) }
{ Source: FH_0_ | monitored: 1 | n_generated: 73300 }
{ Source: BH_1_ | monitored: 1 | n_generated: 27000 }

$`2`
simmer environment: anonymous | now: 0.00490430307362402 | next: 0.00490432017201749
{ Monitor:  }
{ Resource: switch1 | monitored: FALSE | server status: 0(1) | queue status: 0(Inf) }
{ Resource: switch2 | monitored: FALSE | server status: 0(1) | queue status: 0(Inf) }
{ Source: FH_0_ | monitored: 1 | n_generated: 73100 }
{ Source: BH_1_ | monitored: 1 | n_generated: 27300 }
{ Source: BH_2_ | monitored: 1 | n_generated: 27000 }

$`3`
simmer environment: anonymous | now: 0.00490430307362402 | next: 0.00490431589063968
{ Monitor:  }
{ Resource: switch1 | monitored: FALSE | server status: 1(1) | queue status: 1(Inf) }
{ Resource: switch2 | monitored: FALSE | server status: 0(1) | queue status: 0(Inf) }
{ Resource: switch3 | monitored: FALSE | server status: 1(1) | queue status: 0(Inf) }
{ Resource: switch4 | monitored: FALSE | server status: 1(1) | queue status: 0(Inf) }
{ Resource: switch5 | monitored: FALSE | server status: 1(1) | queue status: 0(Inf) }
{ Source: FH_0_ | monitored: 1 | n_generated: 72900 }
{ Source: BH_1_ | monitored: 1 | n_generated: 27100 }
{ Source: BH_2_ | monitored: 1 | n_generated: 27000 }
{ Source: BH_3_ | monitored: 1 | n_generated: 26900 }
{ Source: BH_4_ | monitored: 1 | n_generated: 27300 }
{ Source: BH_5_ | monitored: 1 | n_generated: 26900 }

$`4`
simmer environment: anonymous | now: 0.00490430307362402 | next: 0.00490441102654404
{ Monitor:  }
{ Resource: switch1 | monitored: FALSE | server status: 0(1) | queue status: 0(Inf) }
{ Source: FH_0_ | monitored: 1 | n_generated: 73100 }
{ Source: BH_1_ | monitored: 1 | n_generated: 27000 }

$`5`
simmer environment: anonymous | now: 0.00490430307362402 | next: 0.00490431743457436
{ Monitor:  }
{ Resource: switch1 | monitored: FALSE | server status: 1(1) | queue status: 3(Inf) }
{ Resource: switch2 | monitored: FALSE | server status: 1(1) | queue status: 1(Inf) }
{ Source: FH_0_ | monitored: 1 | n_generated: 73200 }
{ Source: BH_1_ | monitored: 1 | n_generated: 27100 }
{ Source: BH_2_ | monitored: 1 | n_generated: 27100 }

$`6`
simmer environment: anonymous | now: 0.00490430307362402 | next: 0.0049043051003623
{ Monitor:  }
{ Resource: switch1 | monitored: FALSE | server status: 1(1) | queue status: 1(Inf) }
{ Resource: switch2 | monitored: FALSE | server status: 0(1) | queue status: 0(Inf) }
{ Resource: switch3 | monitored: FALSE | server status: 1(1) | queue status: 4(Inf) }
{ Resource: switch4 | monitored: FALSE | server status: 1(1) | queue status: 1(Inf) }
{ Resource: switch5 | monitored: FALSE | server status: 0(1) | queue status: 0(Inf) }
{ Source: FH_0_ | monitored: 1 | n_generated: 73200 }
{ Source: BH_1_ | monitored: 1 | n_generated: 26900 }
{ Source: BH_2_ | monitored: 1 | n_generated: 26900 }
{ Source: BH_3_ | monitored: 1 | n_generated: 27000 }
{ Source: BH_4_ | monitored: 1 | n_generated: 27200 }
{ Source: BH_5_ | monitored: 1 | n_generated: 27100 }

Can I get you anything else to help?

palandh commented 5 years ago

I tried a complete fresh run with the code from here: https://raw.githubusercontent.com/r-simmer/simmer/master/vignettes/includes/5G-1.R

Error persists.

I assume the code worked some time. So the question is wheather this is specific to my machine and my R Setup or maybe due to a newer R version ? Other ideas or anything I can do to help? Just let me know.

Enchufa2 commented 5 years ago

Thanks, the issue has to do with the names of the elements. The minimal reproducible example would be:

library(simmer)

get_mon_arrivals(list(simmer()))
#> [1] name          start_time    end_time      activity_time finished     
#> <0 rows> (or 0-length row.names)

get_mon_arrivals(list(some_name=simmer()))
#> Error in (function (x) : unused argument (some_name = <environment>)

A workaround until this is fixed would be:

arrivals <- unname(envs) %>%
  get_mon_arrivals() %>%
  ...

etc.

palandh commented 5 years ago

I thought in this direction but could not narrow it down.

Thanks for the workaround and quick response. Also thumbs up for the package in general.

Enchufa2 commented 5 years ago

Many thanks for the report. Fixed in master.