[PYTHON] [PyMC3] Resolve the Compilation Failed error

Introduction

This article is a Compilation Failed error that occurred when the syntax of PyMC2 used in Bayesian inference experienced in Python was rewritten in PyMC3. about, I didn't find much that corresponded to my symptoms, so I'll share it here.

A rewrite of the Bayesian inference code experienced in Python in PyMC3 is available on Github.

environment

error contents

Chapter 1 rewritten in PyMC3 At? "

There is no problem with execution here.

import pymc3 as pm
import theano.tensor as tt

with pm.Model() as model:
    alpha = 1.0/count_data.mean()  # Recall count_data is the
                                   # variable that holds our txt counts
    lambda_1 = pm.Exponential("lambda_1", alpha)
    lambda_2 = pm.Exponential("lambda_2", alpha)
    
    tau = pm.DiscreteUniform("tau", lower=0, upper=n_count_data - 1)

The following error occurred in this part next.

with model:
    idx = np.arange(n_count_data) # Index
    lambda_ = pm.math.switch(tau > idx, lambda_1, lambda_2)

error contents



Exception: ('Compilation failed (return status=1): C:\\Users\\user\\AppData\\Local\\Temp\\ccq4MDSW.s: Assembler messages:\r. C:\\Users\\user\\AppData\\Local\\Temp\\ccq4MDSW.s:270: Error: invalid register for .seh_savexmm\r. ', '[Elemwise{gt,no_inplace}(<TensorType(int64, (True,))>, TensorConstant{[ 0  1  2 ..71\n 72 73]})]')

Solution

-Install MinGW-w64 and set environment variables (See here)

--Recreate a new virtual environment

Terminal


conda create -n env_name
conda install numpy
conda install scipy
conda install cython
pip install git+https://github.com/theano/theano
pip install git+https://github.com/pymc-devs/pymc3
conda install jupyter

I installed theano and PyMC3 with conda once, but in that case, I got the exact same error and could not solve it. However, mixing pip and conda is not very good in operation, so I thought it would be better to create an independent environment. I will.

--Run again

import pymc3 as pm
import theano.tensor as tt

with pm.Model() as model:
    alpha = 1.0/count_data.mean()  # Recall count_data is the
                                   # variable that holds our txt counts
    lambda_1 = pm.Exponential("lambda_1", alpha)
    lambda_2 = pm.Exponential("lambda_2", alpha)
    
    tau = pm.DiscreteUniform("tau", lower=0, upper=n_count_data - 1)

with model:
    idx = np.arange(n_count_data) # Index
    lambda_ = pm.math.switch(tau > idx, lambda_1, lambda_2)

So I passed. After that, I also added matplotlib and seaborn with conda, but there is no problem so far.

If anyone has the same symptoms, I hope this helps ...

Recommended Posts

[PyMC3] Resolve the Compilation Failed error
Resolve the Address already in use error
How to resolve the error from toimage (from PIL.Image import fromarray as toimage)