Closed sreedat closed 2 years ago
Before I go through the details, here are two suggestions:
python -c "import pymc3; print(pymc3.__version__)
<details><summary>Click here to show detailed instructions</summary>
Inside the details you can have Markdown formatting (including code sections) and images.
Is that theano.tensor.blas
warning an indication that the installation is not optimal?
Thanks @michaelosthege for the initial feedback - I will include those changes. Collapsible sections are a great idea and thanks for showing how it is done!
@ricardoV94 yes it is (and thanks for the question) - what this means (upon researching I found) is that theano
is unable to find the optimized libraries such as mkl
and is calling indirectly via numpy
. From what I read, this will slow down the computation and also increase the memory utilization.
I found a solution: install blas
from conda-forge: conda install -c conda-forge blas
. After the installation of blas
, the warning went away.
@michaelosthege I will add blas
to the requirements in the environment.yml
file.
Update: ``blashas been added to the
environment.yml``` file
this looks like a really detailed and helpful way of explaining things!! thanks! we do have a lot of windows installation problems. A lil suggestion that you can think about, although wait to see what others think but: a few of the steps seem to be things that are more to do with requirements for a working "anaconda and jupyter" which can probably be a separate subsection. as in "here's the guide to install pymc3 on windows: 1. If you don't have a working anaconda/are not familiar with condo envs check {insert link}" and perhaps after some suggestions we can make a small installation troubleshooting guide, I think there are some common import errors that happen, so users don't have to dig through old issues and are aware of common troubles, it can be an FAQ/ troubleshooting guide thing, a lot of libraries nowadays have those I think. the docs team might have a different approach about it, here's just my two cents!!
@mjhajharia thank you for the feedback and the suggestions. I included Jupyter as a way to test as it reflects my Windows bias rather than my comfort with command line. @michaelosthege has already proposed a way to test the Pymc3 installation using the command line and I will change that in the document. I agree that the sub-sections to installing Pymc3 and testing it are many. I hope that with my own experience, I can help others avoid the mistakes that I did. Please share any additional feedback.
@michaelosthege @ricardoV94 Just an update on the Warning associated with Theano and Blas:
What I found is the folliwing:
blas
worked only in the environment with Python=3.7.9pm.sample()
command samples lot more slowly compared to scenario 1 above without the warning.@michaelosthege Any idea why this is happening?
Sree
My experience with this whole installation stuff is just empirical. I have very little understanding of how these dependencies interact with each other.
Over here (and linked there) are ongoing activities to fix the Aesara and PyMC3 conda recipes: https://github.com/pymc-devs/pymc3/pull/4932.
Again I'm not involved with making these changes right now. I just happen to be someone with a Windows machine who found a local optimum of more or less reproducible installation instructions.
@michaelosthege thanks for getting back Michael! I will check the link and understand more. It is good that there is a very good working setup with 3.7.9 that I found on Windows 10 and you have some thing similar. Hopefully between these two variations we can have some stability. Might be wishful thinking on my part! In the documentation, the Python=3.7.9 and Python=3.8.8 and their respective environments can be provided which may help out other users.
@michaelosthege @ricardoV94 the installation instructions are no good. On a new machine I tried to follow these instructions and create a working installation of pymc3 (v=3.11.2 as well as v=3.11.3)
. I cannot create the environment using Python=3.7.9
that was working on one machine with Windows 10 and replicate this on another Windows 10 machine by making use of the "environment.yml``` I had created from a fully working version. Following the user path that @michaelosthege posted, which worked on one machine, is not helping on another. This is a completely fresh install. I get the same error below:
Exception: ('Compilation failed (return status=1): C:\Users\SreeDatta\AppData\Local\Temp\ccEWCiGI.s: Assembler messages:\r. C:\Users\SreeDatta\AppData\Local\Temp\ccEWCiGI.s:367: Error: invalid register for .seh_savexmm\r. ', 'FunctionGraph(Elemwise{eq,no_inplace}(<TensorType(int64, vector)>, <TensorType(int8, (True,))>))')
I have to do more investigation into why this is failing for Windows 10 and understand this seemingly random behavior
@michaelosthege @ricardoV94 I think I have discovered a working solution to installing and running pymc3
on Windows 10. I have now replicated this approach on 3 laptops running Windows 10 and it works without any errors so far. The problem appears to be:
m2w64-toolchain
uses gcc 5.3.0
and some part of that, on Windows 10, is incompatible with theano-pymc
being used in pymc3 v=3.11.2 & v=3.11.3
(since I have only tested these versions).
On a whim, I installed RTools mingw tool chain and used it, since it uses gcc 8.3.0
. I checked on Anaconda and found that the gcc 8.3.0
based m2w64-toolchain
is not available for Windows. It is available for Linux. In addition to installing RTools, in the specific pymc3
environmentI also installed
blasand
libblas(after installing RTools) from
conda-forge```.
When RTools was installed, I allowed that to be on the System PATH and to be discovered as the main mingw
compiler source for conda
environments and disabled the installed m2w64-toolchain
by changing the directory name in the conda envs
.
After I restarted each of the Windows 10 machines, I could run all of the examples from the Pymc3 Getting Started page successfully without any theano
errors. I tested and made sure that the only gcc & g++
accessed in conda envs
were those from RTools.
These invalid register errors crop up only with theano-pymc
. In testing pymc3 v4
with aesara
, these invalid register errors do not appear for now. I was ready to give up on using pymc3
on Windows 10. With this serendipitous solution, I have hope. I will see how long this lasts.
Lastly, is there anything that can be done to precisely identify the problem and find a proper solution? I have a solution, but this is a stop gap at best.
@sreedat can you post the exact install commands you used?
@twiecki After posting this I could make my pymc3
work without installing m2w64-toolchain
in the first place any where, either the base
Anaconda or one of the envs
. Here are the steps I followed.
Downloaded the latest 64-bit RTools from this page https://cran.r-project.org/bin/windows/Rtools/ and installed it with Admin rights so that the mingw
compilers are on the System PATH and also First on the PATH. I installed RTools to the default location installer prefers C:\rtools40
Note: RTools on WIndows has to be installed in directory paths without any space in the directory names.
Restarted the machine.
All of the next steps are in Anaconda.
Used the following command to create a basic environment:
conda create -n pm3env -c conda forge "python=3.8" libpython mkl mkl-service numba scipy python-graphviz
conda activate pm3env
pip install pymc3==3.11.2
(I'm running everything with Admin rights)
(pm3env) C:\Users\SreeDatta> which gcc
and then which g++
(to ensure C:\rtools40\mingw64\bin
is referenced as the primary C and C++ compiler.
(pm3env) C:\Users\SreeDatta>conda install -c conda-forge blas libblas
(I did this a preemptive install. I got tired of seeing the invalid register theano
error.
For reference these were the versions `installed:
blas 1.0 mkl conda-forge
libblas 3.9.0 1_h8933c1f_netlib conda-forge
After this step, I stalled jupyter
using conda install -c conda-forge notebook
as that is my preferred way to interact with pymc3
Then I could run the basic and some advanced hierarchical models without the theano-pymc
error.
I do not know how long this working environment will last. I also verified that on my WSL Ubuntu as well as my dedicated Ubuntu laptop, I've gcc 8.3.0
- compared to Windows 10, Linux / Ubuntu has been a breeze, but all of my team members work on WIndows 10 and I needed to get a decent Windows 10 environment for pymc3
.
I will post more here as I see what happens with different users.
@twiecki I have successfully repeated the exact process of using RTools as the preferred gcc
compiler and created additional environments across the same 3 machines using python=3.9
and pymc3=3.11.3
. I installed blas
and libblas
in these environments as I specified in the steps above. I have a good working pymc3
environment without theano-pymc
errors.
Here are the two environment.yml files for both of what I have tested to date when using RTools gcc 8.3.0
@twiecki upon further testing I did notice the following warning in pymc3
environment built with python=3.8
:
WARNING (theano.tensor.blas): We did not find a dynamic library in the library_dir of the library we use for blas. If you use ATLAS, make sure to compile it with dynamics library.
I do not get this warning in pymc3
environment built with python=3.9
- I have to test some more!
@twiecki I was able to resolve this warning, although I do not understand why, by installing m2w64-openblas
using
conda install -c msys2 m2w64-openblas
. I was getting this error in the Python=3.9 env too. I was not seeing in the correct place. Sorry for the confusion.
The time for sampling is interesting to note:
pymc3=3.11.2
took 5 seconds to sample 2 chains on 1 core; pymc3=3.11.3
took 3 seconds for the same. There clearly seem to be some improvements in version 3.11.3
Hi All,
Just wanted to add some additional instructions for the Windows Installation Guide. I just wanted to add that even using RTools with gcc 8.3.0, there seems to be a problem with compilation (same error as above, "invalid register ...") for Xeon users on Windows 10. GCC seems to have fixed this bug in version 9.0+ (see the discourse post that gave me the idea to try other compilers (including clang and VS Tools).
To get gcc working properly on Windows 10 with Xeon processors:
import theano
print(theano.config.cxx)
Thanks @curtywang. msys2
should also be available through condo-forge, have you tried installing that?
Thanks @curtywang.
msys2
should also be available through condo-forge, have you tried installing that?
Yes, but the msys2 version of gcc on conda repos for Windows has stalled at 5.3.0.
Any idea why m2w64 doesn't work for you?
Any idea why m2w64 doesn't work for you?
It's the same compilation error as above, even if I remove everything except the m2w64 paths from PATH and check the CXX being used. If I use clang or MSVC, theano-pymc is able to compile models (but not use any optimizations). I suspect it has to do with GCC and Windows more than anything, given that even numpy seems to have faced this problem for GCC 8.3.0. The version of GCC on my MSYS2 install now is 10.3.0.
@sreedat this was the only approach that managed to produce at least a half working pymc3 installation on my Windows 10. However, it seems even this approach produces an unstable installation, with some things working some not. Doing a quick check reproducing https://towardsdatascience.com/bayesian-statistics-101-4c4bc5fde1e1 examples the standard linear regressions work, but the binomial examples do not, neither in the GLM mode nor when implementing from scratch. Both give 'Compilation failed (return status=1): C:\Users\\AppData\Local\Temp\ccKUWQjU.s: Assembler messages:\r. C:\Users\\AppData\Local\Temp\ccKUWQjU.s:367: Error: invalid register for .seh_savexmm\r. ', 'FunctionGraph(Elemwise{eq,no_inplace}(TensorConstant{[0 0 1 1 0..1 1 1 0 1]}, <TensorType(int8, (True,))>))'" error.
Install:
@sreedat this was the only approach that managed to produce at least a half working pymc3 installation on my Windows 10. However, it seems even this approach produces an unstable installation, with some things working some not. Doing a quick check reproducing https://towardsdatascience.com/bayesian-statistics-101-4c4bc5fde1e1 examples the standard linear regressions work, but the binomial examples do not, neither in the GLM mode nor when implementing from scratch. Both give 'Compilation failed (return status=1): C:\Users**\AppData\Local\Temp\ccKUWQjU.s: Assembler messages:\r. C:\Users**\AppData\Local\Temp\ccKUWQjU.s:367: Error: invalid register for .seh_savexmm\r. ', 'FunctionGraph(Elemwise{eq,no_inplace}(TensorConstant{[0 0 1 1 0..1 1 1 0 1]}, <TensorType(int8, (True,))>))'" error.
Install:
- theano-pymc 1.1.2
- pymc3 3.11.2
- python 3.8.12
- numba 0.54.1
- arviz 0.11.4
Let me try the binomial example and see if it works for the MSYS2 GCC 10.3.0 setup.
@sreedat this was the only approach that managed to produce at least a half working pymc3 installation on my Windows 10. However, it seems even this approach produces an unstable installation, with some things working some not. Doing a quick check reproducing https://towardsdatascience.com/bayesian-statistics-101-4c4bc5fde1e1 examples the standard linear regressions work, but the binomial examples do not, neither in the GLM mode nor when implementing from scratch. Both give 'Compilation failed (return status=1): C:\Users_\AppData\Local\Temp\ccKUWQjU.s: Assembler messages:\r. C:\Users_\AppData\Local\Temp\ccKUWQjU.s:367: Error: invalid register for .seh_savexmm\r. ', 'FunctionGraph(Elemwise{eq,no_inplace}(TensorConstant{[0 0 1 1 0..1 1 1 0 1]}, <TensorType(int8, (True,))>))'" error. Install:
- theano-pymc 1.1.2
- pymc3 3.11.2
- python 3.8.12
- numba 0.54.1
- arviz 0.11.4
Let me try the binomial example and see if it works for the MSYS2 GCC 10.3.0 setup.
@zperko On the MSYS2 GCC 10.3.0 setup, the Bernoulli model seems to have worked:
import arviz as az
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import pymc3 as pm
# Setting a random seed for reproducibility
np.random.seed(23)
# True parameter values
alpha = -0.8
beta = [-1, 1.5]
sigma = 1
# Number of observations
size = 500
# Predictor variables
X1 = np.random.randn(size)
X2 = np.random.randn(size) * 0.8
# Outcome variable
Y = alpha + beta[0] * X1 + beta[1] * X2 + np.random.randn(size) * sigma
# Putting our original data into a dataframe (we'll use it later on)
df = pd.DataFrame(
data = np.array([X1, X2, Y]),
index=['X1', 'X2', 'Y']
).T
outputs just the usual WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
.
# Creating a binary variable
df['Y_bin']=df['Y']>df['Y'].mean()
with pm.Model() as model_log:
# Priors
alpha = pm.Normal("alpha", mu=0, sigma=10)
beta = pm.Normal("beta", mu=0, sigma=10, shape=2)
# Likelihood
p = pm.Deterministic('p', pm.math.sigmoid(alpha + beta[0] * X1 + beta[1] * X2))
Y_obs = pm.Bernoulli("Y_obs", p, observed=df['Y_bin'])
# Posterior
trace = pm.sample(100, return_inferencedata=False, chains=4)
az.plot_trace(trace)
Is able to run the sampler in whole:
Only 100 samples in chain.
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [beta, alpha]
100.00% [4400/4400 00:07<00:00 Sampling 4 chains, 0 divergences]
Sampling 4 chains for 1_000 tune and 100 draw iterations (4_000 + 400 draws total) took 47 seconds.
@curtywang Thanks for the fast reply and try. I've tried to replicate your solution, installing msys2, but in runtime now all examples give a "cc1plux.exe system error", complaining about not finding zlib1.dll. Despite the dll file being in /mingw64/bin. Really weird.
@curtywang Managed to solve it, thanks for the help. Apparently the issue was with theano config not using the msys g++ compiler, was still pointing to my Strawberry install. One sidenote though, seems like msys2 is pretty slow, at least for the regression problems that both are able to run it's factor 3-4 slower.
@twiecki I just confirmed that it might just be a newer Intel microarch problem for Windows m2w64-toolchain. I had another user who has a Ice Lake (Core i5-1035G4) and I myself have a Xeon Silver 4216 (Cascade Lake). It seems as though the msys2 g++ will solve the problem.
@zperko I have the same problem, Windows multiprocessing is slower than just running the sampler singlethreaded, sometimes.
I've been trying to get this working on Win11 using the advice above, but I run into compilation errors:
~\miniforge3\envs\pymc_env\lib\site-packages\theano\link\c\cmodule.py in compile_str(module_name, src_code, location, include_dirs, lib_dirs, libs, preargs, py_module, hide_symbols)
2544 # difficult to read.
2545 compile_stderr = compile_stderr.replace("\n", ". ")
-> 2546 raise Exception(
2547 f"Compilation failed (return status={status}): {compile_stderr}"
2548 )
Exception: ('Compilation failed (return status=1): C:\\Users\\fonne\\AppData\\Local\\Temp\\ccabwyOj.s: Assembler messages:\r. C:\\Users\\fonne\\AppData\\Local\\Temp\\ccabwyOj.s:114: Error: invalid register for .seh_savexmm\r. ', 'FunctionGraph(Elemwise{le,no_inplace}(TensorConstant{[0 0 1 0 0..0 0 1 1 1]}, <TensorType(int8, (True,))>))')
This is having installed m2w64-toolchain from the msys2 repository. This is a Surface Pro 8, so 11th gen core i7.
Sorry accidentally closed the issue. Reopening.
@curtywang thanks for the thorough follow-ups. I have been out sick.
@twiecki I will setup new PyMC3 with Msys2 approach tested by @curtywang and report back here for Windows installation
@curtywang @zperko thanks for both of your feedback. I will share what results I get following the process outlined by @curtywang and share it here.
After a long long struggle, I was able to install Pymc3 on my newly purchased windows 10 machine. The machine's CPU is an 11th gen Intel(R) Core(TM) i7-1165G7.
The key seems to be to use the proper version of gcc and g++ for the Intel CPU generation.
The m2w64-toolchain installed by anaconda3 has a too-old gcc version 5.3.0. So I couldn't even run a simple linear regression demo program on my machine.
According to the information provided by @sreedat, I installed the Rtools and set the PATH to MinGW toolchain of it before building the pymc3 environment in anaconda. Wait a minute! You don't need to install Rtools.
Although the linear regression demo program worked, the slightly more complex model I had written earlier gave a compilation error from Theano at sampling and did not work at all. (It is working fine on an old machine with Pymc3 installed before and automatically updated.) The gcc version of the current Rtools is 8.3.0. Probably, this is not new enough for 11th gen CPU.
At this point, I created the
.theanorc
file with the following 2 lines
[blas]
ldflags = -lblas
and put it the directly just under the username (like "owner".) Then, the following warning was disappeared.
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
But the overall situation did not change.
Finally, the information provided by @curtywang helped me. The problem was solved by using the current version of the MinGW toolchain of MSYS2.
Here I share what I did in a step-by-step manner.
Install MSYS2, and from the MSYS2 console execute
pacman -Syuu
This automatically closes the MSYS2 console after the update. So, re-open it and execute
pacman -S base-devel
pacman -S mingw-w64-x86_64-toolchain
to install gcc and other tools (Default installation settings are used for both.)
Add the PATH to the compilers like
C:\msys64\mingw64\bin
(The directory where gcc and g++ of MSYS2 are installed. Check by yourself.)
The PATH should be copied from the properties of the gcc.exe. <- very important to avoid careless mistakes.
Make this PATH higher than those for any other compiler.
Execute
gcc -v
g++ -v
in Anaconda power shell, and confirm that the PATH to the MSYS2 compiler is active.
I got the following message.
gcc version 11.2.0 (Rev2, Built by MSYS2 project)
After that, I started the Jupyter notebook in the Pymc3 environment that I built just after the installation of Rtools, and confirmed that it works fine.
I hope you will have a successful installation!
The above-mentioned installation also solved the 1-year long problem in another PC with 10th gen Intel(R) Core(TM) i7-1065G7 CPU.
I also found that the usage of the current version of compilers by theano accelerates the sampling on old machines without the re-installation of pymc3.
One thing I was wondering was that I had no problems in installing PyMC3 from conda-forge on the i9-10900 machine I bought after the i7-1065G7 machine. When I found out that i9-10900's microarchitecture is still Skylake and there was a big change in i7-1065G7's Sunny Cove from Skylake, although both CPUs are categorized as 10th gen, I understood why.
@KTada777 if you can translate these findings into a dependency and version requirement, that would be a great contribution to the Aesara conda-forge feedstock!
@michaelosthege Unfortunately, I don't have the skills to do it.
As long as the binary installer is available, https://www.mingw-w64.org/downloads/ shows that gcc ver.11 or later on Windows is only supported by MSYS2. Since MSYS2 of Anaconda3 does not seem to be currently maintained, I think that it is difficult to solve the problem only inside Anaconda3.
It would be nice to avoid having to install RTools. Has anyone tried installing mingw from Chocolatey? It appears to install v. 11.2.0 of gcc/g++
I was able to get a working installation using miniforge and mingw from Chocolatey. This is on a Surface Pro 8 running Win11.
The one other modification I made to the current install instructions is to install arviz from conda rather than having it install as a PyMC dependency from pip. This avoids the geweke error that I had been getting.
It would be nice to avoid having to install RTools. Has anyone tried installing mingw from Chocolatey? It appears to install v. 11.2.0 of gcc/g++
Absolutely, we do not need Rtools but gcc/g++ v.11.2.0. We also do not need MSYS2. We just need to install MinGW-w64 including the latest gcc/g++, so the installation of it with Chocolatey (I did not know it) is a great suggestion!
Probably the best way to solve this would be to just get the mingw packages updated. Opened an issue here: https://github.com/conda-forge/toolchain-feedstock/issues/60
I discovered another approach to solving the precise error mentioned here: https://github.com/pymc-devs/pymc/issues/4937#issuecomment-953993182. As a plus, it works with the olderm2w64-toolchain
version of GCC.
I took inspiration from https://github.com/numpy/numpy/issues/14787 and decided to see if I could figure out how to insert the compiler flag -fno-asynchronous-unwind-tables
as described at this comment: https://github.com/numpy/numpy/issues/14787#issuecomment-546690428. I located the spot in Aesara where compiler arguments are being set:
I then modified the list of arguments to include -fno-asynchronous-unwind-tables
like so:
def compile_args(self):
"""
Returns a list of compile args that are needed by one
or more Variables or Ops.
This might contain duplicates.
"""
ret = ["-O3"]
# this is the param the -ffast-math activate. I put the explicitly as
# FillMissing must disable some of them. Putting -ffast-math would
# make it disable all other parameter at the same time.
ret += [
"-fno-math-errno",
"-fno-asynchronous-unwind-tables",
There may be a more appropriate place to put this additional flag, but I'm not that familiar with the Aesara codebase. At any rate, this solved the problem, and the compiler error disappears. Under this approach, PyMC continues to work with the older version of GCC included in m2w64-toolchain
.
This approach doesn't require the user to get a separate install of MinGW that sits directly on the Windows path for all command prompts. It allows MinGW to exist only in certain conda environments where it is needed, and it makes the process of adding MinGW very easy by simply including it in the conda environment spec. It could be an interim solution until m2w64-toolchain
is updated to a more recent version of GCC.
@jedludlow That is extremely useful to have figured out, thanks for reporting back. Want to do a PR to add this compiler setting to https://github.com/pymc-devs/pymc/blob/main/pymc/__init__.py#L36 or do you want me to?
@twiecki @fonnesbeck @KTada777 @curtywang @michaelosthege
I have just posted at Pymc3 Discourse on setting up a successful installation of Pymc3 on Windows 10 and Anaconda. Like @curtywang @KTada777 I solved the compiler problem by installing the latest MSYS2 with gcc-11.2.0
compiler suite.
I tried RTools (using MSYS2 8.3.0) out of sheer frustration as I saw that the old version of gcc-5.3.0
that Anaconda had was a dud. As noted above, that works only on simple models.
Based on what I have been able to do, there is no need to install RTools at all for Pymc3 to work. However, for users such as I, who work in both R and Python, setting the User Path
variable can be a critical step in ensuring both R and Python play with respective compilers nicely. This was something @michaelosthege had shared on how he got his install to work and I finally figured out (until the next breakdown) how Pymc3 and R can coexist.
Thanks everyone!!!
I will post the same instructions here next.
@twiecki @fonnesbeck @michaelosthege @KTada777 @curtywang
Follow this link for the detailed Pymc3 Windows 10 installation guide using Anaconda
Pymc3 Windows 10 Installation using Anaconda
Let me know if there are any questions. Thanks every one once again!
Sree
@jedludlow just read your comment on modifying the flags!!!!!!! This is an absolute god send solution!!! Can this be incorporated into the theano-pymc
library like you did for aesara
? Right now, the current pymc3
does not work with gcc-5.3.0
.
That really would be a huge help for a large number of Windows users to get Pymc3 working with the default gcc-5.3.0
tools. I know I spent at least the last 18 months figuring out a solution.
I'm also interested in learning how this is done. So if you can provide some guidance, I can try my hand at it.
@KTada777 thanks for your solution about creating the .theanorc
file with the relevant flag setting.
That damn warning goes away. Can you explain what the flag setting is doing?
@fonnesbeck I could do a complete working Pymc3 and gccc-11.2.0
using MingW64
via Choclatey on my personal laptop with Windows 10. There are 3 different solutions:
gcc-5.3.0
workgcc-11.2.0
gcc-11.2.0
via ChoclateyAs @KTada777 noted, there is a speed advantage when using Pymc3 with the newest compilers when sampling. So I definitely prefer having either the MSYS2 or Choclatey solution with 11.2.0 version of the compilers.
@KTada777 thanks for your solution about creating the
.theanorc
file with the relevant flag setting.That damn warning goes away. Can you explain what the flag setting is doing?
I am happy to hear that my information is working for you. Is it possible to know what CPU you are using?
I am not sure why we have to create the .theanorc
file for the flag, because
https://theano-pymc.readthedocs.io/en/latest/library/config.html
says that
ldflags = -lblas
is the default setting.
However, It seems that we need it for recent Intel CPUs that require recent compilers.
Probably, the default flag is somehow ignored.
@sreedta8 the pull request ( #5363) I put together to solve this problem on the main branch could easily be ported to the v3 branch, which would likely solve the problem for pymc3
. I haven't tested this, though. Assuming that fix works, it would require another release of pymc3
before it became broadly available to users who were installing via conda
or pip
. If such a release is planned, I'd be willing to make the pull request. But the value of doing that depends upon release strategies for the various versions of PyMC over the next while, and I'm not familiar with that strategy.
Hi @michaelosthege - here is the first version of the Installation Reference. Let me know what changes may be needed.
For Pymc3 Windows users who may not have a programming background or have comfort with tool chains and such, the installation instructions on this page (https://github.com/pymc-devs/pymc3/wiki/Installation-Guide-(Windows)) may not be sufficient. The instructions posted below go beyond the basic installation process posted at the above link.
In addition, there are a large community of users, who use both R and Python (Anaconda). The
RTools mingw tool chain
has to be first on the System Environment variables so thatR packages that need compilation such as rstan, brms
will run correctly. In this situation, the compilation ofpymc3
models will break and additional post-installUser Environment Variables
has to be done sopymc3
works correctly.Versions and main components
theano-pymc
)m2w64 tool chain from conda-forge
RTools mingw tool chain
on the System PATHThe essence of a solid PyMC3 installation on Windows is to install most of the dependencies through conda. The reason installation via PyPI is difficult is that Theano/Aesara require compilation against MKL, which is difficult to set up, while Conda comes with its own compilers and MKL installation.
⚠ Do not pip install without first installing dependencies with conda. ⚠
Method 1: Run
conda env create -f environment.yml
to create a fresh environment in one step - use Notepad++, if possible to create the saidenvironment.yml
file.environment.yml (copy from
name: pm3env
and ending withpymc3
and save it inC:\Users\Your_User_Name
)You can change name to something meaningful for you such as
pym3
orenv_pym3
. You do not have to usepm3env
. Keep it simple and meaningful so you can use the environment with ease when using the command line.Method 2: You can create
pymc3
specific environment also directly from theAnaconda3 Command Prompt
using the following command:conda create -n pm3env -c conda-forge "python=3.8" libpython mkl-service m2w64-toolchain numba python-graphviz scipy
After you have created the environment, you can test it has been created successfully by typing:
conda info --envs
- the output of the command will show all the environments that exist in the current Anaconda3 install. Hopefully you will see your environment forpymc3
Activate your environment by typing the command:
conda activate pm3env
(or whatever name you chose) Your command prompt will look like:(pm3env) C:\Users\Your_User_Name
Check Packages Installed using the command
conda list
and all packages installed inpm3env
will be shown. Check if either one oftheano
ortheano-pymc
has been installed. Make note of it (It should not be)Install Pymc3: Now you can install Pymc3 using the command:
pip install pymc3
and then if all requirements are met, all packages from pip and their dependencies will be installed,. Of critical importance to note is whethertheano-pymc
has been installed along withpymc3
- pymc3 will not run without this - Heretheano-pymc
should be installed. In addition, in thepip
output check that dependencies such asarviz
(for working withpymc3
objects) andmatplotlib
(for general purpose data graphing) have also been installed.Sometimes these packages may not be installed in your new environment but will be installed likely in the location below on Windows 10:
c:\users\your_user_name\appdata\roaming\python\python38\site-packages
- note the number 38 next topython38
in the folder name. This means that versions relevant for python3.8 have been installed here. These packages will not appear in the output ofconda list
. Ensure that thepython
you specified (python=3.8) matches what you see in the folder name here (python38)[@michaelosthege The original instructions ask to install
theano-pymc
usingconda-forge
. However, I found that in the new dependency installation ofpymc3
,theano-pymc
is being automatically being installed and it is working correctly. This is one where I need your input on whether we remove the note to updatetheano-pymc
. I think this is outdated]Now there are additional ways to install ``pymc3
and additional variants of
pymc3```. Refer to the next section, which may be more appropriate for advanced users.Developer Installation
If you want to tinker with PyMC3 itself, first clone the repository and then make an "editable" installation: (You need to have already installed
git
for this to work, if not installgit
first)Upgrading from Theano to Theano-PyMC - Just in case when you run
conda list
at thepm3env
prompt and find that you havetheano
instead oftheano-pymc
(stranger things have and will happen!)theano
was installed from: it will show pypi or conda-forge.pip uninstall theano
- you should see a message statingtheano
has been uninstalledconda remove theano
- you should answer with a y if prompted for the removal oftheano
theano-pymc
using the command,conda install -c conda-forge theano-pymc
.conda list
and verifypymc3 & theano-pymc
are installed.Optional Dependencies (before you install any packages, first check they have not been already installed using
conda list
conda install -c conda-forge python-graphviz
andpip install pydot-ng
Jupyter Notebook
orJupyter Lab
are not installed. If you are working with Anaconda3, you install these two Jupyter tools from Anaconda3 Navigator or from thepm3env command prompt
using the command:conda install -c conda-forge notebook
Do Not Close the Command Prompt window of the pm3env - we have to use it later on.
Post Installation Checks - Do Not Skip This Step on Windows A. Assumes you have installed Jupyter Notebook B. Make note of whether you have R and in particular RTools installed on your laptop and location of its' install. C. Assumes you have either Admin or Power-User rights on your laptop so that you can make changes to the environment variables at the User level.
Windows does not come pre-installed with C and C++ compilers (as Mac and Linux Distros do) so it is important to ensure your Anaconda3 environments are pointing to the correct internal compilers.
Going back to the original creation / installation of
pm3env
environment, one of the packages installed ism2w64-toolchain
. Here things can get complex in terms of having compiler tools specific to the version of Python and to that of the environment. So generally speaking, try to keep your Anaconda3 environments to a minimum, when you are starting out with tools such aspymc3
. Also make sure you install am2w64-toolchain
in each environment you create. Conda will ensure that you have the most appropriate version of the compilers for the version of Python in that environment. There are exceptions, but it gets beyond the scope of this document.On Windows, search for "Edit System Environment Variables". You will be taken to the screen below
Click on the "Environment Variables" on the bottom right-hand corner and you will see a new window pop-up with the top Window for User variables and the bottom window for the System variables. Click on the entry labeled Path under User Variables for Your_User_Name and click edit. Here you should add the following Anaconda paths specific to your environment:
Note the location of where Anaconda3 is installed by default (as shown below). If you have changed the location during the installation of Anaconda3, please make the changes accordingly.
First:
C:\ProgramData\Anaconda3\Library\mingw-w64\bin
Second:C:\ProgramData\Anaconda3\Library\bin
Third:C:\ProgramData\Anaconda3\Scripts
Move each of the entries so that they appear in the exact order as shown above at the top of the User Variables Path using the Move Up and Move Down buttons
Then click "OK" to accept the changes all the way.
Go back to the
pm3env
Command Prompt window that is already open that displays(pm3env) C:\Users\Your_User_Name>
Type
jupyter-notebook
at the prompt and (hopefully) a page should be opened in your Default Browser.On the top right corner, click on the drop-down under New
Select Python 3 (ipykernel)
You should see a new Jupyter Notebook open that looks as follows:
Make sure that at the top right corner, the button says Trusted. If this is the first time you are using a Jupyter Notebook, it might show up as Not Trusted. Click on it if it says "Not Trusted" and select the option to make it "Trusted".
In the first Notebook cell, type
import theano as tp
and click on the Run button.You may see a warning as shown in the picture below (
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
)In the next cell type the following commands and click Run
import pymc3 as pm
print(f"Running on PyMC3 v{pm.__version__}")
You should see an output as follows:
Running on PyMC3 v3.11.2
You can now begin testing the full capabilities of Pymc3 by starting with the three examples from the Getting Started with Pymc3 - linked here - http://docs.pymc.io/notebooks/getting_started
Good luck with using Pymc3!