Difficulty getting code that works on one computer to work on another computer

Hello,

I hope this isn’t too much of a general question.

I have code that works on my Mac Laptop. It’s very processor intensive so I’m trying to get my code to work on a different computer but I’m having issues. I’m working within an anaconda environment on each and I’ve made sure that my PyMC3, Theano, numpy, scipy, etc…versions are the same between the two computers. Beyond that I’m not sure what differences to look for so I’d appreciate any advice on what I should be looking for to determine what’s going wrong.

For reference, below is the code that I’m trying to run (this is not the very processor intensive code, this is a test that also doesn’t work on the different computer):

import numpy as np
from scipy import stats

import pymc3 as pm
import theano.tensor as tt

np.random.seed(1234)
n_classes = 2

with pm.Model() as mog:
    
    p = pm.Dirichlet("p", a=np.ones(n_classes), shape=n_classes)
    mu = pm.Normal("mu", mu=np.mean(y_obs), sd=5, shape=n_classes,
                   testval=np.sort(y_obs[np.random.randint(len(y_obs), size=n_classes)]),
                   transform=pm.distributions.transforms.Ordered())
    logs = pm.Normal("logs", mu=np.log(np.std(y_obs)), sd=20.0, shape=n_classes)
    
    resid = y_obs[:, None] - mu[None, :]
    sd = tt.sqrt(yerr_obs[:, None]**2 + tt.exp(2*logs[None, :]))
    
    logp = pm.Normal.dist(sd=sd).logp(resid)
    logp += tt.log(p)[None, :]
    logp_marg = tt.log(tt.sum(tt.exp(logp), axis=1))
    pm.Potential("obs", logp_marg)
    pm.Deterministic("log_class_prob", logp - logp_marg[:, None])
    
    trace = pm.sample(sample, tune=500)

And this is the error I get when trying to run it on the new machine,


AssertionError Traceback (most recent call last)
in
10 logs = pm.Normal(“logs”, mu=np.log(np.std(y_obs)), sd=20.0, shape=n_classes)
11
—> 12 resid = y_obs[:, None] - mu[None, :]
13 sd = tt.sqrt(yerr_obs[:, None]**2 + tt.exp(2*logs[None, :]))
14

Hi again - I think I figured it out. It was some difference with how my input arrays were being read in to the model.

1 Like