Looking for help: error occured in simple linear model example

Hello experts. Can you help me to solve the problem. Thanks alot.
I have learned pymc3 framework for weeks.
When I read the (Generalized) Linear and Hierarchical Linear Models in PyMC3 — PyMC3 3.11.4 documentation, I tried to implement the simple linear mode.
But error occured during the process of fitting model.
Error:
--------------------------------------------------------------------------- **
TypeError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_51020/1246198900.py in
1 model = bambi.Model(“y~x”,data )
----> 2 fitted = model.fit(draws =1000)

D:\ProgramData\Anaconda\lib\site-packages\bambi\backend\pymc.py

NOTE: Methods return different types of objects (idata, advi_params, and dictionary)

if method.lower () == "mcmc":

—> 90 result = self._run_mcmc(draws, tune,

D:\ProgramData\Anaconda\lib\site-packages\pymc3\parallel_sampling.py** in init
TypeError : cannot pickle ‘fortran’ object

Environments: OS-Win10 Pro, Intel i5 8300H, Anaconda 3, python 3.9, PyMC3 v3.11.4, Bambi

@silverlion Welcome to the Pymc3 Discourse forum! Could you post the complete code you tried to run? I see that you are using bambi, a pymc3 front-end. Did you check if the code runs correctly in pymc3? Did you test your pymc3 environment to check if you can compile your models since you are on a Windows machine?

Also share the output from conda list command for the list of packages installed.

Thanks for your attention.

Codes :
import os
import numpy as np
import pandas as pd
import xarray as xr
import pymc3 as pm
import bambi

import matplotlib.pyplot as plt
import arviz as az
import theano
from numpy.random import default_rng

%matplotlib inline
%config InlineBackend.figure_format = ‘retina’

Initialize random number generator

RANDOM_SEED = 8927
rng = default_rng(RANDOM_SEED)
az.style.use(“arviz-darkgrid”)

True parameter values

size = 50
true_intercept = 1
true_slope = 2
x = np.linspace(0, 1, size)
y = true_intercept + x * true_slope + rng.normal(scale=0.5, size=size)
data = pd.DataFrame({“x”: x, “y”: y})
model = bambi.Model(“y~x”, data)
fitted = model.fit(draws=1000) # error occured here.

====end of codes =======

And I found that after changing to “fitted = model.fit(draws=1000, cores=1)”, the error disappeared.

@silverlion nice to know that you have a solution, although I find it a bit unusual that not specifying the number of cores caused the error. Hopefully some body more experienced with the internals of bambi can explain better why that happened.

Thanks for sharing the code. I will try to replicate the error.

1 Like