Issues with theano in a python code used to generate mu in a Gaussian model

Hi,

I am trying to get the best fit values of some parameters thetas, from observed data pairs of (x_obs,y_obs). I am assuming that y~N(mu,sigma) and mu = F(x_obs,thetas).
The function F is a complex physical model written in python.
The code for F works outside of the PyMC model, but when I try it inside the model() I start getting theano -linked errors.
Would anyone be able to point me to resources that I can read and could help with this?
Thank you!
Claudia

1 Like

I’m not sure, but it might help you.https://docs.pymc.io/en/v3/pymc-examples/examples/case_studies/blackbox_external_likelihood.html

3 Likes

To add to the previous answer, the notebooks on the v3 version tag are frozen (like v3 development) and you should generally read the updated notebooks from https://docs.pymc.io/projects/examples/en/latest/

In this case, the blackbox external likelihood I think hasn’t been updated, but we have added an alternative version that uses numpy instead of cython to implement the black box function:

We are already updating the notebooks to use the beta release of pymc v4, and you might want a frozen version of the notebooks where all still use v3. You will see a version menu at the bottom right of the page, you can select the snapshot from this January in that menu for this.

2 Likes

Hi – thank you very much for these links. They are exactly what I needed.
However, when I try to run their code (the version Running on PyMC v3.11.4 as myself), I get the error below.
Do you have any idea of what may be going wrong here? Thank you in advance!


RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
“”"
Traceback (most recent call last):
File “/Users/claudia/anaconda3/anaconda3/envs/stsci/lib/python3.7/site-packages/pymc3/parallel_sampling.py”, line 116, in _unpickle_step_method
self._step_method = pickle.loads(self._step_method)
AttributeError: Can’t get attribute ‘LogLike’ on <module ‘main’ (built-in)>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/Users/claudia/anaconda3/anaconda3/envs/stsci/lib/python3.7/site-packages/pymc3/parallel_sampling.py”, line 135, in run
self._unpickle_step_method()
File “/Users/claudia/anaconda3/anaconda3/envs/stsci/lib/python3.7/site-packages/pymc3/parallel_sampling.py”, line 118, in _unpickle_step_method
raise ValueError(unpickle_error)
ValueError: The model could not be unpickled. This is required for sampling with more than one core and multiprocessing context spawn or forkserver.
“”"

The above exception was the direct cause of the following exception:

ValueError Traceback (most recent call last)
ValueError: The model could not be unpickled. This is required for sampling with more than one core and multiprocessing context spawn or forkserver.

The above exception was the direct cause of the following exception:

RuntimeError Traceback (most recent call last)
/var/folders/mt/j5_ht1ns57zcwpnlm45sqzwr0000gn/T/ipykernel_5791/3401078307.py in
29
30 # Use custom number of draws to replace the HMC based defaults
—> 31 idata_mh = pm.sample(3000, tune=1000, return_inferencedata=True)
32
33 # plot the traces

~/anaconda3/anaconda3/envs/stsci/lib/python3.7/site-packages/pymc3/sampling.py in sample(draws, step, init, n_init, start, trace, chain_idx, chains, cores, tune, progressbar, model, random_seed, discard_tuned_samples, compute_convergence_checks, callback, jitter_max_retries, return_inferencedata, idata_kwargs, mp_ctx, pickle_backend, **kwargs)
557 _print_step_hierarchy(step)
558 try:
→ 559 trace = _mp_sample(**sample_args, **parallel_args)
560 except pickle.PickleError:
561 _log.warning(“Could not pickle model, sampling singlethreaded.”)

~/anaconda3/anaconda3/envs/stsci/lib/python3.7/site-packages/pymc3/sampling.py in _mp_sample(draws, tune, step, chains, cores, chain, random_seed, start, progressbar, trace, model, callback, discard_tuned_samples, mp_ctx, pickle_backend, **kwargs)
1475 try:
1476 with sampler:
→ 1477 for draw in sampler:
1478 trace = traces[draw.chain - chain]
1479 if trace.supports_sampler_stats and draw.stats is not None:

~/anaconda3/anaconda3/envs/stsci/lib/python3.7/site-packages/pymc3/parallel_sampling.py in iter(self)
477
478 while self._active:
→ 479 draw = ProcessAdapter.recv_draw(self._active)
480 proc, is_last, draw, tuning, stats, warns = draw
481 self._total_draws += 1

~/anaconda3/anaconda3/envs/stsci/lib/python3.7/site-packages/pymc3/parallel_sampling.py in recv_draw(processes, timeout)
357 else:
358 error = RuntimeError(“Chain %s failed.” % proc.chain)
→ 359 raise error from old_error
360 elif msg[0] == “writing_done”:
361 proc._readable = True

RuntimeError: Chain 0 failed.