grattan / covid19.model.sa2

4 stars 0 forks source link

Test portability #19

Closed HughParsonage closed 4 years ago

HughParsonage commented 4 years ago

Does this work and deliver reasonable results on MacOS? (Yes, Travis-CI is a good idea but also want to know interactively)

covid19.model.sa2::simulate_sa2(20, PolicyPars = list(supermarkets_open = T), nThread = 10L)

If you have fewer than 10 threads, try as many as you can.

wfmackey commented 4 years ago

Could not load package

> library(devtools)
Loading required package: usethis
Warning messages:
1: package ‘devtools’ was built under R version 3.6.2 
2: package ‘usethis’ was built under R version 3.6.2 
> load_all()
Loading covid19.model.sa2
Re-compiling covid19.model.sa2
─  installing *source* package ‘covid19.model.sa2’ ...
   ** using staged installation
   ** libs
   clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Users/mackeyw/Library/R/3.6/library/Rcpp/include" -I"/Users/mackeyw/Library/R/3.6/library/dqrng/include" -I"/Users/mackeyw/Library/R/3.6/library/RcppProgress/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include  -fPIC  -Wall -g -O2  -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always -c RcppExports.cpp -o RcppExports.o
   clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Users/mackeyw/Library/R/3.6/library/Rcpp/include" -I"/Users/mackeyw/Library/R/3.6/library/dqrng/include" -I"/Users/mackeyw/Library/R/3.6/library/RcppProgress/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include  -fPIC  -Wall -g -O2  -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always -c distr2status.cpp -o distr2status.o
   clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Users/mackeyw/Library/R/3.6/library/Rcpp/include" -I"/Users/mackeyw/Library/R/3.6/library/dqrng/include" -I"/Users/mackeyw/Library/R/3.6/library/RcppProgress/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include  -fPIC  -Wall -g -O2  -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always -c do_aus_simulate.cpp -o do_aus_simulate.o
   do_aus_simulate.cpp:171:14: error: use of undeclared identifier 'omp_get_num_threads'
       if ((k % omp_get_num_threads()) != omp_get_thread_num()) {
                ^
   do_aus_simulate.cpp:171:40: error: use of undeclared identifier 'omp_get_thread_num'
       if ((k % omp_get_num_threads()) != omp_get_thread_num()) {
                                          ^
   do_aus_simulate.cpp:192:14: error: use of undeclared identifier 'omp_get_num_threads'
       if ((k % omp_get_num_threads()) != omp_get_thread_num()) {
                ^
   do_aus_simulate.cpp:192:40: error: use of undeclared identifier 'omp_get_thread_num'
       if ((k % omp_get_num_threads()) != omp_get_thread_num()) {
                                          ^
   do_aus_simulate.cpp:224:15: warning: variable length arrays are a C99 feature [-Wvla-extension]
     int s_visits[n_schools][21];
                 ^
   do_aus_simulate.cpp:225:15: warning: variable length arrays are a C99 feature [-Wvla-extension]
     int i_visits[n_schools][21];
                 ^
   do_aus_simulate.cpp:290:19: error: use of undeclared identifier 'omp_get_num_threads'
       if ((hid[i] % omp_get_num_threads()) != omp_get_thread_num()) {
                     ^
   do_aus_simulate.cpp:290:45: error: use of undeclared identifier 'omp_get_thread_num'
       if ((hid[i] % omp_get_num_threads()) != omp_get_thread_num()) {
                                               ^
   do_aus_simulate.cpp:581:7: error: no matching function for call to 'infect_supermarkets'
         infect_supermarkets(Status,
         ^~~~~~~~~~~~~~~~~~~
   do_aus_simulate.cpp:102:6: note: candidate function not viable: requires at least 19 arguments, but 18 were provided
   void infect_supermarkets(IntegerVector Status,
        ^
   2 warnings and 7 errors generated.
   make: *** [do_aus_simulate.o] Error 1
   ERROR: compilation failed for package ‘covid19.model.sa2’
─  removing ‘/private/var/folders/g2/728t399s5gbbk6bgj5ndlgy1w8w938/T/RtmpSWsgCT/devtools_install_da887841c659/covid19.model.sa2’
Error in (function (command = NULL, args = character(), error_on_status = TRUE,  : 
  System command 'R' failed, exit status: 1, stdout + stderr (last 10 lines):
E> do_aus_simulate.cpp:581:7: error: no matching function for call to 'infect_supermarkets'
E>       infect_supermarkets(Status,
E>       ^~~~~~~~~~~~~~~~~~~
E> do_aus_simulate.cpp:102:6: note: candidate function not viable: requires at least 19 arguments, but 18 were provided
E> void infect_supermarkets(IntegerVector Status,
E>      ^
E> 2 warnings and 7 errors generated.
E> make: *** [do_aus_simulate.o] Error 1
E> ERROR: compilation failed for package ‘covid19.model.sa2’
E> * removing ‘/private/var/folders/g2/728t399s5gbbk6bgj5ndlgy1w8w938/T/RtmpSWsgCT/devtools_install_da887841c659/covid19.model.sa2’
Type .Last.error.trace to see where the error occured
> 

> session_info()
─ Session info ─────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.6.0 (2019-04-26)
 os       macOS  10.15.3              
 system   x86_64, darwin15.6.0        
 ui       RStudio                     
 language (EN)                        
 collate  en_AU.UTF-8                 
 ctype    en_AU.UTF-8                 
 tz       Australia/Melbourne         
 date     2020-04-22                  

─ Packages ─────────────────────────────────────────────────────────────────────────────────────────────────
 package      * version     date       lib source                             
 assertthat     0.2.1       2019-03-21 [2] CRAN (R 3.6.0)                     
 backports      1.1.5       2019-10-02 [1] CRAN (R 3.6.0)                     
 callr          3.4.3       2020-03-28 [1] CRAN (R 3.6.2)                     
 cli            2.0.2       2020-02-28 [1] CRAN (R 3.6.0)                     
 clipr          0.7.0       2019-07-23 [1] CRAN (R 3.6.0)                     
 crayon         1.3.4       2017-09-16 [2] CRAN (R 3.6.0)                     
 desc           1.2.0       2018-05-01 [2] CRAN (R 3.6.0)                     
 devtools     * 2.3.0       2020-04-10 [1] CRAN (R 3.6.2)                     
 digest         0.6.25      2020-02-23 [1] CRAN (R 3.6.0)                     
 dqrng          0.2.1       2019-05-17 [1] CRAN (R 3.6.0)                     
 ellipsis       0.3.0       2019-09-20 [1] CRAN (R 3.6.0)                     
 evaluate       0.14        2019-05-28 [2] CRAN (R 3.6.0)                     
 fansi          0.4.1       2020-01-08 [1] CRAN (R 3.6.0)                     
 fs             1.3.2       2020-03-05 [1] CRAN (R 3.6.0)                     
 glue           1.4.0       2020-04-03 [1] CRAN (R 3.6.0)                     
 htmltools      0.4.0       2019-10-04 [1] CRAN (R 3.6.0)                     
 knitr          1.28        2020-02-06 [1] CRAN (R 3.6.0)                     
 magrittr       1.5         2014-11-22 [2] CRAN (R 3.6.0)                     
 memoise        1.1.0       2017-04-21 [2] CRAN (R 3.5.0)                     
 packrat        0.5.0       2018-11-14 [2] CRAN (R 3.6.0)                     
 pkgbuild       1.0.6       2019-10-09 [1] CRAN (R 3.6.0)                     
 pkgload        1.0.2       2018-10-29 [2] CRAN (R 3.6.0)                     
 prettyunits    1.1.1       2020-01-24 [1] CRAN (R 3.6.0)                     
 processx       3.4.2       2020-02-09 [1] CRAN (R 3.6.0)                     
 ps             1.3.2       2020-02-13 [1] CRAN (R 3.6.0)                     
 R6             2.4.1       2019-11-12 [1] CRAN (R 3.6.0)                     
 Rcpp           1.0.4.6     2020-04-09 [1] CRAN (R 3.6.0)                     
 RcppProgress   0.4.2       2020-02-06 [1] CRAN (R 3.6.0)                     
 remotes        2.1.1       2020-02-15 [1] CRAN (R 3.6.0)                     
 reprex         0.3.0       2019-05-16 [2] CRAN (R 3.6.0)                     
 rlang          0.4.5.9000  2020-04-08 [1] Github (r-lib/rlang@a90b04b)       
 rmarkdown      2.1         2020-01-20 [1] CRAN (R 3.6.0)                     
 rprojroot      1.3-2       2018-01-03 [2] CRAN (R 3.5.0)                     
 rstudioapi     0.11.0-9000 2020-02-11 [1] Github (rstudio/rstudioapi@deb9c47)
 sessioninfo    1.1.1       2018-11-05 [2] CRAN (R 3.6.0)                     
 testthat       2.3.2       2020-03-02 [1] CRAN (R 3.6.0)                     
 usethis      * 1.6.0       2020-04-09 [1] CRAN (R 3.6.2)                     
 whisker        0.4         2019-08-28 [1] CRAN (R 3.6.0)                     
 withr          2.1.2       2018-03-15 [2] CRAN (R 3.6.0)                     
 xfun           0.12        2020-01-13 [1] CRAN (R 3.6.0)                     

[1] /Users/mackeyw/Library/R/3.6/library
[2] /Library/Frameworks/R.framework/Versions/3.6/Resources/library
HughParsonage commented 4 years ago

Thanks! Pushed two commits that should address those mistakes.

wfmackey commented 4 years ago

Running now...

wfmackey commented 4 years ago

Looks like there's still one there:

> devtools::load_all()
Loading covid19.model.sa2
Re-compiling covid19.model.sa2
─  installing *source* package ‘covid19.model.sa2’ ...
   ** using staged installation
   ** libs
   clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Users/mackeyw/Library/R/3.6/library/Rcpp/include" -I"/Users/mackeyw/Library/R/3.6/library/dqrng/include" -I"/Users/mackeyw/Library/R/3.6/library/RcppProgress/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fopenmp -std=c++11 -fPIC  -Wall -g -O2  -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always -c RcppExports.cpp -o RcppExports.o
   clang: error: unsupported option '-fopenmp'
   make: *** [RcppExports.o] Error 1
   ERROR: compilation failed for package ‘covid19.model.sa2’
─  removing ‘/private/var/folders/g2/728t399s5gbbk6bgj5ndlgy1w8w938/T/Rtmp6G9Skh/devtools_install_e28872b775ec/covid19.model.sa2’
Error in (function (command = NULL, args = character(), error_on_status = TRUE,  : 
  System command 'R' failed, exit status: 1, stdout + stderr:
E> * installing *source* package ‘covid19.model.sa2’ ...
E> ** using staged installation
E> ** libs
E> clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Users/mackeyw/Library/R/3.6/library/Rcpp/include" -I"/Users/mackeyw/Library/R/3.6/library/dqrng/include" -I"/Users/mackeyw/Library/R/3.6/library/RcppProgress/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fopenmp -std=c++11 -fPIC  -Wall -g -O2  -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always -c RcppExports.cpp -o RcppExports.o
E> clang: error: unsupported option '-fopenmp'
E> make: *** [RcppExports.o] Error 1
E> ERROR: compilation failed for package ‘covid19.model.sa2’
E> * removing ‘/private/var/folders/g2/728t399s5gbbk6bgj5ndlgy1w8w938/T/Rtmp6G9Skh/devtools_install_e28872b775ec/covid19.
[...]
Type .Last.error.trace to see where the err
HughParsonage commented 4 years ago

To clarify you have no OpenMP capability?

On Wed, 22 Apr 2020 at 1:39 pm, Will Mackey notifications@github.com wrote:

Looks like there's still one there:

devtools::load_all()

Loading covid19.model.sa2

Re-compiling covid19.model.sa2

─ installing source package ‘covid19.model.sa2’ ...

** using staged installation

** libs

clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Users/mackeyw/Library/R/3.6/library/Rcpp/include" -I"/Users/mackeyw/Library/R/3.6/library/dqrng/include" -I"/Users/mackeyw/Library/R/3.6/library/RcppProgress/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fopenmp -std=c++11 -fPIC -Wall -g -O2 -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always -c RcppExports.cpp -o RcppExports.o

clang: error: unsupported option '-fopenmp'

make: *** [RcppExports.o] Error 1

ERROR: compilation failed for package ‘covid19.model.sa2’

─ removing ‘/private/var/folders/g2/728t399s5gbbk6bgj5ndlgy1w8w938/T/Rtmp6G9Skh/devtools_install_e28872b775ec/covid19.model.sa2’

Error in (function (command = NULL, args = character(), error_on_status = TRUE, :

System command 'R' failed, exit status: 1, stdout + stderr:

E> installing source* package ‘covid19.model.sa2’ ...

E> ** using staged installation

E> ** libs

E> clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Users/mackeyw/Library/R/3.6/library/Rcpp/include" -I"/Users/mackeyw/Library/R/3.6/library/dqrng/include" -I"/Users/mackeyw/Library/R/3.6/library/RcppProgress/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fopenmp -std=c++11 -fPIC -Wall -g -O2 -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always -c RcppExports.cpp -o RcppExports.o

E> clang: error: unsupported option '-fopenmp'

E> make: *** [RcppExports.o] Error 1

E> ERROR: compilation failed for package ‘covid19.model.sa2’

E> * removing ‘/private/var/folders/g2/728t399s5gbbk6bgj5ndlgy1w8w938/T/Rtmp6G9Skh/devtools_install_e28872b775ec/covid19.

[...]

Type .Last.error.trace to see where the err

— You are receiving this because you authored the thread.

Reply to this email directly, view it on GitHub https://github.com/grattan/covid19.model.sa2/issues/19#issuecomment-617529948, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB54MDHM7GF44LBRPRJSPDLRNZRFHANCNFSM4MNKGPCQ .

wfmackey commented 4 years ago

Not sure what that is. A tool for parallel processing?

HughParsonage commented 4 years ago

Yeah it enables parallelization. It’s what CRAN uses to develop the binaries. Consider the following installation step (recommend the brewless way)

https://github.com/Rdatatable/data.table/wiki/Installation#openmp-enabled-compiler-for-mac

On Wed, 22 Apr 2020 at 2:23 pm, Will Mackey notifications@github.com wrote:

Not sure what that is. A tool for parallel processing?

— You are receiving this because you authored the thread.

Reply to this email directly, view it on GitHub https://github.com/grattan/covid19.model.sa2/issues/19#issuecomment-617540659, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB54MDBHHTTMSTXVKZQFMALRNZWLFANCNFSM4MNKGPCQ .

wfmackey commented 4 years ago

Thanks -- running through that now

HughParsonage commented 4 years ago

Just found this too: https://github.com/rmacoslib/r-macos-rtools

wfmackey commented 4 years ago

r-macos-rtools works -- package loaded. Running covid19.model.sa2::simulate_sa2(20, PolicyPars = list(supermarkets_open = T), nThread = 8L) now

wfmackey commented 4 years ago

Wooh! Looks good:


> covid19.model.sa2::simulate_sa2(20, PolicyPars = list(supermarkets_open = T), nThread = 8L)
15:32:18 Start   
15:32:19 post-read 
15:32:24 pre-C++ 
0%   10   20   30   40   50   60   70   80   90   100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
15:32:43 final 
$nInfected
 [1] 2339 2387 2380 2368 2342 2305 2240 2122 1989 1834 1620 1428 1228 1051  877  719  575  447  321  217

$Statuses
          state       sa2     hid      pid school_id  work_dzn Status InfectedOn Age Resistance
       1:     1 101021007       1        1        NA        NA      0         NA  92        519
       2:     1 101021007       2        2        NA 110078099      0         NA  44        359
       3:     1 101021007       3        3        NA 110078099      0         NA  48        819
       4:     1 101021007       4        4        NA 115390001      0         NA  78        120
       5:     1 101021007       5        5        NA 110078099      0         NA  55        969
      ---                                                                                      
21364881:     9 901041004 8271617 21365049        NA        NA      0         NA  50        309
21364882:     9 901041004 8271617 21365050        NA 910040001      0         NA  25        113
21364883:     9 901041004 8271617 21365051        NA        NA      0         NA   4        270
21364884:     9 901041004 8271617 21365052        NA        NA      0         NA   6        621
21364885:     9 901041004 8271617 21365053        NA 910040001      0         NA  21        130
          nSupermarketsAvbl SupermarketTypical SupermarketHour short_school_id seqN HouseholdSize V1 V2 V3 V4
       1:                 2                  1               1              NA    1             1  0  0  0  0
       2:                 2                  1               4              NA    1             1  0  0  0  0
       3:                 2                  0               0              NA    1             1  0  0  0  0
       4:                 2                  1               6              NA    1             1  0  0  0  0
       5:                 2                  0               2              NA    1             1  0  0  0  0
      ---                                                                                                    
21364881:                 0                  0               1              NA    2             3  0  0  0  0
21364882:                 0                  0               4              NA    3             4  0  0  0  0
21364883:                 0                  0               0              NA    4             5  0  0  0  0
21364884:                 0                  0               6              NA    5             6  0  0  0  0
21364885:                 0                  0               2              NA    6             6  0  0  0  0
          V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21
       1:  0  0  0  0  0   0   0   0   0   0   0   0   0   0   0   0   0
       2:  0  0  0  0  0   0   0   0   0   0   0   0   0   0   0   0   0
       3:  0  0  0  0  0   0   0   0   0   0   0   0   0   0   0   0   0
       4:  0  0  0  0  0   0   0   0   0   0   0   0   0   0   0   0   0
       5:  0  0  0  0  0   0   0   0   0   0   0   0   0   0   0   0   0
      ---                                                               
21364881:  0  0  0  0  0   0   0   0   0   0   0   0   0   0   0   0   0
21364882:  0  0  0  0  0   0   0   0   0   0   0   0   0   0   0   0   0
21364883:  0  0  0  0  0   0   0   0   0   0   0   0   0   0   0   0   0
21364884:  0  0  0  0  0   0   0   0   0   0   0   0   0   0   0   0   0
21364885:  0  0  0  0  0   0   0   0   0   0   0   0   0   0   0   0   0
wfmackey commented 4 years ago

Hugh it was very quick.

HughParsonage commented 4 years ago

Bless! Could you rerun with nThread = 1. Interested to see the performance difference.

wfmackey commented 4 years ago

running with one thread now, will let you know tomorrow when it finishes

wfmackey commented 4 years ago
> mod <- covid19.model.sa2::simulate_sa2(20, PolicyPars = list(supermarkets_open = T), nThread = 1L)
15:35:44 Start   
15:35:45 post-read 
15:35:50 pre-C++ 
0%   10   20   30   40   50   60   70   80   90   100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
15:36:47 final 
HughParsonage commented 4 years ago

Ta! So about 3 times faster with 8 threads. Seems like the multithreading is kicking in properly.

wfmackey commented 4 years ago

@HughParsonage can we spend some time tomorrow running through the code structure and output?

HughParsonage commented 4 years ago

Yep. Also feel free to just click line numbers and raise issues out of curiosity ("what does this do?).

wfmackey commented 4 years ago

That's a better approach.

https://github.com/grattan/covid19.model.sa2/blob/9aa6f1214af55fffd963a0b8b85494f913f9b913/R/set_epipars.R#L43 Can you explain what is going on here with match.arg? It looks like it should have two arguments.

HughParsonage commented 4 years ago

By default, if choices is missing in match.arg the available options are those supplied as the defaults to the first argument. If incubation_distribution is missing, the first of the defaults are used. This is a handy way to simultaneously document and check the allowed arguments to a function.

z <- function(x = c("a", "b", "c")) match.arg(x)
z()
#> [1] "a"
z("b")
#> [1] "b"
z("BBB")
#> Error in match.arg(x): 'arg' should be one of "a", "b", "c"

Created on 2020-04-23 by the reprex package (v0.3.0)

wfmackey commented 4 years ago

I don't understand the p_asympto rate is transformed into the asympto figure here: https://github.com/grattan/covid19.model.sa2/blob/f292c483187b8c7cffe5b8fb87c682e2198e3596/R/simulate.R#L191-L192

Is it just to set it to ~0?

wfmackey commented 4 years ago

What's the significance of 13381 (not that is matters) https://github.com/grattan/covid19.model.sa2/blob/f292c483187b8c7cffe5b8fb87c682e2198e3596/R/simulate.R#L217

Actually, what is the benefit of

rep_len(sample(x, n, TRUE), N))

over

sample(x, N, TRUE)

?

Is it just for flexibility when replace = FALSE?

HughParsonage commented 4 years ago

I don't understand the p_asympto rate is transformed into the asympto figure here: https://github.com/grattan/covid19.model.sa2/blob/f292c483187b8c7cffe5b8fb87c682e2198e3596/R/simulate.R#L191-L192

Note that set_epipars converts percentages into integers out of 1000 (for efficiency -- we don't need more accurate than 99.2%, and integers are memory-efficient). At this point we want the percentage back, so we divide by 1000 before subtracting from 1.


What's the significance of 13381 (not that is matters) https://github.com/grattan/covid19.model.sa2/blob/f292c483187b8c7cffe5b8fb87c682e2198e3596/R/simulate.R#L217

Actually, what is the benefit of

rep_len(sample(x, n, TRUE), N))

over

sample(x, N, TRUE)

?

13381 is just a magic number that is not (likely) to be a fraction of the size of any subsets. We want it to be large enough that any patterns due to the ordering of the data doesn't clump resistance inappropriately in a simulation.

Why rep_len(sample(x, n, TRUE), N))? Speed. It's "well known" that in these sort of models, generating random numbers is often the bottleneck. Indeed the sample would take almost a second on my machine, whereas with rep_len it's pretty negligible even for small days_to_sim.

N <- 21364885  # nrow(aus)
bench::mark(use_rep_len = rep_len(sample(1:1000, size = 13381, replace = TRUE), N),
            just_sample = sample(1:1000, size = N, replace = TRUE))
#> Warning: Each result must equal the first result:
#>   `use_rep_len` does not equal `just_sample`
#> # A tibble: 2 x 10
#>   expression       min      mean    median       max `itr/sec` mem_alloc  n_gc
#>   <chr>       <bch:tm>  <bch:tm>  <bch:tm>  <bch:tm>     <dbl> <bch:byt> <dbl>
#> 1 use_rep_l~  34.648ms  34.789ms  34.737ms  34.969ms     28.7   81.624MB     4
#> 2 just_samp~ 989.844ms 989.844ms 989.844ms 989.844ms      1.01 163.004MB     0
#> # ... with 2 more variables: n_itr <int>, total_time <bch:tm>

Created on 2020-04-25 by the reprex package (v0.3.0)

While in this particular instance the difference wasn't huge, I had just got in the habit of doing rep_len by the time I wrote this. Note that it becomes of major significance when the sample is done every day (hence why we use rep_len and other tricks there too).

wfmackey commented 4 years ago
  1. cool yep makes sense
  2. coooool -- good to know. And speed the same reason for sample() over runif()? (seems to be on my machine)

Turning to resistance, which I think is a really clever way to factor in individual's behaviour. Do you have a basis for resistance1 = 400? Also for resistance_penalty = 100 in the household?

wfmackey commented 4 years ago

Can you explain what r_div is doing in supermarkets? https://github.com/grattan/covid19.model.sa2/blob/f292c483187b8c7cffe5b8fb87c682e2198e3596/src/do_aus_simulate.cpp#L134

HughParsonage commented 4 years ago

No basis for resistance1 = 400 or resistance_penalty = 100. Probably should be an epipar.

Previously, supermarkets were modelled as everyone going to their supermarket simultaneously, r_div attempts to reduce the transmission taking this implementation detail into account.

HughParsonage commented 4 years ago

What does echo |cpp -fopenmp -dM |grep -i open return for you @wfmackey ? Relatedly, how awful would it be if you were obliged to upgrade to R 4.0.0?

wfmackey commented 4 years ago

I have already moved to 4.0.0, so "zero awful".

echo |cpp -fopenmp -dM |grep -i open returns clang: error: unsupported option '-fopenmp'

HughParsonage commented 4 years ago

OK I think that's just MacOS issues. From what I can see you should have support for OpenMP 4.5, which means we can parallelize array constructs.

https://releases.llvm.org/7.0.0/tools/clang/docs/OpenMPSupport.html

Clang fully supports OpenMP 4.5

https://github.com/rmacoslib/r-macos-rtools

clang7

HughParsonage commented 4 years ago

@wfmackey Can you confirm that your 16 GB 8-threaded macOS machine cannot run e.g.

S <- simulate_sa2(49)

Also, if you haven't installed from/checked out the yaml branch, don't -- I intend to squash it as it was mistake to upload the results to the same repo -- but if you have already you could try installing that branch's latest version and

S <- simulate_sa2(49, returner = 1)

which should require slightly less memory.

wfmackey commented 4 years ago

@HughParsonage I reinstalled the current version from master and it seems to have solved the high memory usage issues.

s <- simulate_sa2(100, PolicyPars = set_policypars(schools_open = TRUE))

works for me now in about 70 seconds, which is fine.