4

I am running Python 3.8 on Windows 10 Pro. I am attempting to fit a multinomial fixed effects model to some data. All the packages appear to load fine, the data loads and can be manipulated and viewed. But I get an error when I call a module that my collaborator wrote to fit the model (called contactai). Here is the code for contactai:

Note: tt stands for theano.tensor and pm stands for pymc3

def fixed_effects_model(X, y):

Parameters

X : array contains covariates Design matrix n x p

y : array or shared theano variable Multinomial response variable, n x 3

Returns

pymc3 model object containing fitted model

  yarray = y.eval() 
else:
  yarray = y

if type(X) == tt.sharedvar.TensorSharedVariable:
  Xmat = X.eval()
else:
  Xmat = X

model = pm.Model() 

with model:

  # Transformed coefficients
  betaD = pm.Normal('betad', mu=0, sd=5, shape=(Xmat.shape[1], 1))
  betaI = pm.Normal('betai', mu=0, sd=5, shape=(Xmat.shape[1], 1))
  
  # Softmax transformation with no contact as baseline
  etad = tt.exp(tt.dot(X, betaD)) 
  etai = tt.exp(tt.dot(X, betaI))

  p_d = etad / (1 + etad + etai)
  p_i = etai / (1 + etad + etai)
  p_n = 1 - p_d - p_i 
  ps = tt.stack([p_n, p_d, p_i], axis=1).reshape((len(yarray), 3)) # Stack column-wise
   
  Y_obs = pm.Multinomial("Y_obs", n=1, p=ps, observed=y)

return(model) 

When I call contaciai.py in my jupyter notebook using

test_mod = contactai.fixed_effects_model(Xmat1, Yres.values) 

I get this error message:

ImportError                               Traceback (most recent call last)
<ipython-input-6-275ca67d4b63> in <module>
      1 # Run Fixed Effects model
----> 2 test_mod = contactai.fixed_effects_model(Xmat1, Yres.values)
      3 niter = 1000
      4 
      5 with test_mod:

~\dropbox\Brooke\ai_multinomial_model\contactai.py in fixed_effects_model(X, y)
     50     # Transformed coefficients, what are D and I? In other examples this is where priors are
     51     #specified.
---> 52     betaD = pm.Normal('betad', mu=0, sd=5, shape=(Xmat.shape[1], 1))
     53     betaI = pm.Normal('betai', mu=0, sd=5, shape=(Xmat.shape[1], 1))
     54     # First argument is the name of the random variable

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\pymc3\distributions\distribution.py in __new__(cls, name, *args, **kwargs)
     44                 raise TypeError("observed needs to be data but got: {}".format(type(data)))
     45             total_size = kwargs.pop('total_size', None)
---> 46             dist = cls.dist(*args, **kwargs)
     47             return model.Var(name, dist, data, total_size)
     48         else:

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\pymc3\distributions\distribution.py in dist(cls, *args, **kwargs)
     55     def dist(cls, *args, **kwargs):
     56         dist = object.__new__(cls)
---> 57         dist.__init__(*args, **kwargs)
     58         return dist
     59 

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\pymc3\distributions\continuous.py in __init__(self, mu, sigma, tau, sd, **kwargs)
    468 
    469         self.mean = self.median = self.mode = self.mu = mu = tt.as_tensor_variable(floatX(mu))
--> 470         self.variance = 1. / self.tau
    471 
    472         assert_negative_support(sigma, 'sigma', 'Normal')

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\tensor\var.py in __rtruediv__(self, other)
    204 
    205     def __rtruediv__(self, other):
--> 206         return theano.tensor.basic.true_div(other, self)
    207 
    208     def __rfloordiv__(self, other):

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\gof\op.py in __call__(self, *inputs, **kwargs)
    667 
    668                 # compute output value once with test inputs to validate graph
--> 669                 thunk = node.op.make_thunk(node, storage_map, compute_map,
    670                                            no_recycling=[])
    671                 thunk.inputs = [storage_map[v] for v in node.inputs]

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\gof\op.py in make_thunk(self, node, storage_map, compute_map, no_recycling, impl)
    952                               compute_map=compute_map, impl='c')
    953             try:
--> 954                 return self.make_c_thunk(node, storage_map, compute_map,
    955                                          no_recycling)
    956             except (NotImplementedError, utils.MethodNotDefined):

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\gof\op.py in make_c_thunk(self, node, storage_map, compute_map, no_recycling)
    855                 raise NotImplementedError("float16")
    856         _logger.debug('Trying CLinker.make_thunk')
--> 857         outputs = cl.make_thunk(input_storage=node_input_storage,
    858                                 output_storage=node_output_storage)
    859         thunk, node_input_filters, node_output_filters = outputs

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\gof\cc.py in make_thunk(self, input_storage, output_storage, storage_map, keep_lock)
   1213         """
   1214         init_tasks, tasks = self.get_init_tasks()
-> 1215         cthunk, module, in_storage, out_storage, error_storage = self.__compile__(
   1216             input_storage, output_storage, storage_map,
   1217             keep_lock=keep_lock)

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\gof\cc.py in __compile__(self, input_storage, output_storage, storage_map, keep_lock)
   1151         input_storage = tuple(input_storage)
   1152         output_storage = tuple(output_storage)
-> 1153         thunk, module = self.cthunk_factory(error_storage,
   1154                                             input_storage,
   1155                                             output_storage,

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\gof\cc.py in cthunk_factory(self, error_storage, in_storage, out_storage, storage_map, keep_lock)
   1621             for node in self.node_order:
   1622                 node.op.prepare_node(node, storage_map, None, 'c')
-> 1623             module = get_module_cache().module_from_key(
   1624                 key=key, lnk=self, keep_lock=keep_lock)
   1625 

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\gof\cmodule.py in module_from_key(self, key, lnk, keep_lock)
   1187             try:
   1188                 location = dlimport_workdir(self.dirname)
-> 1189                 module = lnk.compile_cmodule(location)
   1190                 name = module.__file__
   1191                 assert name.startswith(location)

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\gof\cc.py in compile_cmodule(self, location)
   1518         try:
   1519             _logger.debug("LOCATION %s", str(location))
-> 1520             module = c_compiler.compile_str(
   1521                 module_name=mod.code_hash,
   1522                 src_code=src_code,

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\gof\cmodule.py in compile_str(module_name, src_code, location, include_dirs, lib_dirs, libs, preargs, py_module, hide_symbols)
   2418             open(os.path.join(location, "__init__.py"), 'w').close()
   2419             assert os.path.isfile(lib_filename)
-> 2420             return dlimport(lib_filename)
   2421 
   2422 

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\gof\cmodule.py in dlimport(fullpath, suffix)
    315             warnings.filterwarnings("ignore",
    316                                     message="numpy.ndarray size changed")
--> 317             rval = __import__(module_name, {}, {}, [module_name])
    318         t1 = time.time()
    319         import_time += t1 - t0

ImportError: DLL load failed while importing m54e1ce4760689129b813fce15fee7f8d468afbe167bc036205eea6bd301309d7: The specified module could not be found.

My collaborator does not get this error when running identical code on their macbook so the issue is not with the code. I installed all packages with pip. Any help would be greatly appreciated, this has brought me to a standstill on this project.

BLBerger
  • 41
  • 1
  • Any progress on this issue? I stumbled across the same error while trying a few scripts with bambi, and same as here it is pointing at the same line. It seems linked to theano for PyMC3, however the fix is restrictive: https://discourse.pymc.io/t/dll-load-error-on-windows-10/2312/10 and is not obviously applicable in this case. – Iqigai Mar 09 '22 at 06:59

0 Answers0