r-and-gama / gamar

An R interface to the GAMA platform (https://gama-platform.github.io)
https://r-and-gama.github.io/gamar
Other
13 stars 4 forks source link

Call to gama are not working on Windows #1

Open LucieContamin opened 5 years ago

LucieContamin commented 5 years ago

After downloading, installing and using defpath to link GAMA and rama on Windows, I try to run the code:

gaml_file <- system.file("models", "sir.gaml", package = "rama")
exp1 <- load_experiment("sir", gaml_file)

and I obtain the error:

Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") : 
    cannot open file `C:\Users\TEMPFILE.stdout` : No such file or directory

It might be an error coming from the function system2 which returns an error 127.

LucieContamin commented 5 years ago

It might be because the path in R are written like C:/Program Files/gama and should be something like: C:\Program Files\gama (needed to be tested)

DAM-Philippon commented 4 years ago

Hi, got the same problem, any update or workaround on this one ?

> gaml_file <- system.file("models", "sir.gaml", package = "rama")
> exp1 <- load_experiment("sir", gaml_file)
Loading experiment "sir" from file ""...
active display
> JAI/ImageIO subsystem activated
An error has occurred. See the log file
C:\Users\damie\Documents\workspace\.metadata\.log.
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
  cannot open file 'C:\Users\damie\AppData\Local\Temp\RtmpiCv1Xw\file171cc7b8c17b0.stdout': No such file or directory
daanieo commented 3 years ago

The bug could be related to LucieContamin's message:

It might be because the path in R are written like C:/Program Files/gama and should be something like: C:\Program Files\gama (needed to be tested)

But: on my machine (Linux Mint 20), I ran into the same problem as you. For me, the problem lies in the call_gama function, more specifically where the Headless Java command is formulated: run$exitStatus <- system2( command = 'java', args = c('-jar', getOption("gamar.startjar"), '-Xms', getOption("gamar.Xms"), '-Xmx', getOption("gamar.Xmx"), '-Djava.awt.headless=true org.eclipse.core.launcher.Main', '-application msi.gama.headless.id4', '-hpc', hpc, '-v', parameter_xml_file, output_dir_gama, '>', shQuote(stdoutFile), '2>', shQuote(stderrFile)))

My suspicion is that in our case the function does not properly handle the output and subsequently the following line:

 run$stdout <-  readLines(stdoutFile)
  run$stderr <-  readLines(stderrFile)

causes the error we're after.

In my case, running an experiment using the call_gama function created an ouput XML in the same folder as the parameter_xml_file is located. I wrote some extra code around call_gama in order to import the experiment outcomes and so bypassing the parts of load_experiment that didn't work for me:

call_gama(tmp_xml,hpc=2,output_dir = tmp_dir) # run gama model

# import outcome xml 
tmp_df<-XML::xmlToDataFrame(XML::xmlParse(paste0(tmp_dir,"/","simulation-outputs",simulation_id,".xml")), stringsAsFactors = FALSE)