ropensci / nlrx

nlrx NetLogo R
https://docs.ropensci.org/nlrx
GNU General Public License v3.0
77 stars 12 forks source link

Java requirements, JAVA_HOME, JRE path setting unclear #32

Closed tmwaring closed 4 years ago

tmwaring commented 4 years ago

Dear @nldoc,

Excited to use nlrx. It looks like the best way to connect R and NetLogo yet. I am having trouble getting it to work, and the problem seems to be the java version, or failing to connect to the JRE (java runtime environment). I have:

I use the code:

netlogopath <- file.path("/Applications/NetLogo 6.1.0") modelpath <- file.path(netlogopath, "/Applications/NetLogo 6.1.0/models/Sample Models/Biology/Wolf Sheep Predation.nlogo")

nl <- nl(nlversion = "6.1.0", nlpath = netlogopath, modelpath = modelpath, jvmmem = 1024)

nl@experiment <- experiment(expname="wolf-sheep", outpath="~/Desktop/", repetition=1, tickmetrics="true", idsetup="setup", idgo="go", idfinal=NA_character_, idrunnum=NA_character_, runtime=50, evalticks=seq(40,50), metrics=c("count sheep", "count wolves", "count patches with [pcolor = green]"), variables = list(), constants = list("initial-number-sheep" = 20, "initial-number-wolves" = 20, "model-version" = "\"sheep-wolves-grass\"", "grass-regrowth-time" = 30, "sheep-gain-from-food" = 4, "wolf-gain-from-food" = 20, "sheep-reproduce" = 4, "wolf-reproduce" = 5, "show-energy?" = "false"))

nl@simdesign <- simdesign_simple(nl=nl, nseeds=3)

results <- run_nl_all(nl)

And I get this error:

JAVA_HOME undefined, using java from path. For control over exact java version, set JAVA_HOME Exception in thread "main" java.lang.UnsupportedClassVersionError: org/nlogo/headless/Main : Unsupported major.minor version 52.0

How do I set JAVA_HOME, as it is not a package variable, apparently? Thanks!

tmwaring commented 4 years ago

After searching stackoverflow, I learned how to set JAVA_HOME in the terminal. I also installed a Java 1.8.x JDK. And how NLRX is running. Despite this, I still get the error:

JAVA_HOME undefined, using java from path. For control over exact java version, set JAVA_HOME

for every simulation NLRX runs. I suspect this is not ideal. How to set JAVA_HOME in a way that NLRX likes, so that it is persistent? Even more importantly, it would be good to set JAVA_HOME from within NLRX, or do something that has the same effect, telling LNRX where the right JRE is.

Here is how I set JAVA_HOME on MacOS, from the terminal: echo $JAVA_HOME to make sure it's set to a good version of the JRE. Running the line: /usr/libexec/java_home gives me the output: /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home then set JAVA_HOME with this line: export JAVA_HOME=$(/usr/libexec/java_home)

Also, to discover your java version, from the terminal: java -version

nldoc commented 4 years ago

@tmwaring thank you very much for your feedback. Good to hear, that you could solve part of the problem by installing the Java 1.8.x JDK. It took a while to figure out the problem because I did not have a mac at hand. Luckily, a colleague helped me out with debugging this issue. We could reproduce the problem (run_nl_all was running succesfully but the warning message still appeared). We set JAVA_HOME from the terminal, as you did. Interestingly we were able to run nlrx succesfully from an R session started in the terminal without the warning.

We figured out it might be a problem with Rstudio not sourcing the environmental variables correctly. Luckily, we found a way to solve this problem. You just need to set the JAVA_HOME environmental variable from within your Rstudio session, like this: Sys.setenv(JAVA_HOME = "/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home") You may add this line to your .Rprofile file to execute this code on startup of R. You can verify this by executing system("echo $JAVA_HOME"). Before executing the Sys.setenv() line above it will probably report "", whereas after running the Sys.setenv() line above, it should report the path to your java installation.

tmwaring commented 4 years ago

Dear @nldoc,

Wow, good sleuthing! Because nlrx was working (on three different machines), I was just accepting the error. But your discovery that RStudio is not sourcing the environmental variables correctly explains everything. I've tested your new R code, and can confirm it works just as you said!

Thanks so much!

nldoc commented 4 years ago

My pleasure. I am glad the solution works out on your system as well :)

tmwaring commented 4 years ago

Happy that nlrx exists! It's not very user friendly or perfectly documented yet, though. I'm working through various complexities with optimization and parameter sampling now as well. Looking forward to a full version 1.0! One thing that would be nice is a computed "# of runs" which nl_run() could print just before starting the runs. Or even a more verbose set of reporting such as:

model: model_name exper: experiment_type design: sim_design runs: 525

run? (y/n) or (t) for test run:

On Tue, Nov 19, 2019 at 9:03 AM nldoc notifications@github.com wrote:

My pleasure. I am glad the solution works out on your system as well :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ropensci/nlrx/issues/32?email_source=notifications&email_token=ACUQ2L3Y23TICULA235UKVDQUPWZ7A5CNFSM4JOEYM62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEOJI5Y#issuecomment-555521143, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUQ2LYYE4HDI6XHFB7LO6LQUPWZ7ANCNFSM4JOEYM6Q .

nldoc commented 4 years ago

Thanks again for your very helpful feedback. You are right, currently there is not much console output. But in my opinion it is also challenging to find the right mix of useful console output vs spamming the console. But I will defenitely think about your suggestions. I like the idea of having a summary output, maybe by providing an nl-object specific output for the basic summary() function. Then, one could do summary(nl) to get a nice formatted overview of the current nl object. I will check that out soon. I am not sure about interactive console queries, personally I do not find them really helpful. For doing test runs, you can also use the run_nl_one() function. And documentation-wise, I hope you did check out our webpage? The link is somewhat hidden at the top of the github repository, so I just wanted to make sure you are aware of that webpage, which contains a lot more detailed instructions and examples (check out the "More" menu at the top). Best regards

tmwaring commented 4 years ago

Hi Jan (I assume it's Jan),

Oh, I like your suggestion very much: "summary output, maybe by providing an nl-object specific output for the basic summary() function." This way a careful R programmer can just run some test code before starting a large run.

And yes, I've been all over the webpage. It's very handsome, and complete, and because it is early still (v0.3.0) this is enough. However, as it matures the documentation will as well. So adding things like this issue with RStudio (on the mac only, I guess?) to some troubleshooting page, might be useful.

Best,

Tim Waring Associate Professor, School of Economics Mitchell Center for Sustainability Solutions, University of Maine web: timwaring.info, phone: 207-581-3157

On Tue, Nov 19, 2019 at 11:03 AM nldoc notifications@github.com wrote:

Thanks again for your very helpful feedback. You are right, currently there is not much console output. But in my opinion it is also challenging to find the right mix of useful console output vs spamming the console. But I will defenitely think about your suggestions. I like the idea of having a summary output, maybe by providing an nl-object specific output for the basic summary() function. Then, one could do summary(nl) to get a nice formatted overview of the current nl object. I will check that out soon. I am not sure about interactive console queries, personally I do not find them really helpful. For doing test runs, you can also use the run_nl_one() function. And documentation-wise, I hope you did check out our webpage https://ropensci.github.io/nlrx/? The link is somewhat hidden at the top of the github repository, so I just wanted to make sure you are aware of that webpage, which contains a lot more detailed instructions and examples (check out the "More" menu at the top). Best regards

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ropensci/nlrx/issues/32?email_source=notifications&email_token=ACUQ2L7J6RXU2AVCPCGGA43QUQE5TA5CNFSM4JOEYM62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEOWWJI#issuecomment-555576101, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUQ2L55EUSHURCDC4SVEJTQUQE5TANCNFSM4JOEYM6Q .