pystan doesn't load when trying to execute example on home page
bob-carpenter opened this issue · 4 comments
I typed in the example from the image on your home page (included below), but it fails on loading pystan.
Here's the result of the pip install:
~/github/abhiagwl/vistan (master)$ pip install vistan
...
Successfully installed aiohttp-3.8.4 aiosignal-1.3.1 appdirs-1.4.4 async-timeout-4.0.2 autograd-1.5 charset-normalizer-3.1.0 clikit-0.6.2 crashtest-0.3.1 frozenlist-1.3.3 future-0.18.3 httpstan-4.9.1 idna-3.4 joblib-1.2.0 marshmallow-3.19.0 multidict-6.0.4 pastel-0.2.1 pylev-1.4.0 pysimdjson-5.0.2 pystan-3.6.0 vistan-0.0.0.6 webargs-8.2.0 yarl-1.8.2
[notice] A new release of pip is available: 23.0 -> 23.0.1
[notice] To update, run: python3.9 -m pip install --upgrade pip
It says pystan-3.6.0 is installed, but when I try to run it through the script attached below, I get this:
~/github/abhiagwl/vistan/sandbox (master)$ python3
Python 3.9.4 (default, Apr 5 2021, 01:47:16)
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exec(open('bernoulli-eg.py').read())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.9/site-packages/vistan/__init__.py", line 1, in <module>
from .inference import algorithm, recipe
File "/usr/local/lib/python3.9/site-packages/vistan/inference.py", line 7, in <module>
import vistan.interface as interface
File "/usr/local/lib/python3.9/site-packages/vistan/interface.py", line 1, in <module>
import pystan
ModuleNotFoundError: No module named 'pystan'
Independently installing pystan
also doesn't work. @justindomke suggested it may be a Python version number.
Here's the script I transcribed from the image on the home page:
import vistan
import matplotlib.pyplot as plt
import numpy as np
import scipy
plt.style.use("ggplot")
code = """
data {
int N;
int x[N];
}
parameters {
real<lower=0, upper=1> theta;
}
model {
x ~ bernoulli(theta);
}
"""
data = {"N":5, "x":[0,1,0,0,0]}
for r in ['meanfield', 'flows']:
algo = vistan.recipe(r)
posterior = algo(code, data)
sample = posterior.sample(100_000)
plt.hist(sample['theta'], 200, density=True, histtype='step', label= r, linewidth = 1.5)
points = np.arange(0, 1, 0.01)
plot.points(points, scipy.stats.beta(2,5).pdf(points), label='True Posterior', linewidth=1.5)
plt.legend()
plot.show()
Hey Bob!
Thank you for pointing this out. I appreciate the detailed message.
I looked into the development setup I had at the time. I believe I was using pystan=2.9.1.1
; however, for some reason, that did not make it to the dependencies requirements for the pip
package upload. I have uploaded an updated version on pip
to address this.
I also noticed that numpy>=1.20
had some data type changes that caused backward compatibility issues. This should fix that too.
I hope vistan
works for you now. Please, let me know either way.
Thanks for patching. I'm pretty new to Python, so please bear with me. When I try to pip install vistan
again, I get this:
~/github/abhiagwl/vistan/sandbox (master)$ pip install vistan
Requirement already satisfied: vistan in /usr/local/lib/python3.9/site-packages (0.0.0.6)
So I don't seem to be getting a new version. This is confirmed in Python:
~/github/abhiagwl/vistan/sandbox (master)$ python3
Python 3.9.4 (default, Apr 5 2021, 01:47:16)
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import vistan as vs
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.9/site-packages/vistan/__init__.py", line 1, in <module>
from .inference import algorithm, recipe
File "/usr/local/lib/python3.9/site-packages/vistan/inference.py", line 7, in <module>
import vistan.interface as interface
File "/usr/local/lib/python3.9/site-packages/vistan/interface.py", line 1, in <module>
import pystan
ModuleNotFoundError: No module named 'pystan'
The above worked for Bob (confirmed in personal conversation.)