This error is when we remove the dill and mp_ctx params
Section/Code
# Set up finest model and perform inference with PyMC3, using the MLDA algorithm
# and passing the coarse_models list created above.
method_names = []
traces = []
runtimes = []
with pm.Model() as model:
# Multivariate normal prior.
theta = pm.MvNormal("theta", mu=mu_prior, cov=cov_prior, shape=mkl)
# Use the Potential class to evaluate likelihood
pm.Potential("likelihood", logl[-1](theta))
# Find the MAP estimate which is used as the starting point for sampling
MAP = pm.find_MAP()
# Initialise a Metropolis, DEMetropolisZ and MLDA step method objects (passing the subsampling rate and
# coarse models list for the latter)
step_metropolis = pm.Metropolis(tune=tune, tune_interval=tune_interval)
step_demetropolisz = pm.DEMetropolisZ(tune_interval=tune_interval)
step_mlda = pm.MLDA(
coarse_models=coarse_models, subsampling_rates=nsub, base_tune_interval=tune_interval
)
# Inference!
# Metropolis
t_start = time.time()
method_names.append("Metropolis")
traces.append(
pm.sample(
draws=ndraws,
step=step_metropolis,
chains=nchains,
tune=nburn,
discard_tuned_samples=discard_tuning,
random_seed=sampling_seed,
start=MAP,
mp_ctx="forkserver",
pickle_backend="dill",
)
)
runtimes.append(time.time() - t_start)
# DEMetropolisZ
t_start = time.time()
method_names.append("DEMetropolisZ")
traces.append(
pm.sample(
draws=ndraws,
step=step_demetropolisz,
chains=nchains,
tune=nburn,
discard_tuned_samples=discard_tuning,
random_seed=sampling_seed,
start=MAP,
mp_ctx="forkserver",
pickle_backend="dill",
)
)
runtimes.append(time.time() - t_start)
# MLDA
t_start = time.time()
method_names.append("MLDA")
traces.append(
pm.sample(
draws=ndraws,
step=step_mlda,
chains=nchains,
tune=nburn,
discard_tuned_samples=discard_tuning,
random_seed=sampling_seed,
start=MAP,
mp_ctx="forkserver",
pickle_backend="dill",
)
)
runtimes.append(time.time() - t_start)
Traceback for pymc-examples/examples/samplers/MLDA_gravity_surveying.ipynb
ultiprocess sampling (3 chains in 2 jobs)
Metropolis: [theta]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-26-500b476e321f> in <module>
29 method_names.append("Metropolis")
30 traces.append(
---> 31 pm.sample(
32 draws=ndraws,
33 step=step_metropolis,
~/Documents/Projects-Dev/pymc3/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)
555 _print_step_hierarchy(step)
556 try:
--> 557 trace = _mp_sample(**sample_args, **parallel_args)
558 except pickle.PickleError:
559 _log.warning("Could not pickle model, sampling singlethreaded.")
~/Documents/Projects-Dev/pymc3/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)
1457 traces.append(strace)
1458
-> 1459 sampler = ps.ParallelSampler(
1460 draws,
1461 tune,
~/Documents/Projects-Dev/pymc3/pymc3/parallel_sampling.py in __init__(self, draws, tune, chains, cores, seeds, start_points, step_method, start_chain_num, progressbar, mp_ctx, pickle_backend)
427 except ImportError:
428 raise ValueError("dill must be installed for pickle_backend='dill'.")
--> 429 step_method_pickled = dill.dumps(step_method, protocol=-1)
430
431 self._samplers = [
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/site-packages/dill/_dill.py in dumps(obj, protocol, byref, fmode, recurse, **kwds)
271 """pickle an object to a string"""
272 file = StringIO()
--> 273 dump(obj, file, protocol, byref, fmode, recurse, **kwds)#, strictio)
274 return file.getvalue()
275
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/site-packages/dill/_dill.py in dump(obj, file, protocol, byref, fmode, recurse, **kwds)
265 _kwds = kwds.copy()
266 _kwds.update(dict(byref=byref, fmode=fmode, recurse=recurse))
--> 267 Pickler(file, protocol, **_kwds).dump(obj)
268 return
269
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/site-packages/dill/_dill.py in dump(self, obj)
452 raise PicklingError(msg)
453 else:
--> 454 StockPickler.dump(self, obj)
455 stack.clear() # clear record of 'recursion-sensitive' pickled objects
456 return
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in dump(self, obj)
483 if self.proto >= 4:
484 self.framer.start_framing()
--> 485 self.save(obj)
486 self.write(STOP)
487 self.framer.end_framing()
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save(self, obj, save_persistent_id)
599
600 # Save the reduce() output and finally memoize the object
--> 601 self.save_reduce(obj=obj, *rv)
602
603 def persistent_id(self, obj):
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save_reduce(self, func, args, state, listitems, dictitems, state_setter, obj)
640 if self.proto >= 4:
641 save(cls)
--> 642 save(args)
643 save(kwargs)
644 write(NEWOBJ_EX)
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save(self, obj, save_persistent_id)
556 f = self.dispatch.get(t)
557 if f is not None:
--> 558 f(self, obj) # Call unbound method with explicit self
559 return
560
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save_tuple(self, obj)
882 if n <= 3 and self.proto >= 2:
883 for element in obj:
--> 884 save(element)
885 # Subtle. Same as in the big comment below.
886 if id(obj) in memo:
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save(self, obj, save_persistent_id)
556 f = self.dispatch.get(t)
557 if f is not None:
--> 558 f(self, obj) # Call unbound method with explicit self
559 return
560
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save_list(self, obj)
927
928 self.memoize(obj)
--> 929 self._batch_appends(obj)
930
931 dispatch[list] = save_list
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in _batch_appends(self, items)
954 write(APPENDS)
955 elif n:
--> 956 save(tmp[0])
957 write(APPEND)
958 # else tmp is empty, and we're done
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save(self, obj, save_persistent_id)
599
600 # Save the reduce() output and finally memoize the object
--> 601 self.save_reduce(obj=obj, *rv)
602
603 def persistent_id(self, obj):
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save_reduce(self, func, args, state, listitems, dictitems, state_setter, obj)
713 if state is not None:
714 if state_setter is None:
--> 715 save(state)
716 write(BUILD)
717 else:
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save(self, obj, save_persistent_id)
556 f = self.dispatch.get(t)
557 if f is not None:
--> 558 f(self, obj) # Call unbound method with explicit self
559 return
560
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/site-packages/dill/_dill.py in save_module_dict(pickler, obj)
939 # we only care about session the first pass thru
940 pickler._session = False
--> 941 StockPickler.save_dict(pickler, obj)
942 log.info("# D2")
943 return
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save_dict(self, obj)
967
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save_dict(self, obj)
967
968 self.memoize(obj)
--> 969 self._batch_setitems(obj.items())
970
971 dispatch[dict] = save_dict
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in _batch_setitems(self, items)
993 for k, v in tmp:
994 save(k)
--> 995 save(v)
996 write(SETITEMS)
997 elif n:
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save(self, obj, save_persistent_id)
599
600 # Save the reduce() output and finally memoize the object
--> 601 self.save_reduce(obj=obj, *rv)
602
603 def persistent_id(self, obj):
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save_reduce(self, func, args, state, listitems, dictitems, state_setter, obj)
713 if state is not None:
714 if state_setter is None:
--> 715 save(state)
716 write(BUILD)
717 else:
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save(self, obj, save_persistent_id)
556 f = self.dispatch.get(t)
557 if f is not None:
--> 558 f(self, obj) # Call unbound method with explicit self
559 return
560
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/site-packages/dill/_dill.py in save_module_dict(pickler, obj)
939 # we only care about session the first pass thru
940 pickler._session = False
--> 941 StockPickler.save_dict(pickler, obj)
942 log.info("# D2")
943 return
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save_dict(self, obj)
967
968 self.memoize(obj)
--> 969 self._batch_setitems(obj.items())
970
971 dispatch[dict] = save_dict
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in _batch_setitems(self, items)
993 for k, v in tmp:
994 save(k)
--> 995 save(v)
996 write(SETITEMS)
997 elif n:
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save(self, obj, save_persistent_id)
599
600 # Save the reduce() output and finally memoize the object
--> 601 self.save_reduce(obj=obj, *rv)
602
603 def persistent_id(self, obj):
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save_reduce(self, func, args, state, listitems, dictitems, state_setter, obj)
709
710 if dictitems is not None:
--> 711 self._batch_setitems(dictitems)
712
713 if state is not None:
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in _batch_setitems(self, items)
993 for k, v in tmp:
994 save(k)
--> 995 save(v)
996 write(SETITEMS)
997 elif n:
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save(self, obj, save_persistent_id)
599
600 # Save the reduce() output and finally memoize the object
--> 601 self.save_reduce(obj=obj, *rv)
602
603 def persistent_id(self, obj):
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save_reduce(self, func, args, state, listitems, dictitems, state_setter, obj)
713 if state is not None:
714 if state_setter is None:
--> 715 save(state)
716 write(BUILD)
717 else:
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save(self, obj, save_persistent_id)
556 f = self.dispatch.get(t)
557 if f is not None:
--> 558 f(self, obj) # Call unbound method with explicit self
559 return
560
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/site-packages/dill/_dill.py in save_module_dict(pickler, obj)
939 # we only care about session the first pass thru
940 pickler._session = False
--> 941 StockPickler.save_dict(pickler, obj)
942 log.info("# D2")
943 return
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save_dict(self, obj)
967
968 self.memoize(obj)
--> 969 self._batch_setitems(obj.items())
970
971 dispatch[dict] = save_dict
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in _batch_setitems(self, items)
993 for k, v in tmp:
994 save(k)
--> 995 save(v)
996 write(SETITEMS)
997 elif n:
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save(self, obj, save_persistent_id)
599
600 # Save the reduce() output and finally memoize the object
--> 601 self.save_reduce(obj=obj, *rv)
602
603 def persistent_id(self, obj):
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save_reduce(self, func, args, state, listitems, dictitems, state_setter, obj)
713 if state is not None:
714 if state_setter is None:
--> 715 save(state)
716 write(BUILD)
717 else:
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save(self, obj, save_persistent_id)
556 f = self.dispatch.get(t)
557 if f is not None:
--> 558 f(self, obj) # Call unbound method with explicit self
559 return
560
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/site-packages/dill/_dill.py in save_module_dict(pickler, obj)
939 # we only care about session the first pass thru
940 pickler._session = False
--> 941 StockPickler.save_dict(pickler, obj)
942 log.info("# D2")
943 return
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save_dict(self, obj)
967
968 self.memoize(obj)
--> 969 self._batch_setitems(obj.items())
970
971 dispatch[dict] = save_dict
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in _batch_setitems(self, items)
993 for k, v in tmp:
994 save(k)
--> 995 save(v)
996 write(SETITEMS)
997 elif n:
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save(self, obj, save_persistent_id)
599
600 # Save the reduce() output and finally memoize the object
--> 601 self.save_reduce(obj=obj, *rv)
602
603 def persistent_id(self, obj):
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save_reduce(self, func, args, state, listitems, dictitems, state_setter, obj)
683 "args[0] from __newobj__ args has the wrong class")
684 args = args[1:]
--> 685 save(cls)
686 save(args)
687 write(NEWOBJ)
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save(self, obj, save_persistent_id)
556 f = self.dispatch.get(t)
557 if f is not None:
--> 558 f(self, obj) # Call unbound method with explicit self
559 return
560
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/site-packages/dill/_dill.py in save_type(pickler, obj)
1371 for name in _dict.get("__slots__", []):
1372 del _dict[name]
-> 1373 pickler.save_reduce(_create_type, (type(obj), obj.__name__,
1374 obj.__bases__, _dict), obj=obj)
1375 log.info("# %s" % _t)
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save_reduce(self, func, args, state, listitems, dictitems, state_setter, obj)
688 else:
689 save(func)
--> 690 save(args)
691 write(REDUCE)
692
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save(self, obj, save_persistent_id)
556 f = self.dispatch.get(t)
557 if f is not None:
--> 558 f(self, obj) # Call unbound method with explicit self
559 return
560
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save_tuple(self, obj)
897 write(MARK)
898 for element in obj:
--> 899 save(element)
900
901 if id(obj) in memo:
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save(self, obj, save_persistent_id)
556 f = self.dispatch.get(t)
557 if f is not None:
--> 558 f(self, obj) # Call unbound method with explicit self
559 return
560
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/site-packages/dill/_dill.py in save_module_dict(pickler, obj)
939 # we only care about session the first pass thru
940 pickler._session = False
--> 941 StockPickler.save_dict(pickler, obj)
942 log.info("# D2")
943 return
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save_dict(self, obj)
967
968 self.memoize(obj)
--> 969 self._batch_setitems(obj.items())
970
971 dispatch[dict] = save_dict
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in _batch_setitems(self, items)
993 for k, v in tmp:
994 save(k)
--> 995 save(v)
996 write(SETITEMS)
997 elif n:
~/opt/anaconda3/envs/pymc3-dev-py38/lib/python3.8/pickle.py in save(self, obj, save_persistent_id)
574 reduce = getattr(obj, "__reduce_ex__", None)
575 if reduce is not None:
--> 576 rv = reduce(self.proto)
577 else:
578 reduce = getattr(obj, "__reduce__", None)
TypeError: cannot pickle '_abc_data' object
Env
pymc3 3.11.0 dev_0 <develop>
theano-pymc 1.1.2 pypi_0 pypi