Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
Loading required package: utils
> #!/usr/bin/env Rscript
> 
> ###############################################################################
> # script pour lancer calibration sur Datarmor avec PBS qsub
> # toutes les variables d���environnement sont d��finies dans le script PBS
> ###############################################################################
> 
> # normalement 2 packages charg��s: {Rmpi} et {snow} qui mettent �� dispo:
> # `makeCluster`, `clusterEvalQ`, `clusterExport`, `stopCluster`
> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: SUSE Linux Enterprise Server 12 SP1

Matrix products: default
BLAS/LAPACK: /appli/intel/parallel_studio/parallel_studio_xe_2017_update2/compilers_and_libraries_2017.2.174/linux/mkl/lib/intel64_lin/libmkl_rt.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] snow_0.4-3 Rmpi_0.6-9

loaded via a namespace (and not attached):
[1] compiler_3.6.3 parallel_3.6.3
> 
> library(doParallel, include.only = c("registerDoParallel")) # pour ��viter d�����craser `makeCluster`
> 
> # la fa��on dont {calibrar} utilise {foreach} perturbe {doParallel}
> # il faut toujours charger tous les pkgs n��cessaires ici et dans `clusterEvalQ` dessous
> # si vous le faites pas en double, erreur ���function not found��� directe!
> #library(calibrar, lib.loc = Sys.getenv("NICO_REPO"))
> library(calibrar, lib.loc = "/home1/datawork/nbarrier/libs/R/lib/")
> library(dplyr, warn.conflicts = FALSE)
> library(data.table, include.only = c("fread"))
> library(stringi, include.only = c("stri_extract_last_regex", "stri_join"))
> options(dplyr.summarise.inform = FALSE)
> 
> cl <- makeCluster()
> registerDoParallel(cl)
> 
> clusterEvalQ(cl, {
+ #  library(calibrar, lib.loc = Sys.getenv("NICO_REPO"))
+   library(calibrar, lib.loc = "/home1/datawork/nbarrier/libs/R/lib/")
+   
+ 	library(dplyr, warn.conflicts = FALSE)
+ 	library(data.table, include.only = c("fread"))
+ 	library(stringi, include.only = c("stri_extract_last_regex", "stri_join"))
+ 	options(dplyr.summarise.inform = FALSE)
+ }) %>% # cacher des messages encombrants
+ suppressMessages() %>%
+ suppressWarnings() %>%
+ capture.output() %>%
+ invisible()
> 
> ###############################################################################
> 
> runModel <- function(par) { # "par" provided by the calibrate function
+ 
+ 	# run ISIS ======================================================
+ 	# ATTENTION we are in RUN_*/i* folder
+ 
+ 	# if necessary, manually save q of each generation
+ 	current_time <- format(Sys.time(), format = "%F %Hh%M", tz = "CET", usetz = TRUE)
+ 	current_gen <- 1L + length(list.files(pattern = "^params .+\\.csv$"))
+ 	info_suffix <- sprintf(" gen %03d start %s", current_gen, current_time)
+ 
+ 	# get back the capturability parameters (par) and write them in the format the model is able to read (csv, semantic)
+ 	textLines <- readLines(Sys.getenv("PARAMS_FILE"))
+ 	for (i in seq_along(par)) {
+ 		id <- 2 + i
+ 		tmp <- strsplit(textLines[id], ";")[[1]]
+ 		textLines[id] <- paste0(tmp[1], ";", par[i])
+ 	}
+ 	write(textLines, file = Sys.getenv("PARAMS_FILE"))
+ 	file.copy(from = Sys.getenv("PARAMS_FILE"), to = paste0("params", info_suffix, ".csv"))
+ 
+ 	# launch ISIS from R, cf le script PBS
+ 	current_ind <- basename(getwd()) # current individual of the population
+ 	nomSimul_i <- Sys.getenv("SIMUL_BASENAME") %>% paste(., current_ind, sep = "_")
+ 	# debug_file <- paste0("debugISIS", info_suffix, ".log")
+ 	system2("myIsis", args = nomSimul_i, stdout = "debugISIS_octopus2017.log", stderr = "debugISIS_octopus2017.log")
+ 
+ 	dossier_simul <- file.path(Sys.getenv("ISIS_BD"), "isis-database/simulations", nomSimul_i, "resultExports")
+ 
+ 	# read the model outputs and tranform them into a list ==========
+ 
+ 	# catch at age
+ 	export1 <- file.path(dossier_simul, "CapturesPoids.csv") %>%
+ 		fread(data.table = FALSE) %>%
+ 		mutate(names = paste0("gp",group,"_Octopus2017")) %>%
+ 		select(names, value)
+ 
+ 	
+ 	# combine (if several inputs)=======================================================
+ 	# export <- rbind(export1, export2)
+ 	export <- export1
+ 	output <- as.list(export$value)
+ 	names(output) <- export$names
+ 	return(output)
+ 	
+ 	
+ 	
+ 	# path_export <- file.path(ifelse(Mon_disk == "~", "~", "c:/Users/Dedah"), paste0("isis-fish-4/isis-database/simulations/", nomSimu, "/resultExports/"))
+ 	export1 <- read.table(paste(dossier_simul, "Captures_AgeStructure_pop.csv", sep = '/'), header = TRUE, sep = ';')
+ 	export2 <- read.table(paste(dossier_simul, "Captures_MoisStructure_pop.csv", sep = '/'), header = TRUE, sep = ';')
+ 	
+ 	
+ 	export2 = export2[-c(1:5, 11:12),]
+ 	df.output <- data.frame('step'=c(paste("gp", c(0, 1:2) ,"_" ,"2018" , sep =""), paste("Mois", c(6:10) ,"_" ,"2018" , sep =""))
+ 	                        , 'value'=NA)
+ 	
+ 	for (i in 1:3) {
+ 	  df.output[i,2] <- export1[i, 4]
+ 	}
+ 	
+ 	
+ 	for (i in 4:8) {
+ 	  df.output[i,2] <- export2[i-3, 3]
+ 	}
+ 	
+ 	output <- list()
+ 	for (i in 1:dim(df.output)[1]) {
+ 	  output[[i]] <- df.output[i,2]
+ 	}
+ 	
+ 	names(output) <- c(df.output[,1])
+ 	
+ 	return(output) ## List of nb year X nb pop group  elements : captures per age, per year
+ 	
+ 
+ }
> 
> ###############################################################################
> 
> #' @title residual sum of squares function
> #' @description name of this fx must match what is declared in calibrationInfo.csv
> #' @param obs,sim numeric values of LENGTH 1
> userFunction <- function(obs, sim) {
+ 	# obs peut ��tre NA, c-a-d pas de valeurs observ��es mais valeurs simul��es existent dans les exports
+ 	# d�� �� des combinaisons irr��elles entre flottille avec GSA zone pop
+ 	res <-
+ 		if (is.na(obs))    0
+ 		else if (obs == 0) sim
+ 		else               (obs - sim) / obs
+ 	return(res ^ 2)
+ }
> 
> # calibrationInfo
> calib_set <- calibration_setup(
+ 	file = "data_calib/data_calib_Octopus2017/calibrationInfo.csv",
+ 	control = list(col_skip = 1) # pour compatibilit�� avec ancienne version
+ )
Error in calibration_setup(file = "data_calib/data_calib_Octopus2017/calibrationInfo.csv",  : 
  could not find function "calibration_setup"
Execution halted
