USCbiostats / slurmR

slurmR: A Lightweight Wrapper for Slurm
https://uscbiostats.github.io/slurmR/
Other
58 stars 12 forks source link

Error in save.image(name) when running R task in batch mode using slurm #34

Closed lyfranki closed 2 years ago

lyfranki commented 2 years ago

Hi, When I run the R codes on the Linux, it works well. But when I ran R in batch mode on Linux, I always got the same error. The following are my .sh file, .R file and .out file. APSIM.out was created automatically. It shows that "Error in save.image(name) :", but I already told R not to save workspace "--vanilla". Do you have any suggestions about it? Maybe it is unrelated with Apsimx packages, but with R. Thanks!

APSIM.sh

#!/bin/bash
#SBATCH --time=00:30:00
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=16
#SBATCH --job-name="myjob"
#SBATCH --partition=secondary
#SBATCH --output=myjob.o%j
#SBATCH --dependency=afterany:<JobID>

conda activate ly-envi

cd xx/xx/xx/apsim
srun R --vanilla CMD BATCH  APSIM.R APSIM.out

APSIM.R


library(soilDB)
library(sp)
library(sf)
library(spData)
library(apsimx)
library(raster)
library(lubridate)
estimated_sowing_list = list()

apsim_path = "/data/keeling/a/xx/apsim/apsim_2016.txt"
apsim_input <- read.delim(apsim_path,header = FALSE, sep = ",", dec = ",")
colnames(apsim_input) <- c('SD','B21','B25','Long','Lati')
head(apsim_input)

apsimx_options(exe.path = "/data/keeling/a/xxx/ApsimX/bin/Debug/netcoreapp3.1/Models")

for (i in 1:2) {

  options(digits=15)
  filed_latilongi = c(as.double(as.character(apsim_input$Long[i])) , as.double(as.character(apsim_input$Lati[i]) ) )

  # extd.dir <- system.file("extdata", package = "apsimx")
  tmp.dir ="/data/keeling/a/xxx/apsim/"

  dmet12 <- get_daymet_apsim_met(lonlat = filed_latilongi, years = c(2016))
  write_apsim_met(dmet12,wrt.dir = tmp.dir, filename = "test.met")

    print(i)

}

APSIM.out


[Previously saved workspace restored]

> 
> library(soilDB)
> library(sp)
> library(sf)
Linking to GEOS 3.8.0, GDAL 3.0.2, PROJ 6.2.1; sf_use_s2() is TRUE
> library(spData)
To access larger datasets in this package, install the spDataLarge
package with: `install.packages('spDataLarge',
repos='https://nowosad.github.io/drat/', type='source')`
> library(apsimx)
APSIM(X) not found.
                        If APSIM(X) is installed in an alternative location,
                        set paths manually using 'apsimx_options' or 'apsim_options'.
                        You can still try as the package will look into the registry (under Windows)
> library(raster)
> library(lubridate)

Attaching package: 'lubridate'

The following objects are masked from 'package:raster':

    intersect, union

The following objects are masked from 'package:base':

    date, intersect, setdiff, union

> estimated_sowing_list = list()
> 
> 
> apsim_path = "/data/keeling/a/xxx/apsim/apsim_2016.txt"
> apsim_input <- read.delim(apsim_path,header = FALSE, sep = ",", dec = ",")
> colnames(apsim_input) <- c('SD','B21','B25','Long','Lati')
> head(apsim_input)
   SD B21 B25                 Long                 Lati
1 111 145 150  -89.48824446937473    39.29027168436681 
2 108 133 137   -89.5437797576881    39.21354130583063 
3 144 164 168   -89.5826152805141    39.08288777713276 
4 115 132 138  -89.83044110359363    39.12534519941483 
5 145 155 159  -89.51309913395067   39.370810476566184 
6 109 140 144  -89.37520541425403    39.49220820731174 
> 
> apsimx_options(exe.path = "/data/keeling/a/xxx/ApsimX/bin/Debug/netcoreapp3.1/Models")
> 
> for (i in 1:1) {
+   
+   options(digits=15)
+   filed_latilongi = c(as.double(as.character(apsim_input$Long[i])) , as.double(as.character(apsim_input$Lati[i]) ) )
+   
+   # extd.dir <- system.file("extdata", package = "apsimx")
+   tmp.dir ="/data/keeling/a/xxx/apsim/"
+ 
+   dmet12 <- get_daymet_apsim_met(lonlat = filed_latilongi, years = c(2016),silent=TRUE)
+   write_apsim_met(dmet12,wrt.dir = tmp.dir, filename = "test.met")
+   summary(dmet12)
+   ## Check for reasonable ranges 
+   check_apsim_met(dmet12)
+   print(i)
+ 
+ }
[1] 1
Warning message:
In check_apsim_met(dmet12) :
  Last year in the met file is a leap year and it only has 365 days
> 
> proc.time()
   user  system elapsed 
  5.752   0.380  13.795 
Error in save.image(name) : 
  image could not be renamed and is left in .RDataTmp
Calls: sys.save.image -> save.image
In addition: Warning message:
In file.rename(outfile, file) :
  cannot rename file '.RDataTmp' to '.RData', reason 'No such file or directory'
Execution halted
gvegayon commented 2 years ago

Not sure what would be the problem here. Are you using slurmR in any way? BTW, it does seem you are restoring a previously saved environment. Try to get rid of the .RData file located in the folder where your script is running.