stan-dev / pystan2

PyStan, the Python interface to Stan
GNU General Public License v3.0
920 stars 189 forks source link

Running PySTAN on Windows 10 #723

Closed saccpp closed 3 years ago

saccpp commented 4 years ago

I am trying to compile the following sample code on WIN 10

import pystan model_code = 'parameters {real y;} model {y ~ normal(0,1);}' model = pystan.StanModel(model_code=model_code) y = model.sampling().extract()['y'] print(y.mean()) # with luck the result will be near 0

The code is running from the past 30 minutes with following message

INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_5944b02c79788fa0db5b3a93728ca2bf NOW.

with no output, Can you suggest to speed up the execution?

ahartikainen commented 4 years ago

Hi, are you running your code in jupyter notebook? See the cmd window for possible error msg.

Have you followed our Windows instructions?

https://pystan.readthedocs.io/en/latest/windows.html

saccpp commented 4 years ago

Hello, I am using Spyder. I also tried cmd window, I was getting the following error

RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase. This probably means that you are not using fork to start your child processes and you have forgotten to use the proper idiom in the main module: if name == 'main': freeze_support() ... The "freeze_support()" line can be omitted if the program is not going to be frozen to produce an executable. During handling of the above exception, another exception occurred:

I followed the instruction mentioned in the link.

ahartikainen commented 4 years ago

Ok, can you first try adding this to .sampling -> n_jobs=1.

I assume this is somekind of "bug" with multiprocessing on Windows + spyder. (in cmd the script needs to be under following block)

if __name__ == "__main__":
    #compile and sample here
saccpp commented 4 years ago

Setting n_jobs=1 does compile code on Spyde in Windows.

ahartikainen commented 4 years ago

Hi, could you try solution mentioned here?

https://stackoverflow.com/questions/34821877/joblib-parallel-running-through-spyder-hanging-on-windows