kingaa / pomp

R package for statistical inference using partially observed Markov processes
https://kingaa.github.io/pomp
GNU General Public License v3.0
111 stars 27 forks source link

rm: cannot remove 'tmp.def': Permission denied #120

Closed alexandrasouly closed 4 years ago

alexandrasouly commented 4 years ago

Hi Aaron,

I am occasionally getting an error message that is very mysterious to me. I tried to run the following code as a local job, I closed everything else before it and left it alone for the night: ("full_pomp_model.R" creates my pomp object)

source("full_pomp_model.R", local = TRUE)

library(foreach)
library(iterators)
library(dplyr)
library(ggplot2)
library(ggpubr)

library(doParallel)
registerDoParallel(cores= 8)
library(doRNG)
registerDoRNG(625904618)
library(pomp)

sobolDesign(
  lower=model_4_params_lower,
  upper=model_4_params_upper,
  nseq=20
) -> guesses

Nmif = 30
Np = 2000
# filtering---
  run_time <- system.time({
        mf3<- foreach(guess=iter(guesses,"row"),
                  .combine=c, 
                  .packages = "pomp"

        ) %dopar%
        {
          mif2( 
            pomp_object,
            params = guess,
            Nmif = Nmif, 
            Np = Np, 
            cooling.fraction.50=0.5,
            cooling.type="geometric",
            rw.sd=rw.sd(R0=0.02, rho_val=0.02, epsilon_val = 0.02, zeta=0.02,
                        c=0.02, s=0.02, phi=0.02, s_v=0.02, phi_v=0.02, disp=0.02, d=0.01)
          )
        }
  })

  save(Nmif, Np, run_time, guesses,  file = "Sili_filtering_proper.rda")

  mf3 %>%
    traces() %>%
    melt() %>%
    filter(variable %in% c("loglik", "R0", "rho_val", "epsilon_val",  "zeta", "c",
           "s", "phi","s_v", "phi_v", "disp", "d") )%>%
    ggplot(aes(x=iteration,y=value,group=L1,color=L1))+
    geom_line()+
    facet_wrap(~variable,scales="free_y")+
    guides(color=FALSE)

After successfully sourcing the file and loading the packages, it gave the following error message after 1h45min of runtime:

Error in { : 
  task 2 failed - "in 'mif2': cannot compile shared-object library 'C:/Users/alexa/AppData/Local/Temp/RtmpeW8GFr/21988/pomp_8a9000e487110376cee3fda4cf60ea76.dll': status = 1
compiler messages:
"C:/rtools40/mingw64/bin/"gcc  -I"C:/PROGRA~1/R/R-40~1.1/include" -DNDEBUG          -O2 -Wall  -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c C:/Users/alexa/AppData/Local/Temp/RtmpeW8GFr/21988/pomp_8a9000e487110376cee3fda4cf60ea76.c -o C:/Users/alexa/AppData/Local/Temp/RtmpeW8GFr/21988/pomp_8a9000e487110376cee3fda4cf60ea76.o
C:/rtools40/mingw64/bin/gcc -shared -s -static-libgcc -o C:/Users/alexa/AppData/Local/Temp/RtmpeW8GFr/21988/pomp_8a9000e487110376cee3fda4cf60ea76.dll tmp.def C:/Users/alexa/AppData/Local/Temp/RtmpeW8GFr/21988/pomp_8a9000e487110376cee3fda4cf60ea76.o -LC:/PROGRA~1/R/R-40~1.1/bin/x64 -lR
rm: cannot remove 'tmp.def': Permission denied
make: *** [C:/PROGRA~1/R/R-40~1.1/share/make/winshlib.mk:13: C:/Users/alexa/AppData/Local/Temp/RtmpeW8GFr/21988/pomp_8a9000e487110376cee3
Calls: sourceWithProgress ... do.call -> <Anonymous> -> do.call -> %dopar% -> <Anonymous>```

Then, to see what was wrong, I changed to the smaller values

sobolDesign(
  lower=model_4_params_lower,
  upper=model_4_params_upper,
  nseq=2
) -> guesses
Nmif = 10
Np =  30

and this ran without any issues. I am not sure what is triggering the previous error, but I seem to get it randomly.

I'm running R version 4.0.1 (2020-06-06) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 17134)

kingaa commented 4 years ago

@szantamano: This appears to be a problem with the settings on your Windows operating system, or possibly with your installation of Rtools. The issue is that a temporary file created during the compilation of C snippets has incorrect permissions. As such, I do not think it is an issue with pomp per se, since it should arise when you use R CMD SHLIB to compile code. The fact that it arises randomly suggests, however, that it may be a bug in the operating system that is triggered when many temporary files are created. This in turn suggests a workaround.

In building the pomp object (i.e., in your "full_pomp_model.R"), use the cdir and cfile options to cause the C snippets to be compiled in the current working directory. See, for example, here. Does this solve the problem?

alexandrasouly commented 4 years ago

It did work like magic, thanks a lot! Alexandra

kingaa commented 4 years ago

That's great @szantamano! By the way, although this is, I think, the first time I've seen the issue with the tmp.def file specifically, other Windows users have reported similar issues fixed in this same way, as I mentioned. I've wondered how to deal with this in a more efficient way. The problem with writing an FAQ is that the error messages vary. Maybe I just need to have a whole set of FAQs, one for each class of error message? That seems inefficient. For the moment, I have inserted a section entitled "Note to Windows users" into the help pages for all or most relevant pomp algorithms. People are not very good about reading the help pages, especially when these are long. Do you have any ideas as to how we can save other Windows users the trouble that you've been through?

alexandrasouly commented 4 years ago

I think the first page I checked was the POMP FAQ page (https://kingaa.github.io/pomp/FAQ.html), so I think adding the "Note to Windows users" section there would be helpful!