brian-lau / MatlabStan

Matlab interface to Stan, a package for Bayesian inference
BSD 3-Clause "New" or "Revised" License
79 stars 47 forks source link

"Having a problem getting stan version" Matlab 2015a error #17

Closed rplab closed 7 years ago

rplab commented 8 years ago

(Moved from the Stan email list. Thanks Brian for your reply, and it's good to know that MatlabStan and OS X can get along!)

Hi, I’ve attempted to install and run MatlabStan (v. 2.7.0; cmdstan 2.8.0; operating system Mac OS X 10.10.5), but am unsuccessful for reasons I can’t figure out. Running, for example, the eight-schools example gives the following error:

Having a problem getting stan version. This is likely a problem with Java running out of file descriptors Trying again. [repeated 6 times] Giving up. Error using processManager/start (line 402) Looks like command doesn't exist. Check spelling or path? Error in processManager/set.command (line 212) self.start(); Error in processManager (line 179) self.command = p.Results.command; _Error in StanModel/stanversion (line 789) p = processManager('id','stanc version','command',command,... Error in StanModel (line 194) _ver = self.stanversion(); Error in stan (line 108) model = StanModel(); _Error in schooltest (line 27) _fit = stan('model_code',schools_code,'data',schoolsdat);

This error & message seems very similar to an issue reported elsewhere, caused by MATLAB not using the appropriate libraries, using its own rather than those in /usr/lib . See e.g. items 13-18 at https://www.mathworks.com/matlabcentral/newsreader/view_thread/162466, or http://sgpsproject.sourceforge.net/JavierVGomez/index.php/Solving_issues_with_GLIBCXX_and_libstdc%2B%2B . However, trying the solutions posted at these places does not work. (Essentially, many of the solutions involve setting the LD_PRELOAD variable to, for example, /usr/lib/libstdc++.so.6 to redirect to the proper libraries.) I think this fails for me because in Mac OS X there is no LD_LIBRARY_PATH variable; the prior discussion of solutions is all for Unix. Also, I don't see libstdc++... in Matlab's binary directories, and don't know what other things I should be looking for. It’s very non-obvious (to me) how to direct Matlab to the proper libraries. (I tried “setenv('DYLD_LIBRARY_PATH', '/usr/lib’);” — this also fails. It is also, of course, possible that the problem is something completely different!

Has anyone used MatlabStan with OS X ? If so, is there some necessary step I’m missing?

(Running Stan from the command line, not through Matlab, works, by the way.)

Any thoughts are very much appreciated!

best wishes,

Raghu

Raghuveer Parthasarathy Group web page: http://physics.uoregon.edu/~raghu/ Blog: http://eighteenthelephant.wordpress.com/

Associate Professor Department of Physics 1274 University of Oregon Eugene, OR 97403-1274 (541) 346-2933 -- office

brian-lau commented 8 years ago

Couple of quick checks: 1) does ProcessManager work? Try running a couple of the examples here: https://github.com/brian-lau/MatlabProcessManager 2) Do you have spaces in any of the directory names?

rplab commented 8 years ago

Hi Brian, 1) Yes. ProcessManager works (I tried the first two examples you listed, and both are fine.) 2) Yes! I now moved cmdstan into a folder that does not contain a space in its name, and MatlabStan runs! Thanks!

(It still gives an error with the 8 schools example, that is now:

Stan is still working. You can either: 1) Use the peek method to get partial samples 2) Come back later, or 3) Attach a listener to the StanFit object. Attempt to reference field of non-structure array. Error in school_test (line 31) eta = fit.extract('permuted',true).eta;

But: I'm not sure if this issue is fatal, and I can think about it. (Ideas?) In any case, thanks a lot for your help! -- Raghu

brian-lau commented 8 years ago

I suspect that the 8 schools problem is due to the extract method getting called before sampling has finished. This would happen if the entire example was evaluated all at once. See here: https://github.com/brian-lau/MatlabStan/wiki/Blocking-the-Matlab-command-line

if you want to extract in a script.

sharnapax commented 8 years ago

Hi, I have the "space in path name" problem but because I am running off a second iMac HDD all paths have "Macintosh HD" in them. If I change this it will throw all sorts of things out of kilter. Is there a fix rather than just change/move?

many thanks

Rob Harrison Sheffield UK

brian-lau commented 8 years ago

Hi Rob

I did not find a simple way to do this. If I recall correctly, I couldn't figure out a way to escape spaces in the command that gets passed through Java.

I think 'Macintosh HD' is just a link to '/', so replacing your references with '/' may solve the problem?

-b

sharnapax commented 8 years ago

Thanks for that Brian but it doesn;t recognise this at all (as below) - at least when I specify /Volumes/Macintosh HD/Users/ ... it gets into the try/catch section. My problem is that I boot and run apps from a SSD and have my user a/c (data etc.) on the HDD so everything needs the full path. Anyway, thanks for the prompt response - I'll keep on hacking! Rob

Error using StanModel/set.stan_home (line 303) Can't parse stan_home. Is it set correctly?

Error in StanModel (line 184) self.stan_home = p.Results.stan_home;

Error in stan (line 108) model = StanModel();

gianlucaRinaldi commented 7 years ago

Thanks for developing this amazing tool! I have the same problem: cmdstan built and working (can use it with Rstan) but Matlab giving the following output

Having a problem getting stan version.
This is likely a problem with Java running out of file descriptors
Trying again.
Trying again.
Trying again.
Trying again.
Trying again.
Trying again.
Giving up.
Output argument "ver" (and maybe others) not assigned during call to "StanModel/stan_version".

Error in StanModel (line 194)
               ver = self.stan_version();

Error in stan (line 108)
   model = StanModel();

I don't have spaces in either the cmdstan install folder nor in the matlab stan folder. Moreover my startup.m file contains the following line: addpath C:\Users\grinaldi\Documents\MATLAB\stan

brian-lau commented 7 years ago

Sorry, seems the error output got suppressed?

gianlucaRinaldi commented 7 years ago

Hi Brian, I've updated my post in case you didn't see!

brian-lau commented 7 years ago

I've seen this problem occasionally, and it seems to be a Java-related issue (java is used for communicating with CmdStan). You may find some clues here:

https://github.com/brian-lau/MatlabProcessManager/wiki/Potential-gotchas#process-fails-to-start

although I don't know how to change things on Windows. If it's not too troublesome, can you try after a restart?

ianthe00 commented 7 years ago

Hi everyone,

I’ve tried to install and run MatlabStan (v. 2.7.0; cmdstan 2.14.0; operating system Operating System: Debian GNU/Linux 8 (jessie), Kernel: Linux 3.16.0-4-amd64)

After adding cmstan and ProcesManager (in addition to MatlabStan) to the MATLAB path, I get the same error some have reported before when testing the simple "eight schools" code:

??? Error using ==> StanModel>StanModel.set.stan_home at 311 Does not look like a proper stan setup

Note: ProcessManager runs properly (tested exampleListener & exitHandler(src,data))

Note 2: I edited stan_home.m in +mstan to include the proper directory

d='/home/myusername/eeg/matlab/bayesian/Stan/cmdstan';

Thanks for any advice!

ianthe00

brian-lau commented 7 years ago

Hi,

Can you confirm that running the CmdStan example from the user's guide runs outside of matlab (ie, at the command line)?

-b

ianthe00 commented 7 years ago

Hi Brian,

thanks for the quick reply. I proceeded today to follow the cmdstan tutorial (Building cmdstan, compiling and executing a program etc) and it works fine from the command line.

After doing that, I tried again to use stan within MATLAB and now it finds the proper stan setup. I have however other issues now (with the version of GLIBCXX in libstdc++.so.6) but I can solve this hopefully by using my other linux machine with the current 2016 MATLAB version.

Thanks for your help. So I guess that the issue was that I had not yet properly configured cmdstan from the command line (using make -j4 and so on)? Do you think it would be possible to explicitly mention this requirement here?

https://github.com/brian-lau/MatlabStan/wiki/Getting-Started

Thanks again

brian-lau commented 7 years ago

Hi,

The wiki has been clarified. Regarding the GLIBCXX error, you may find a solution here:

https://github.com/brian-lau/MatlabStan/wiki/Solving-issues-with-GLIBCXX-and-libstdc

Thanks.

ianthe00 commented 7 years ago

Thanks so much!

ericaashe commented 7 years ago

I am also having a problem getting started running Stan from Matlab. I compiled cmdstan, but when i try to run any of the examples, I get an error. I have stan_home in /MatlabStan-2.7.0.0/+mstan, and I have the directory in stan_home set to my matlab folder, which also contains cmdstan-2.14.0

I get the following error:

Error using StanModel/set.stan_home (line 311) Does not look like a proper stan setup

Error in StanModel (line 184) self.stan_home = p.Results.stan_home;

Error in stan (line 108) model = StanModel();

brian-lau commented 7 years ago

stan_home should be set to the path where the CmdStan is, which is where you built CmdStan, not necessarily where you put the Matlab files.

ericaashe commented 7 years ago

Thanks so much. Now I am having another problem:

Error using matlab.unittest.TestSuite.fromFile (line 159) The specified superclass 'TestCase' contains a parse error, cannot be found on MATLAB's search path, or is shadowed by another file with the same name.

Error in testsuite>createSuite (line 127) suite = TestSuite.fromFile(file, selector);

Error in testsuite>@(test)createSuite(test,selector,logical(parser.Results.IncludeSubfolders),logical(parser.Results.IncludeSubpackages)) (line 87) fun = @(test)createSuite(test, selector, ...

Error in testsuite (line 89) suites = cellfun(fun, cellstr(parser.Results.tests), 'UniformOutput', false);

Error in runtests (line 82) suites = testsuite(parser.Results.tests,pvcell{:});

Error in run_all_tests (line 14) runtests TestBasicArray;

On Fri, Jan 6, 2017 at 2:58 AM, Brian Lau notifications@github.com wrote:

stan_home should be set to the path where the CmdStan is, which is where you built CmdStan, not necessarily where you put the Matlab files.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/brian-lau/MatlabStan/issues/17#issuecomment-270851471, or mute the thread https://github.com/notifications/unsubscribe-auth/AIL7_qkAk-NHVuor2sP5pGu6luOBmXsLks5rPfQsgaJpZM4Gde5U .

brian-lau commented 7 years ago

What version of Matlab are you using? Does the eight schools example from the readme run?

ericaashe commented 7 years ago

2016a

No, and now it is going back to giving me that same error again.

Error using StanModel/set.stan_home (line 311) Does not look like a proper stan setup

Error in StanModel (line 184) self.stan_home = p.Results.stan_home;

Error in stan (line 108) model = StanModel();

On Fri, Jan 6, 2017 at 1:29 PM, Brian Lau notifications@github.com wrote:

What version of Matlab are you using? Does the eight schools example from the readme run?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/brian-lau/MatlabStan/issues/17#issuecomment-270970012, or mute the thread https://github.com/notifications/unsubscribe-auth/AIL7_nryq4G0xCTWKzzP6Nkw5d0WD9TVks5rPof4gaJpZM4Gde5U .

brian-lau commented 7 years ago

Are you able to run CmdStan examples outside of Matlab?

ericaashe commented 7 years ago

This is the error I get when trying to run the bernoulli example from terminal:

make: *** No rule to make target `examples/bernoulli/bernoulli.'. Stop.

On Fri, Jan 6, 2017 at 1:44 PM Brian Lau notifications@github.com wrote:

Are you able to run CmdStan examples outside of Matlab?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/brian-lau/MatlabStan/issues/17#issuecomment-270973835, or mute the thread https://github.com/notifications/unsubscribe-auth/AIL7_pXThTaqGlBGBO5WAsB2gq1K5CtOks5rPouRgaJpZM4Gde5U .

ericaashe commented 7 years ago

I've tried installing and compiling a few times. Maybe I have multiple folders of cmdstan?

On Fri, Jan 6, 2017 at 1:57 PM, Erica Ashe ericaashe@gmail.com wrote:

This is the error I get when trying to run the bernoulli example from terminal:

make: *** No rule to make target `examples/bernoulli/bernoulli.'. Stop.

On Fri, Jan 6, 2017 at 1:44 PM Brian Lau notifications@github.com wrote:

Are you able to run CmdStan examples outside of Matlab?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/brian-lau/MatlabStan/issues/17#issuecomment-270973835, or mute the thread https://github.com/notifications/unsubscribe-auth/AIL7_pXThTaqGlBGBO5WAsB2gq1K5CtOks5rPouRgaJpZM4Gde5U .

ericaashe commented 7 years ago

It worked from the command line. I just had a period there.

Sorry!

On Fri, Jan 6, 2017 at 1:59 PM, Erica Ashe ericaashe@gmail.com wrote:

I've tried installing and compiling a few times. Maybe I have multiple folders of cmdstan?

On Fri, Jan 6, 2017 at 1:57 PM, Erica Ashe ericaashe@gmail.com wrote:

This is the error I get when trying to run the bernoulli example from terminal:

make: *** No rule to make target `examples/bernoulli/bernoulli.'. Stop.

On Fri, Jan 6, 2017 at 1:44 PM Brian Lau notifications@github.com wrote:

Are you able to run CmdStan examples outside of Matlab?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/brian-lau/MatlabStan/issues/17#issuecomment-270973835, or mute the thread https://github.com/notifications/unsubscribe-auth/AIL7_pXThTaqGlBGBO5WAsB2gq1K5CtOks5rPouRgaJpZM4Gde5U .

ericaashe commented 7 years ago

Thanks for your prompt responses. It is working now in Matlab, too. Sorry to trouble you!

Thanks again!

On Fri, Jan 6, 2017 at 2:03 PM, Erica Ashe ericaashe@gmail.com wrote:

It worked from the command line. I just had a period there.

Sorry!

On Fri, Jan 6, 2017 at 1:59 PM, Erica Ashe ericaashe@gmail.com wrote:

I've tried installing and compiling a few times. Maybe I have multiple folders of cmdstan?

On Fri, Jan 6, 2017 at 1:57 PM, Erica Ashe ericaashe@gmail.com wrote:

This is the error I get when trying to run the bernoulli example from terminal:

make: *** No rule to make target `examples/bernoulli/bernoulli.'. Stop.

On Fri, Jan 6, 2017 at 1:44 PM Brian Lau notifications@github.com wrote:

Are you able to run CmdStan examples outside of Matlab?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/brian-lau/MatlabStan/issues/17#issuecomment-270973835, or mute the thread https://github.com/notifications/unsubscribe-auth/AIL7_pXThTaqGlBGBO5WAsB2gq1K5CtOks5rPouRgaJpZM4Gde5U .

mfalcy commented 6 years ago

I'm also "Having a problem getting stan version" when trying to run the eight schools example. For whatever it's worth, processManager seems to work if I enter

p = processManager('command','nslookup www.google.com');

I'm on Windows 10 and MATLAB 2017b.

Full error readout follows.

Thanks in advance!

Having a problem getting stan version. This is likely a problem with Java running out of file descriptors Trying again. Trying again. Trying again. Trying again. Trying again. Trying again. Giving up. Error using processManager/start (line 366) Java exception occurred: java.io.IOException: Cannot run program "C:\Stan\cmdstan-2.17.1\bin\stanc" (in directory "N:\docs\Stan\MatlabStan-2.15.1.0"): CreateProcess error=2, The system cannot find the file specified

at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)

at java.lang.Runtime.exec(Runtime.java:620)

at java.lang.Runtime.exec(Runtime.java:450)

Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified

at java.lang.ProcessImpl.create(Native Method)

at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)

at java.lang.ProcessImpl.start(ProcessImpl.java:137)

at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)

... 2 more

Error in processManager/set.command (line 216) self.start(); Error in processManager (line 181) self.command = p.Results.command; Error in StanModel/stan_version (line 843) p = processManager('id','stanc version','command',command,... Error in StanModel (line 196) ver = self.stan_version(); Error in stan (line 108) model = StanModel();

HashemiScience commented 4 years ago

@mfalcy not sure if you ever solved your issue, but I was having a similar problem and none of the above solutions solved it. I managed to localize the issue to line 850 of StanModel.m. It was not appropriately extracting the stanc version, so I just hardcoded it in (ver = '2.21.0') and it works. I'm sure this can be solved much more elegantly so it isn't hard coded.

SaidehF commented 3 years ago

Hello,

I also have the same problem as mfalcy. I have Matlab2019a and Windows10. I did the above recommendations, but none of them work. I really appreciate if anyone could help me to find the solution.

thanks in advance. Saideh