Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential solutions for the problems of using MatlabStan in Windows systems #57

Open
Mack-Ma opened this issue Feb 24, 2020 · 1 comment

Comments

@Mack-Ma
Copy link

Mack-Ma commented Feb 24, 2020

Hi Brian,

I'm using MatlabStan for cognitive modeling right now. It's very helpful for me. Thanks so much for developing this amazing toolbox!

The problem of getting stan version

However, when I first tested it by using the 8-school example, the following error messages pop out,

Having a problem getting stan version.
This is likely a problem with Java running out of file descriptors
Trying again. (6 times)
Giving up.
You can try setting the Stan version explicitly using the stan_version attribute.
i.e. StanModel.stan_version = [2 15 0]
Error using cellfun
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.
Error in StanModel/get_stan_version_ (line 932)
            ver = cellfun(@str2num,regexp(str{3},'\.','split'));
Error in StanModel/get_stan_version (line 897)
               ver = self.get_stan_version_();
Error in StanModel (line 197)
            self.stan_version = self.get_stan_version();

It seems that some other users came across this problem as well (e.g. #17).

I'm using Cmdstan 2.22.0, Matlab 2016a & Windows 10.
I looked into the script (StanModel.m) and found that the string that the command (Line 923 in StanModel.m) obtained is actually,

stanc3 b5b5a3ca (Win32)

which might not stand for the version of Stan.
I think that might originate from the update of CmdStan. After 2.22.0, Stan was using stanc3 to transcompile Stan to C++. This compiler was actually named as stanc.exe and the old stanc.exe was then named as stanc2.exe instead. Hence, my problem could be simply solved by adapting the original code (line 923 in StanModel.m)

command = [fullfile(self.stan_home,'bin','stanc') ' --version'];

as

command = [fullfile(self.stan_home,'bin','stanc2') ' --version'];

Nonetheless, users might still want to make sure that their MatlabProcessManager & CmdStan work smoothly beforehand.

The problem of using make in Windows systems

Besides, there might be another part in StanModel.m that needs adaptation for Windows users.
Given that Windows users should use mingw32-make instead of make in the command line, line 990, 994 & 996

command = ['make ' flags 'bin/' target];
command = ['make ' flags regexprep(self.model_binary_path,'\','/')];
command = ['make ' flags self.model_binary_path];

should be respectively adapted as

command = ['mingw32-make ' flags 'bin/' target];
command = ['mingw32-make ' flags regexprep(self.model_binary_path,'\','/')];
command = ['mingw32-make ' flags self.model_binary_path];

There might be some other similar cases in the scripts that needs to be adapted for Windows users.

The 8-school example could run smoothly after these two adaptations in my case. Hopefully my experience could help other users that came across these problems.

Best,
Ma, Tianye

@xtmgit
Copy link

xtmgit commented Dec 28, 2020

Regarding The problem of getting stan version:
I'm using cmdstan 2.25.0, Matlab 2019b and MatlabStan 2.15.1.0. on Windows 10

I solved this problem by making a small change in the function stan_version in StanModel.m (function starts at line 841).
Changing line 850 from

ver = cellfun(@str2num,regexp(str{3},'\.','split'));

to

ver = cellfun(@str2num,regexp(str{2}, '\d*', 'Match'));

enables the function to correctly extract the version number.

Small disclaimer, it was a while since I did this and there is a small chance that I'd made some additional change to make it work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants